Prevent writeback of a const char* array through a director when using the byte[] %typemap.

This commit is contained in:
Andrew Galante 2017-07-26 13:59:08 -07:00
commit 36b3c56a06

View file

@ -1366,12 +1366,12 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) } %apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
/* String & length */ /* String & length */
%typemap(jni) (char *STRING, size_t LENGTH) "jbyteArray" %typemap(jni) (const char *STRING, size_t LENGTH) "jbyteArray"
%typemap(jtype) (char *STRING, size_t LENGTH) "byte[]" %typemap(jtype) (const char *STRING, size_t LENGTH) "byte[]"
%typemap(jstype) (char *STRING, size_t LENGTH) "byte[]" %typemap(jstype) (const char *STRING, size_t LENGTH) "byte[]"
%typemap(javain) (char *STRING, size_t LENGTH) "$javainput" %typemap(javain) (const char *STRING, size_t LENGTH) "$javainput"
%typemap(freearg) (char *STRING, size_t LENGTH) "" %typemap(freearg) (const char *STRING, size_t LENGTH) ""
%typemap(in) (char *STRING, size_t LENGTH) { %typemap(in) (const char *STRING, size_t LENGTH) {
if ($input) { if ($input) {
$1 = ($1_ltype) JCALL2(GetByteArrayElements, jenv, $input, 0); $1 = ($1_ltype) JCALL2(GetByteArrayElements, jenv, $input, 0);
$2 = ($2_type) JCALL1(GetArrayLength, jenv, $input); $2 = ($2_type) JCALL1(GetArrayLength, jenv, $input);
@ -1380,10 +1380,10 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
$2 = 0; $2 = 0;
} }
} }
%typemap(argout) (char *STRING, size_t LENGTH) { %typemap(argout) (const char *STRING, size_t LENGTH) {
if ($input) JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0); if ($input) JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0);
} }
%typemap(directorin, descriptor="[B", noblock=1) (char *STRING, size_t LENGTH) { %typemap(directorin, descriptor="[B", noblock=1) (const char *STRING, size_t LENGTH) {
$input = 0; $input = 0;
if ($1) { if ($1) {
$input = JCALL1(NewByteArray, jenv, (jsize)$2); $input = JCALL1(NewByteArray, jenv, (jsize)$2);
@ -1392,9 +1392,10 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
} }
Swig::LocalRefGuard $1_refguard(jenv, $input); Swig::LocalRefGuard $1_refguard(jenv, $input);
} }
%typemap(javadirectorin, descriptor="[B") (const char *STRING, size_t LENGTH) "$jniinput"
%apply (const char *STRING, size_t LENGTH) { (char *STRING, size_t LENGTH) }
%typemap(directorargout, noblock=1) (char *STRING, size_t LENGTH) %typemap(directorargout, noblock=1) (char *STRING, size_t LENGTH)
{ if ($input && $1) JCALL4(GetByteArrayRegion, jenv, $input, 0, (jsize)$2, (jbyte *)$1); } { if ($input && $1) JCALL4(GetByteArrayRegion, jenv, $input, 0, (jsize)$2, (jbyte *)$1); }
%typemap(javadirectorin, descriptor="[B") (char *STRING, size_t LENGTH) "$jniinput"
%apply (char *STRING, size_t LENGTH) { (char *STRING, int LENGTH) } %apply (char *STRING, size_t LENGTH) { (char *STRING, int LENGTH) }
/* java keywords */ /* java keywords */