actually add patches
This commit is contained in:
parent
41f98f53de
commit
22ca1ba2d4
66
jna-3.0.4-callbacks-methodname.patch
Normal file
66
jna-3.0.4-callbacks-methodname.patch
Normal file
@ -0,0 +1,66 @@
|
||||
diff -ur jna-3.0.4-svn630/src/com/sun/jna/CallbackReference.java jna-3.0.4-svn630.orig/src/com/sun/jna/CallbackReference.java
|
||||
--- jna-3.0.4-svn630/src/com/sun/jna/CallbackReference.java 2008-07-31 13:44:21.000000000 -0400
|
||||
+++ jna-3.0.4-svn630.orig/src/com/sun/jna/CallbackReference.java 2008-09-03 09:04:35.000000000 -0400
|
||||
@@ -16,6 +16,7 @@
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
+import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -150,22 +151,45 @@
|
||||
}
|
||||
return cls;
|
||||
}
|
||||
+
|
||||
+ private static Method checkMethod(Method m) {
|
||||
+ if (m.getParameterTypes().length > Function.MAX_NARGS) {
|
||||
+ String msg = "Method signature exceeds the maximum "
|
||||
+ + "parameter count: " + m;
|
||||
+ throw new IllegalArgumentException(msg);
|
||||
+ }
|
||||
+ return m;
|
||||
+ }
|
||||
|
||||
private static Method getCallbackMethod(Callback callback) {
|
||||
- Method[] mlist = callback.getClass().getMethods();
|
||||
+ Class klass = callback.getClass();
|
||||
+ Method[] mlist = klass.getDeclaredMethods();
|
||||
+
|
||||
+ /* If there's only one method, just try it. */
|
||||
+ if (mlist.length == 1)
|
||||
+ return checkMethod(mlist[0]);
|
||||
+
|
||||
+ /* Now try looking for a field named "METHOD_NAME" which
|
||||
+ * tells us which method to use.
|
||||
+ */
|
||||
+ String methName = Callback.METHOD_NAME;
|
||||
+ try {
|
||||
+ Field methNameField = klass.getField("METHOD_NAME");
|
||||
+ methName = (String) methNameField.get(null);
|
||||
+ } catch (NoSuchFieldException e) {
|
||||
+ } catch (Exception e) {
|
||||
+ String msg = "Callback METHOD_NAME field is invalid";
|
||||
+ throw new IllegalArgumentException(msg);
|
||||
+ }
|
||||
+
|
||||
for (int mi=0;mi < mlist.length;mi++) {
|
||||
Method m = mlist[mi];
|
||||
- if (Callback.METHOD_NAME.equals(m.getName())) {
|
||||
- if (m.getParameterTypes().length > Function.MAX_NARGS) {
|
||||
- String msg = "Method signature exceeds the maximum "
|
||||
- + "parameter count: " + m;
|
||||
- throw new IllegalArgumentException(msg);
|
||||
- }
|
||||
- return m;
|
||||
+ if (methName.equals(m.getName())) {
|
||||
+ return checkMethod(m);
|
||||
}
|
||||
}
|
||||
String msg = "Callback must implement method named '"
|
||||
- + Callback.METHOD_NAME + "'";
|
||||
+ + methName + "'";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
|
81
jna-3.0.4-callbacks-typemappers.patch
Normal file
81
jna-3.0.4-callbacks-typemappers.patch
Normal file
@ -0,0 +1,81 @@
|
||||
Only in jna-3.0.4-svn630.orig/: build-d64
|
||||
Only in jna-3.0.4-svn630.orig/: build.number
|
||||
Only in jna-3.0.4-svn630.orig/: debugfiles.list
|
||||
Only in jna-3.0.4-svn630.orig/: debuglinks.list
|
||||
Only in jna-3.0.4-svn630.orig/: debugsources.list
|
||||
Only in jna-3.0.4-svn630.orig/doc: javadoc
|
||||
diff -ur jna-3.0.4-svn630/src/com/sun/jna/Native.java jna-3.0.4-svn630.orig/src/com/sun/jna/Native.java
|
||||
--- jna-3.0.4-svn630/src/com/sun/jna/Native.java 2008-09-01 12:12:50.000000000 -0400
|
||||
+++ jna-3.0.4-svn630.orig/src/com/sun/jna/Native.java 2008-09-01 12:12:27.000000000 -0400
|
||||
@@ -51,7 +51,9 @@
|
||||
* which would require every {@link Structure} which requires custom mapping
|
||||
* or alignment to define a constructor and pass parameters to the superclass.
|
||||
* To avoid lots of boilerplate, the base {@link Structure} constructor
|
||||
- * figures out these properties based on its enclosing interface.<p>
|
||||
+ * figures out these properties based on its enclosing interface. Alternatively,
|
||||
+ * A field named TYPE_MAPPER may be declared.
|
||||
+ * <p>
|
||||
* <a name=library_loading></a>
|
||||
* <h2>Library Loading</h2>
|
||||
* When JNA classes are loaded, the native shared library (jnidispatch) is
|
||||
@@ -350,32 +352,44 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ private static final TypeMapper getClassTypeMapper(Class cls) {
|
||||
+ try {
|
||||
+ Field field = cls.getField("TYPE_MAPPER");
|
||||
+ return (TypeMapper) field.get(null);
|
||||
+ }
|
||||
+ catch (NoSuchFieldException e) {
|
||||
+ return null;
|
||||
+ }
|
||||
+ catch (Exception e) {
|
||||
+ throw new IllegalArgumentException("TYPE_MAPPER must be a public field of type "
|
||||
+ + TypeMapper.class.getName() + " ("
|
||||
+ + e + "): " + cls);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
/** Return the preferred {@link TypeMapper} for the given native interface.
|
||||
* See {@link com.sun.jna.Library#OPTION_TYPE_MAPPER}.
|
||||
*/
|
||||
public static TypeMapper getTypeMapper(Class cls) {
|
||||
+ if (Callback.class.isAssignableFrom(cls)) {
|
||||
+ return getClassTypeMapper(cls);
|
||||
+ }
|
||||
synchronized(libraries) {
|
||||
Class interfaceClass = findLibraryClass(cls);
|
||||
if (interfaceClass == null)
|
||||
return null;
|
||||
+ TypeMapper mapper = getClassTypeMapper(interfaceClass);
|
||||
+ if (mapper != null) {
|
||||
+ typeMappers.put(interfaceClass, mapper);
|
||||
+ } else {
|
||||
+ Map options = getLibraryOptions(cls);
|
||||
+ if (options != null
|
||||
+ && options.containsKey(Library.OPTION_TYPE_MAPPER)) {
|
||||
+ typeMappers.put(interfaceClass, options.get(Library.OPTION_TYPE_MAPPER));
|
||||
+ }
|
||||
+ }
|
||||
if (!loadInstance(interfaceClass)
|
||||
|| !typeMappers.containsKey(interfaceClass)) {
|
||||
- try {
|
||||
- Field field = interfaceClass.getField("TYPE_MAPPER");
|
||||
- typeMappers.put(interfaceClass, field.get(null));
|
||||
- }
|
||||
- catch (NoSuchFieldException e) {
|
||||
- Map options = getLibraryOptions(cls);
|
||||
- if (options != null
|
||||
- && options.containsKey(Library.OPTION_TYPE_MAPPER)) {
|
||||
- typeMappers.put(interfaceClass, options.get(Library.OPTION_TYPE_MAPPER));
|
||||
- }
|
||||
- }
|
||||
- catch (Exception e) {
|
||||
- throw new IllegalArgumentException("TYPE_MAPPER must be a public field of type "
|
||||
- + TypeMapper.class.getName() + " ("
|
||||
- + e + "): " + interfaceClass);
|
||||
- }
|
||||
}
|
||||
return (TypeMapper)typeMappers.get(interfaceClass);
|
||||
}
|
Loading…
Reference in New Issue
Block a user