Skip to content

Commit 6a700ac

Browse files
committed
Support providing a custom symbol resolver
1 parent 787e4bf commit 6a700ac

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/com/sun/jna/Library.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public interface Library {
113113
* conflict.
114114
*/
115115
String OPTION_CLASSLOADER = "classloader";
116+
/** Provides a custom symbol resolver. */
117+
String OPTION_SYMBOL_RESOLVER = "symbol-resolver";
116118

117119
static class Handler implements InvocationHandler {
118120

src/com/sun/jna/NativeLibrary.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,12 @@ long getSymbolAddress(String name) {
630630
if (handle == 0) {
631631
throw new UnsatisfiedLinkError("Library has been unloaded");
632632
}
633-
return Native.findSymbol(handle, name);
633+
final SymbolResolver resolver = (SymbolResolver)options.get(Library.OPTION_SYMBOL_RESOLVER);
634+
if (resolver != null) {
635+
return resolver.getSymbolAddress(this, name);
636+
} else {
637+
return Native.findSymbol(handle, name);
638+
}
634639
}
635640

636641
@Override
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.sun.jna;
2+
3+
public interface SymbolResolver {
4+
long getSymbolAddress(NativeLibrary library, String symbolName);
5+
}

0 commit comments

Comments
 (0)