Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

direct-mapping with type-mapper return-types crashes #317

Closed
marco2357 opened this issue Apr 7, 2014 · 2 comments
Closed

direct-mapping with type-mapper return-types crashes #317

marco2357 opened this issue Apr 7, 2014 · 2 comments
Labels

Comments

@marco2357
Copy link
Contributor

If OwnString is handled in a type mapper (instead of being NativeMapped), calling this strstr() method will crash due to the return type (arguments work, return types not):

class Test {
   static {
      Native.register(NativeLibrary.getInstance(C_LIBRARY_NAME, mapWithOwnTypeMapper));
   }

   private static native OwnString strstr(OwnString haystack, OwnString needle);
}

Here the fix (the result is created but never used/assigned):

diff --git a/native/dispatch.c b/native/dispatch.c
index 71fd083..fc17dd7 100644
--- a/native/dispatch.c
+++ b/native/dispatch.c
@@ -1149,6 +1149,9 @@
       if (type->type != FFI_TYPE_POINTER) {
         extract_value(env, obj, result, type->size, JNI_TRUE);
       }
+      else {
+        *(jobject*)result = obj;
+      }
     }
   }
 }
@twall
Copy link
Contributor

twall commented Apr 7, 2014

Please provide an associated test case in a PR.

Thanks

On Apr 7, 2014, at 9:17 AM, marco2357 notifications@github.com wrote:

If OwnString is handled in a type mapper (instead of being NativeMapped), calling this strstr() method will crash due to the return type (arguments work, return types not):

class Test {
static {
Native.register(NativeLibrary.getInstance(C_LIBRARY_NAME, mapWithOwnTypeMapper));
}

private static native OwnString strstr(OwnString haystack, OwnString needle);
}

Here the fix (the result is created but never used/assigned):

diff --git a/native/dispatch.c b/native/dispatch.c
index 71fd083..fc17dd7 100644
--- a/native/dispatch.c
+++ b/native/dispatch.c
@@ -1149,6 +1149,9 @@
if (type->type != FFI_TYPE_POINTER) {
extract_value(env, obj, result, type->size, JNI_TRUE);
}

  •  else {
    
  •    _(jobject_)result = obj;
    
  •  }
    
    }
    }
    }


Reply to this email directly or view it on GitHub.

@dblock
Copy link
Member

dblock commented Jun 24, 2014

Closed via #319.

@dblock dblock closed this as completed Jun 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants