Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can 'const unsigned char *' be wrapped with swig for java

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?

like image 984
mab Avatar asked Oct 11 '22 18:10

mab


2 Answers

     %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 !!!!!

like image 95
Mahesh Nayak Avatar answered Oct 14 '22 03:10

Mahesh Nayak


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.

like image 23
Andy Thomas Avatar answered Oct 14 '22 02:10

Andy Thomas