Add support for cdata library for Java
This commit is contained in:
parent
8e6a539d89
commit
90a9d750c9
3 changed files with 60 additions and 0 deletions
33
Lib/cdata.i
33
Lib/cdata.i
|
|
@ -20,17 +20,50 @@ typedef struct SWIGCDATA {
|
|||
$result = scm_from_locale_stringn($1.data,$1.len);
|
||||
}
|
||||
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
|
||||
|
||||
#elif SWIGCHICKEN
|
||||
|
||||
%typemap(out) SWIGCDATA {
|
||||
C_word *string_space = C_alloc(C_SIZEOF_STRING($1.len));
|
||||
$result = C_string(&string_space, $1.len, $1.data);
|
||||
}
|
||||
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
|
||||
|
||||
#elif SWIGPHP
|
||||
|
||||
%typemap(out) SWIGCDATA {
|
||||
ZVAL_STRINGL($result, $1.data, $1.len, 1);
|
||||
}
|
||||
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
|
||||
|
||||
#elif SWIGJAVA
|
||||
|
||||
%apply (char *STRING, int LENGTH) { (const void *indata, int inlen) }
|
||||
%typemap(jni) SWIGCDATA "jbyteArray"
|
||||
%typemap(jtype) SWIGCDATA "byte[]"
|
||||
%typemap(jstype) SWIGCDATA "byte[]"
|
||||
%fragment("SWIG_JavaArrayOutCDATA", "header") {
|
||||
static jbyteArray SWIG_JavaArrayOutCDATA(JNIEnv *jenv, char *result, jsize sz) {
|
||||
jbyte *arr;
|
||||
int i;
|
||||
jbyteArray jresult = JCALL1(NewByteArray, jenv, sz);
|
||||
if (!jresult)
|
||||
return NULL;
|
||||
arr = JCALL2(GetByteArrayElements, jenv, jresult, 0);
|
||||
if (!arr)
|
||||
return NULL;
|
||||
for (i=0; i<sz; i++)
|
||||
arr[i] = (jbyte)result[i];
|
||||
JCALL3(ReleaseByteArrayElements, jenv, jresult, arr, 0);
|
||||
return jresult;
|
||||
}
|
||||
}
|
||||
%typemap(out, fragment="SWIG_JavaArrayOutCDATA") SWIGCDATA
|
||||
%{$result = SWIG_JavaArrayOutCDATA(jenv, (char *)$1.data, $1.len); %}
|
||||
%typemap(javaout) SWIGCDATA {
|
||||
return $jnicall;
|
||||
}
|
||||
|
||||
#else
|
||||
%echo "cdata.i module not supported."
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue