Skip to content

Commit ba7881f

Browse files
committed
Support boolean[] in direct mapping.
1 parent 8f2e773 commit ba7881f

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

native/dispatch.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,7 @@ dispatch_direct(ffi_cif* cif, void* volatile resp, void** argp, void *cdata) {
18401840
objects[i] = *(void **)args[i]; \
18411841
release[i] = (void *)(*env)->Release##Type##ArrayElements; \
18421842
elems[i] = *(void **)args[i] = (*env)->Get##Type##ArrayElements(env, objects[i], NULL); } while(0)
1843+
case CVT_ARRAY_BOOLEAN: ARRAY(Boolean); break;
18431844
case CVT_ARRAY_BYTE: ARRAY(Byte); break;
18441845
case CVT_ARRAY_SHORT: ARRAY(Short); break;
18451846
case CVT_ARRAY_CHAR: ARRAY(Char); break;
@@ -1959,6 +1960,7 @@ dispatch_direct(ffi_cif* cif, void* volatile resp, void** argp, void *cdata) {
19591960
free(*(void **)args[i]);
19601961
break;
19611962
case CVT_BUFFER:
1963+
case CVT_ARRAY_BOOLEAN:
19621964
case CVT_ARRAY_BYTE:
19631965
case CVT_ARRAY_SHORT:
19641966
case CVT_ARRAY_CHAR:

test/com/sun/jna/ArgumentsMarshalTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ public TestPointerType() { }
109109
int fillFloatBuffer(float[] buf, int len, float value);
110110
int fillDoubleBuffer(double[] buf, int len, double value);
111111

112+
// boolean[] maps to jboolean* (always 8-bit), boolean mapping is 32-bit by default; use byte
113+
int fillInt8Buffer(boolean[] buf, int len, byte value);
114+
115+
// char[] maps to jchar* (always 16-bit), char maps to wchar_t (can be 32-bit); use short
116+
int fillInt16Buffer(char[] buf, int len, short value);
117+
112118
// Nonexistent functions
113119
boolean returnBooleanArgument(Object arg);
114120

@@ -507,6 +513,20 @@ public void testReadStructureByReferenceArrayArgumentMemory() {
507513
}
508514
}
509515

516+
public void testBooleanArrayArgument() {
517+
boolean[] buf = new boolean[1024];
518+
assertEquals("Wrong return value", buf.length,
519+
lib.fillInt8Buffer(buf, buf.length, (byte)1));
520+
for (int i=0;i < buf.length;i++) {
521+
assertTrue("Bad value at index " + i, buf[i]);
522+
}
523+
assertEquals("Wrong return value", buf.length,
524+
lib.fillInt8Buffer(buf, buf.length, (byte)0));
525+
for (int i=0;i < buf.length;i++) {
526+
assertFalse("Bad value at index " + i, buf[i]);
527+
}
528+
}
529+
510530
public void testByteArrayArgument() {
511531
byte[] buf = new byte[1024];
512532
final byte MAGIC = (byte)0xED;
@@ -517,6 +537,16 @@ public void testByteArrayArgument() {
517537
}
518538
}
519539

540+
public void testCharArrayArgument() {
541+
char[] buf = new char[1024];
542+
final char MAGIC = '\uFEFF';
543+
assertEquals("Wrong return value", buf.length,
544+
lib.fillInt16Buffer(buf, buf.length, (short)MAGIC));
545+
for (int i=0;i < buf.length;i++) {
546+
assertEquals("Bad value at index " + i, MAGIC, buf[i]);
547+
}
548+
}
549+
520550
public void testShortArrayArgument() {
521551
short[] buf = new short[1024];
522552
final short MAGIC = (short)0xABED;

test/com/sun/jna/DirectArgumentsMarshalTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public void modifyStructureByReferenceArray(CheckFieldAlignment.ByReference[] p,
107107
public native int fillFloatBuffer(float[] buf, int len, float value);
108108
@Override
109109
public native int fillDoubleBuffer(double[] buf, int len, double value);
110+
@Override
111+
public native int fillInt8Buffer(boolean[] buf, int len, byte value);
112+
@Override
113+
public native int fillInt16Buffer(char[] buf, int len, short value);
110114

111115
// dummy to avoid causing Native.register to fail
112116
@Override

0 commit comments

Comments
 (0)