From 3141ed0fe01e5e5cd726dc6410f49a0323361d94 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 29 Nov 2005 18:34:58 +0000 Subject: re PR java/18278 (JNI functions cannot return a weak reference) gcc/java: PR java/18278: * expr.c (build_jni_stub): Unwrap the return value. * java-tree.h (soft_unwrapjni_node): New define. (enum java_tree_index): Added JTI_SOFT_UNWRAPJNI_NODE. * decl.c (java_init_decl_processing): Initialize soft_unwrapjni_node. libjava: PR java/18278: * testsuite/libjava.jni/pr18278.out: New file. * testsuite/libjava.jni/pr18278.c: New file. * testsuite/libjava.jni/pr18278.java: New file. * include/jvm.h (_Jv_UnwrapJNIweakReference): Declare. * jni.cc (_Jv_UnwrapJNIweakReference): New function. (call): Unwrap return value if needed. From-SVN: r107676 --- gcc/java/expr.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'gcc/java/expr.c') diff --git a/gcc/java/expr.c b/gcc/java/expr.c index a21e151..4c2f3f4 100644 --- a/gcc/java/expr.c +++ b/gcc/java/expr.c @@ -2558,8 +2558,17 @@ build_jni_stub (tree method) /* If the JNI call returned a result, capture it here. If we had to unwrap JNI object results, we would do that here. */ if (res_var != NULL_TREE) - call = build2 (MODIFY_EXPR, TREE_TYPE (TREE_TYPE (method)), - res_var, call); + { + /* If the call returns an object, it may return a JNI weak + reference, in which case we must unwrap it. */ + if (! JPRIMITIVE_TYPE_P (TREE_TYPE (TREE_TYPE (method)))) + call = build3 (CALL_EXPR, TREE_TYPE (TREE_TYPE (method)), + build_address_of (soft_unwrapjni_node), + build_tree_list (NULL_TREE, call), + NULL_TREE); + call = build2 (MODIFY_EXPR, TREE_TYPE (TREE_TYPE (method)), + res_var, call); + } TREE_SIDE_EFFECTS (call) = 1; CAN_COMPLETE_NORMALLY (call) = 1; -- cgit v1.1