diff --git a/src/com/sun/jna/Library.java b/src/com/sun/jna/Library.java index 621e4f3552..5928e79e3a 100644 --- a/src/com/sun/jna/Library.java +++ b/src/com/sun/jna/Library.java @@ -118,20 +118,6 @@ static class Handler implements InvocationHandler { } } - private static class FunctionNameMap implements FunctionMapper { - private final Map map; - public FunctionNameMap(Map map) { - this.map = new HashMap(map); - } - public String getFunctionName(NativeLibrary library, Method method) { - String name = method.getName(); - if (map.containsKey(name)) { - return (String)map.get(name); - } - return name; - } - } - private final NativeLibrary nativeLibrary; private final Class interfaceClass; // Library invocation options @@ -154,9 +140,8 @@ public Handler(String libname, Class interfaceClass, Map options) { options.put(OPTION_CALLING_CONVENTION, new Integer(callingConvention)); } - if (!options.containsKey(OPTION_FUNCTION_MAPPER)) { - // Passed-in map is itself the name map - options.put(OPTION_FUNCTION_MAPPER, new FunctionNameMap(options)); + if (options.get(OPTION_CLASSLOADER) == null) { + options.put(OPTION_CLASSLOADER, interfaceClass.getClassLoader()); } this.options = options; this.nativeLibrary = NativeLibrary.getInstance(libname, options); diff --git a/src/com/sun/jna/Native.java b/src/com/sun/jna/Native.java index 8b73b1610f..7c83c735cb 100644 --- a/src/com/sun/jna/Native.java +++ b/src/com/sun/jna/Native.java @@ -1481,6 +1481,7 @@ else if (cvt[t] == CVT_TYPE_MAPPER) { looking them up later. */ private static void cacheOptions(Class cls, Map libOptions, Object proxy) { + libOptions = new HashMap(libOptions); synchronized(libraries) { options.put(cls, libOptions); if (proxy != null) { diff --git a/test/com/sun/jna/NativeTest.java b/test/com/sun/jna/NativeTest.java index 521774d10a..a946ca8d90 100644 --- a/test/com/sun/jna/NativeTest.java +++ b/test/com/sun/jna/NativeTest.java @@ -111,7 +111,7 @@ interface VoidCallback extends Callback { } public void testSynchronizedAccess() throws Exception { final boolean[] lockHeld = { false }; - final NativeLibrary nlib = NativeLibrary.getInstance("testlib"); + final NativeLibrary nlib = NativeLibrary.getInstance("testlib", TestLib.class.getClassLoader()); final TestLib lib = (TestLib)Native.loadLibrary("testlib", TestLib.class); final TestLib synchlib = (TestLib)Native.synchronizedLibrary(lib); final TestLib.VoidCallback cb = new TestLib.VoidCallback() { @@ -168,6 +168,7 @@ public interface TestInterfaceWithInstance extends Library { TypeMapper TEST_MAPPER = new DefaultTypeMapper(); String TEST_ENCODING = "test-encoding"; Map TEST_OPTS = new HashMap() { { + put(OPTION_CLASSLOADER, TestInterfaceWithInstance.class.getClassLoader()); put(OPTION_TYPE_MAPPER, TEST_MAPPER); put(OPTION_STRUCTURE_ALIGNMENT, new Integer(TEST_ALIGNMENT)); put(OPTION_STRING_ENCODING, TEST_ENCODING);