binary data - SWIG unsigned char and byte[] -


i've looked on place. have tried of techniques on site. no avail.

i have c++ global function

char* squid( char* buff, int len ); 

i create .i file

%module crabby  %include "arrays_java.i"  %{ /* headers here included in wrapper code */ #include "sponge.h" %}    %typemap(jtype) (const signed char *arr, size_t sz) "byte[]" %typemap(jstype) (const signed char *arr, size_t sz) "byte[]" %typemap(jni) (const signed char *arr, size_t sz) "jbytearray" %typemap(javain) (const signed char *arr, size_t sz) "$javainput"  %typemap(in) (const signed char* arr, size_t sz) {   $1 = jcall2(getbytearrayelements, jenv, $input, null);   const size_t sz = jcall1(getarraylength, jenv, $input);   $2 = $1 + sz; }  %typemap(freearg) (const signed char *arr, size_t sz) {   // or use  0 instead of abort keep changes if copy   jcall3(releasebytearrayelements, jenv, $input, $1, jni_abort);  }  %apply (const signed char* arr, size_t sz) { (const unsigned char* buff, int len) } %apply (const signed char* arr, size_t sz) { (const unsigned char* query, int querylen) }  %include "sponge.h" 

no matter interface always

public static string squid(string buff, int len) 

if remove unsigned illegal conversions in cxx wrapper

this swig 2.0.1

your interface close, has following issues:

  1. const matters %apply
  2. you need match signed/unsigned qualifier buff (there no qualifier in declaration showed.
  3. your in typemap needs numinputs=1 compress 1 java input.
  4. setting size computed pointer doesn't make sense.

so fixed interface looks like:

%module crabby  %include "arrays_java.i"  %{ /* headers here included in wrapper code */ #include "sponge.h" %}  %typemap(jtype) (const signed char *arr, size_t sz) "byte[]" %typemap(jstype) (const signed char *arr, size_t sz) "byte[]" %typemap(jni) (const signed char *arr, size_t sz) "jbytearray" %typemap(javain) (const signed char *arr, size_t sz) "$javainput"  %typemap(in,numinputs=1) (const signed char* arr, size_t sz) {   $1 = jcall2(getbytearrayelements, jenv, $input, null);   const size_t sz = jcall1(getarraylength, jenv, $input);   $2 = sz; }  %typemap(freearg) (const signed char *arr, size_t sz) {   // or use  0 instead of abort keep changes if copy   jcall3(releasebytearrayelements, jenv, $input, $1, jni_abort); }  %apply (const signed char* arr, size_t sz) { ( char* buff, int len) }  %include "sponge.h" 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -