74 lines
2.7 KiB
Diff
74 lines
2.7 KiB
Diff
diff -ur jna-3.0.4-svn729/src/com/sun/jna/Function.java jna-3.0.4-svn729.orig/src/com/sun/jna/Function.java
|
|
--- jna-3.0.4-svn729/src/com/sun/jna/Function.java 2008-09-12 10:05:07.000000000 -0400
|
|
+++ jna-3.0.4-svn729.orig/src/com/sun/jna/Function.java 2008-10-01 23:23:38.000000000 -0400
|
|
@@ -12,6 +12,7 @@
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
+import java.lang.reflect.Array;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
@@ -351,16 +352,41 @@
|
|
}
|
|
return result;
|
|
}
|
|
+
|
|
+ private Class primitiveFromBoxed(Class boxedClass) {
|
|
+ if (boxedClass.isPrimitive())
|
|
+ return boxedClass;
|
|
+ if (boxedClass == Boolean.class)
|
|
+ return Boolean.TYPE;
|
|
+ if (boxedClass == Byte.class)
|
|
+ return Byte.TYPE;
|
|
+ if (boxedClass == Character.class)
|
|
+ return Character.TYPE;
|
|
+ if (boxedClass == Short.class)
|
|
+ return Short.TYPE;
|
|
+ if (boxedClass == Integer.class)
|
|
+ return Integer.TYPE;
|
|
+ if (boxedClass == Long.class)
|
|
+ return Long.TYPE;
|
|
+ if (boxedClass == Float.class)
|
|
+ return Float.TYPE;
|
|
+ if (boxedClass == Double.class)
|
|
+ return Double.TYPE;
|
|
+ return boxedClass;
|
|
+ }
|
|
|
|
private Object convertArgument(Object[] args, int index, Method invokingMethod, TypeMapper mapper) {
|
|
Object arg = args[index];
|
|
if (arg != null) {
|
|
Class type = arg.getClass();
|
|
ToNativeConverter converter = null;
|
|
+ boolean isArray = false;
|
|
if (NativeMapped.class.isAssignableFrom(type)) {
|
|
converter = NativeMappedConverter.getInstance(type);
|
|
- }
|
|
- else if (mapper != null) {
|
|
+ } else if (NativeMapped[].class.isAssignableFrom(type)) {
|
|
+ isArray = true;
|
|
+ converter = NativeMappedConverter.getInstance(type.getComponentType());
|
|
+ } else if (mapper != null) {
|
|
converter = mapper.getToNativeConverter(type);
|
|
}
|
|
if (converter != null) {
|
|
@@ -371,7 +397,15 @@
|
|
else {
|
|
context = new FunctionParameterContext(this, args, index);
|
|
}
|
|
- arg = converter.toNative(arg, context);
|
|
+ if (isArray) {
|
|
+ NativeMapped[] nativeArg = (NativeMapped[]) arg;
|
|
+ /* Reassign arg here to a new array */
|
|
+ arg = Array.newInstance(primitiveFromBoxed(converter.nativeType()), nativeArg.length);
|
|
+ for (int i = 0; i < nativeArg.length; i++)
|
|
+ Array.set(arg, i, converter.toNative(nativeArg[i], context));
|
|
+ } else {
|
|
+ arg = converter.toNative(arg, context);
|
|
+ }
|
|
}
|
|
}
|
|
if (arg == null || isPrimitiveArray(arg.getClass())) {
|
|
Only in jna-3.0.4-svn729.orig/src/com/sun/jna: Function.java~
|