Skip to content

Commit

Permalink
fix broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
twall committed May 30, 2013
1 parent 8f19978 commit 962ae79
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
19 changes: 2 additions & 17 deletions src/com/sun/jna/Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/com/sun/jna/Native.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion test/com/sun/jna/NativeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 962ae79

Please sign in to comment.