java-native-access / jna

Java Native Access
Other
8.51k stars 1.68k forks source link

Callback shouldn't be direct when CallbackProxy is used #315

Open marco2357 opened 10 years ago

marco2357 commented 10 years ago

If a callback is implemented through a CallbackProxy, it is probably a bad idea to allow it being called directly (bypassing the proxy).

diff --git a/src/com/sun/jna/CallbackReference.java b/src/com/sun/jna/CallbackReference.java
index bcf5568..5b15301 100644
--- a/src/com/sun/jna/CallbackReference.java
+++ b/src/com/sun/jna/CallbackReference.java
@@ -150,6 +150,7 @@
         // Check whether direct mapping may be used, or whether
         // we need to fall back to conventional mapping
         boolean ppc = Platform.isPPC();
+        if (callback instanceof CallbackProxy) direct = false;
         if (direct) {
             Method m = getCallbackMethod(callback);
             Class[] ptypes = m.getParameterTypes();

Also "boolean ppc = ...;" can be put into the "if (direct) {" block

twall commented 10 years ago

good catch.

On Apr 4, 2014, at 10:58 AM, marco2357 notifications@github.com wrote:

If a callback is implemented through a CallbackProxy, it is probably a bad idea to allow it being called directly (bypassing the proxy).

diff --git a/src/com/sun/jna/CallbackReference.java b/src/com/sun/jna/CallbackReference.java index bcf5568..5b15301 100644 --- a/src/com/sun/jna/CallbackReference.java +++ b/src/com/sun/jna/CallbackReference.java @@ -150,6 +150,7 @@ // Check whether direct mapping may be used, or whether // we need to fall back to conventional mapping boolean ppc = Platform.isPPC();

  • if (callback instanceof CallbackProxy) direct = false; if (direct) { Method m = getCallbackMethod(callback); Class[] ptypes = m.getParameterTypes();

Also "boolean ppc = ...;" can be put into the "if (direct) {" block

— Reply to this email directly or view it on GitHub.

dblock commented 10 years ago

This should be a PR, please.