Re: help with typemap
Robert Arkiletian <[email protected]> Thu, 24 Dec 2020 12:24:15 -0800
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CAN_+rpLWrq4E5OM5o3a9Gcfw6H=8j-yZNfvOMgGvCmPQ6OtqXQ@mail.gmail.com> |
On Wed, Dec 23, 2020 at 11:52 AM William S Fulton <[email protected]> wrote: > > Looks like you are using it in an overloaded C++ function. You need to also provide a 'typecheck' typemap in addition to the 'in' typemap. >> >> Thanks for the help William. I looked for examples of how to create a typecheck for a "const unsigned char * " and unfortunately I didn't find much. So I copied an example from the SWIG docs and used SWIG_TYPECHECK_UINT8_PTR. %typemap(typecheck, precedence=SWIG_TYPECHECK_UINT8_PTR, noblock=1) SWIGTYPE * { void *vptr = 0; int res = SWIG_ConvertPtr($input, &vptr, $1_descriptor, 0); $1 = SWIG_IsOK(res) ? 1 : 0; } %typemap(in) const unsigned char *buffer { //used buffer instead of data ... } I don't know if the typecheck is correct. However, it did not work. So I looked more closely at the overloaded C++ header for the function. Fl_JPEG_Image(const char *filename); Fl_JPEG_Image(const char *name, const unsigned char *data); // this is the function Then I noticed I used the variable "buffer" not "data" in typemap(in) (see above). So I simply changed the var name to data %typemap(in) const unsigned char *data { //used data instead of buffer and it worked, even without the typecheck!! I found this in the swig docs http://www.swig.org/Doc4.0/Typemaps.html#Typemaps_nn5 "In addition to tracking typenames, typemaps may also be specialized to match against a specific argument name" So I solved my issue, but is my typecheck correct? If not, how should I fix it?