From 920367dccd700270e604eed83951492b1fa08a69 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 2 Oct 2008 03:33:42 +0000 Subject: [PATCH] - Add new patch to support NativeMapped[] which I want --- jna-3.0.4-nativemapped-array.patch | 73 ++++++++++++++++++++++++++++++ jna.spec | 8 +++- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 jna-3.0.4-nativemapped-array.patch diff --git a/jna-3.0.4-nativemapped-array.patch b/jna-3.0.4-nativemapped-array.patch new file mode 100644 index 0000000..53d2e94 --- /dev/null +++ b/jna-3.0.4-nativemapped-array.patch @@ -0,0 +1,73 @@ +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~ diff --git a/jna.spec b/jna.spec index 0b7fc44..67d9cea 100644 --- a/jna.spec +++ b/jna.spec @@ -1,6 +1,6 @@ Name: jna Version: 3.0.4 -Release: 8.svn729%{?dist} +Release: 9.svn729%{?dist} Summary: Pure Java access to native libraries Group: Development/Libraries @@ -19,6 +19,8 @@ Patch1: jna-3.0.2-loadlibrary.patch # and using a complex API like X11 through JNA just increases the potential # for problems. Patch2: jna-tests-headless.patch +# https://jna.dev.java.net/issues/show_bug.cgi?id=90 +Patch3: jna-3.0.4-nativemapped-array.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRequires: java-devel >= 1.6 ant jpackage-utils ant-nodeps @@ -50,6 +52,7 @@ This package contains the javadocs for %{name}. %setup -q -n %{name}-%{version}-svn729 sed -e 's|@JNIPATH@|%{_libdir}/%{name}|' %{PATCH1} | patch -p1 %patch2 -p1 -b .tests-headless +%patch3 -p1 -b .nativemapped-array # all java binaries must be removed from the sources find . -name '*.jar' -exec rm -f '{}' \; @@ -106,6 +109,9 @@ rm -rf %{buildroot} %changelog +* Wed Oct 01 2008 Colin Walters - 3.0.4-9.svn729 +- Add new patch to support NativeMapped[] which I want + * Wed Oct 01 2008 Colin Walters - 3.0.4-8.svn729 - Update to svn r729 - drop upstreamed typemapper patch