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.

+ * figures out these properties based on its enclosing interface. Alternatively, + * A field named TYPE_MAPPER may be declared. + *

* *

Library Loading

* 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); }