Fix Java multi-argument typemaps (char *STRING, size_t LENGTH)

Now they can be applied to a wider range of types.
Closes #385.
This commit is contained in:
William S Fulton 2015-05-10 13:35:51 +01:00
commit 6c1630b152
4 changed files with 30 additions and 0 deletions

View file

@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.6 (in progress)
===========================
2015-05-10: wsfulton
[Java] Fix multi-argument typemaps (char *STRING, size_t LENGTH)
so that they can be applied to a wider range of types. Fixes #385.
2015-05-07: olly
[Python] Deal with an integer as the default value of a bool
parameter in the C++ prototype. Fixes github #327, reported by

View file

@ -4,6 +4,7 @@
%apply (char *STRING, size_t LENGTH) { (char *dataBufferAA, int sizeAA) };
%apply (char *STRING, size_t LENGTH) { (char *dataBufferBB, int sizeBB) };
%apply (char* STRING, size_t LENGTH) { (const void* data, size_t datalen) };
%inline %{
#include <stdlib.h>
@ -20,6 +21,7 @@ public:
if (dataBufferBB)
memset(dataBufferBB, -1, sizeBB);
}
virtual void writeData(const void* data, size_t datalen) = 0;
};
class Caller {
@ -50,6 +52,17 @@ public:
void call_null() {
_callback->run(NULL, 0, NULL, 0);
}
int callWriteData() {
int sum = 0;
if (_callback) {
char* aa = (char*)malloc(BUFFER_SIZE_AA);
memset(aa, 9, BUFFER_SIZE_AA);
_callback->writeData(aa, BUFFER_SIZE_AA);
for (int i = 0; i < BUFFER_SIZE_AA; i++)
sum += aa[i];
}
return sum;
}
};
%}

View file

@ -17,11 +17,15 @@ public class director_binary_string_runme {
Callback callback = new DirectorBinaryStringCallback();
caller.setCallback(callback);
int sum = caller.call();
int sumData = caller.callWriteData();
caller.delCallback();
if (sum != 9*2*8 + 13*3*5)
throw new RuntimeException("Unexpected sum: " + sum);
if (sumData != 9*2*8)
throw new RuntimeException("Unexpected sum: " + sum);
new Callback().run(null, null);
callback = new DirectorBinaryStringCallback();
caller.setCallback(callback);
@ -45,5 +49,13 @@ class DirectorBinaryStringCallback extends Callback {
for (int i = 0; i < dataBufferBB.length; i++)
dataBufferBB[i] = (byte)(dataBufferBB[i] * 3);
}
@Override
public void writeData(byte[] dataBufferAA)
{
if (dataBufferAA != null)
for (int i = 0; i < dataBufferAA.length; i++)
dataBufferAA[i] = (byte)(dataBufferAA[i] * 2);
}
}

View file

@ -1348,6 +1348,7 @@ SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
%typemap(directorargout) (char *STRING, size_t LENGTH)
%{(jenv)->GetByteArrayRegion($input, 0, $2, (jbyte *)$1);
(jenv)->DeleteLocalRef($input);%}
%typemap(javadirectorin, descriptor="[B") (char *STRING, size_t LENGTH) "$jniinput"
%apply (char *STRING, size_t LENGTH) { (char *STRING, int LENGTH) }
/* java keywords */