From: Stefan Z. <sz...@gm...> - 2011-08-08 23:59:25
|
On Fri, Jul 29, 2011 at 8:47 PM, Joe Chan <fre...@gm...> wrote: > I want to use a c++ program to read a jpg then pass it to python. > > however since jpg has numerous '\0' inside. Python always think that the > jpg only contains less than 10 bytes. > > My question is what is the proper way to pass a binary arrays with numerous > "\0" from c++ to python. > Assuming you don't want to actually manipulate the jpeg data in python, but simply want to pass it around as an opaque object, you can write a set of typemaps that use the PyCapsule API, something like this: %typemap(out) char * { $result = PyCapsule_New((void*) $1, NULL, NULL); } %typemap(in) char * { $1 = (char*) PyCapsule_GetPointer($input, NULL); } As written, these typemaps will apply to all methods that take/return char*; you'll need to apply them selectively if you have other methods that use char* as a string. Hope that helps. Stefan > > > > > ------------------------------------------------------------------------------ > Got Input? Slashdot Needs You. > Take our quick survey online. Come on, we don't ask for help often. > Plus, you'll get a chance to win $100 to spend on ThinkGeek. > http://p.sf.net/sfu/slashdot-survey > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user > > |