aboutsummaryrefslogtreecommitdiff
path: root/gcc/java/expr.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2005-11-29 18:34:58 +0000
committerTom Tromey <tromey@gcc.gnu.org>2005-11-29 18:34:58 +0000
commit3141ed0fe01e5e5cd726dc6410f49a0323361d94 (patch)
tree5ba6f0f10a37c9d1c36de0493f0563ef6f583cad /gcc/java/expr.c
parent4311c8e54c31efed7aa9aaef244a4ac93fbf96d2 (diff)
downloadgcc-3141ed0fe01e5e5cd726dc6410f49a0323361d94.zip
gcc-3141ed0fe01e5e5cd726dc6410f49a0323361d94.tar.gz
gcc-3141ed0fe01e5e5cd726dc6410f49a0323361d94.tar.bz2
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
Diffstat (limited to 'gcc/java/expr.c')
-rw-r--r--gcc/java/expr.c13
1 files changed, 11 insertions, 2 deletions
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;