Skip to content

Commit

Permalink
Fix Java multi-argument typemaps (char *STRING, size_t LENGTH)
Browse files Browse the repository at this point in the history
Now they can be applied to a wider range of types.
Closes swig#385.
  • Loading branch information
wsfulton committed May 10, 2015
1 parent b4c441f commit 6c1630b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.current
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions Examples/test-suite/director_binary_string.i
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -20,6 +21,7 @@ public:
if (dataBufferBB)
memset(dataBufferBB, -1, sizeBB);
}
virtual void writeData(const void* data, size_t datalen) = 0;
};

class Caller {
Expand Down Expand Up @@ -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;
}
};

%}
12 changes: 12 additions & 0 deletions Examples/test-suite/java/director_binary_string_runme.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ public static void main(String argv[]) {
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);
Expand All @@ -45,5 +49,13 @@ public void run(byte[] dataBufferAA, byte[] dataBufferBB)
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);
}
}

1 change: 1 addition & 0 deletions Lib/java/java.swg
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 6c1630b

Please sign in to comment.