From: Jeff L. <jef...@gm...> - 2009-04-30 21:49:04
|
Howdy, Say I've got a C function, like read, that takes a pointer to a buffer, and a byte count argument, and writes count bytes into the buffer. Here is a contrived example: void read(char *buf, size_t count) { memcpy(buf, my_internal_buffer, count); } Whats the quickest and easiest way to wrap this function? My target language is Python but I'd rather not use any language specific tricks. I figured out how to do it using cmalloc and cdata, but that feels kludgy. I'd like to be able to say data = read(4) and have data be a string containing the binary data. There are two macros in cstrings.i that come frustratingly close: %cstring_output_maxsize(parm, maxparm) ^ This Almost does what I want, but it uses strcpy or something and stops on null chars, which really doesn't work for binary data. %cstring_output_withsize(parm, maxparm) ^ This is also extremely close except that it expects maxparm to be a pointer for some reason. I could begrudgingly modify my C code to take count as a pointer. But does some variation exist that takes a straight value instead of a pointer? Is there a straightforward way to do this with typemaps or something? Thanks, Jeff -- 73 de n1ywb |