5

How can the following C function be wrapped with SWIG?

int add_option(const unsigned char *data);

Currently I get this wrapped to:

public static int add_option(SWIGTYPE_p_unsigned_char data);

Is it possible to wrap it for String, Byte[] or something similar?

2 Answers 2

3
     %module Example

     %{
       int func(const unsigned char *data);
      %}


      %include <arrays_java.i>

      %apply signed char[] { const unsigned char *data};


      int func(const unsigned char *data);

Use this code !!!!!

1

Yes, it is possible. In the worst case, you could build your own typemap. But a %apply should be sufficient here. Try this:

    %apply signed char *INOUT { unsigned char *pSeqData };

[I adapted this from a similar problem in my *.i file, after months of not using Swig. YMMV.]

The %apply directive copies typemaps from one type to another. There's more about it here in the SWIG manual.

1
  • Even if I add %include "typemaps.i" and the apply above, it is still wrapped to SWIGTYPE_p_unsigned_char data.
    – mab
    Jun 24, 2011 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.