auto-strip profiler prefix set in jna.profiler.prefix

Esse commit está contido em:
Timothy Wall
2013-05-28 22:49:20 -04:00
commit 3704b23a71
5 arquivos alterados com 19 adições e 7 exclusões
+1
Ver Arquivo
@@ -16,6 +16,7 @@ Features
* Added memory dump for debugging (see `com.sun.jna.Memory`) - [@twall](https://github.com/twall).
* Improved caching of Structure alignment, type mapping, and encoding information - [@twall](https://github.com/twall).
* [#225](https://github.com/twall/jna/pull/225): Added `platform.win32.Kernel32.GetLogicalProcessorInformation` and `platform.win32.Kernel32Util.getLogicalProcessorInformation` - [@trejkaz](https://github.com/trejkaz).
* [#236](https://github.com/twall/jna/issues/236): Auto-strip profiler native method prefix specified by `jna.profiler.prefix`, which defaults to $$YJP$$ - [@twall](https://github.com/twall).
Bug Fixes
---------
+3 -6
Ver Arquivo
@@ -1454,12 +1454,7 @@ public final class Native implements Version {
}
}
String name = method.getName();
FunctionMapper fmapper = (FunctionMapper)lib.getOptions().get(Library.OPTION_FUNCTION_MAPPER);
if (fmapper != null) {
name = fmapper.getFunctionName(lib, method);
}
Function f = lib.getFunction(name, method);
Function f = lib.getFunction(method.getName(), method);
try {
handles[i] = registerMethod(cls, method.getName(),
sig, cvt,
@@ -1842,6 +1837,8 @@ public final class Native implements Version {
<em>Warning</em>: avoid calling {@link #detach detach(true)} on threads
spawned by the JVM; the resulting behavior is not defined.
*/
// TODO: keep references to Java non-detached threads, and clear them when
// native side sets a flag saying they're detached (cleanup)
public static native void detach(boolean detach);
private static class Buffers {
+5
Ver Arquivo
@@ -436,6 +436,11 @@ public class NativeLibrary {
if (mapper != null) {
name = mapper.getFunctionName(this, method);
}
// If there's native method profiler prefix, strip it
String prefix = System.getProperty("jna.profiler.prefix", "$$YJP$$");
if (name.startsWith(prefix)) {
name = name.substring(prefix.length());
}
int flags = this.callFlags;
Class[] etypes = method.getExceptionTypes();
for (int i=0;i < etypes.length;i++) {
+7 -1
Ver Arquivo
@@ -264,6 +264,7 @@ public class DirectTest extends TestCase implements Paths {
}
static class RemappedCLibrary {
public static native int $$YJP$$strlen(String s);
public static native int _prefixed_strlen(String s);
}
@@ -283,7 +284,12 @@ public class DirectTest extends TestCase implements Paths {
Native.register(RemappedCLibrary.class,
NativeLibrary.getInstance(Platform.C_LIBRARY_NAME, options));
final String VALUE = getName();
int len = RemappedCLibrary._prefixed_strlen(VALUE);
int len;
len = RemappedCLibrary.$$YJP$$strlen(VALUE);
assertEquals(VALUE.length(), len);
len = RemappedCLibrary._prefixed_strlen(VALUE);
assertEquals(VALUE.length(), len);
}
catch(Exception e) {
+3
Ver Arquivo
@@ -24,3 +24,6 @@ Direct mapping supports the same type mappings as interface mapping, except for
You can easily convert from interface mapping to direct mapping by creating a direct mapping class which implements your library interface, with all methods defined as native methods. Then your library instance variable can be assigned an instance of this new class instead of the object returned by `Native.loadLibrary()`.
If you are using a profile which rewrites native methods, you may need to
set the system property `jna.profiler.prefix` to the prefix used by the
profiler to avoid linkage errors when binding to native methods.