summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d97acac)
raw | patch | inline | side by side (parent: d97acac)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 29 Mar 2009 12:00:46 +0000 (14:00 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 29 Mar 2009 12:00:46 +0000 (14:00 +0200) |
Apparently GCJ used to modify it's argument, but the spec apparently says
that the return value is important.
that the return value is important.
src/java.c | patch | blob | history |
diff --git a/src/java.c b/src/java.c
index 5d1314167fe91a900e4bc1c1de1cae9bdde8b220..d0eeeff5650c79e2b1f354dce8db0c6656e970ce 100644 (file)
--- a/src/java.c
+++ b/src/java.c
@@ -1782,7 +1782,15 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{
(*jvm_env)->ReleaseStringUTFChars (jvm_env, o_name, c_name);
- cbi->class = (*jvm_env)->GetObjectClass (jvm_env, o_callback);
+ cbi->object = (*jvm_env)->NewGlobalRef (jvm_env, o_callback);
+ if (cbi->object == NULL)
+ {
+ ERROR ("java plugin: cjni_callback_info_create: NewGlobalRef failed.");
+ free (cbi);
+ return (NULL);
+ }
+
+ cbi->class = (*jvm_env)->GetObjectClass (jvm_env, cbi->object);
if (cbi->class == NULL)
{
ERROR ("java plugin: cjni_callback_info_create: GetObjectClass failed.");
@@ -1790,8 +1798,6 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{
return (NULL);
}
- cbi->object = o_callback;
-
cbi->method = (*jvm_env)->GetMethodID (jvm_env, cbi->class,
method_name, method_signature);
if (cbi->method == NULL)
@@ -1803,8 +1809,6 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{
return (NULL);
}
- (*jvm_env)->NewGlobalRef (jvm_env, o_callback);
-
return (cbi);
} /* }}} cjni_callback_info_t cjni_callback_info_create */
JNIEnv *jvm_env;
java_plugin_class_t *class;
jmethodID constructor_id;
+ jobject tmp_object;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
return (-1);
}
- class->object = (*jvm_env)->NewObject (jvm_env, class->class,
+ tmp_object = (*jvm_env)->NewObject (jvm_env, class->class,
constructor_id);
+ if (tmp_object != NULL)
+ class->object = (*jvm_env)->NewGlobalRef (jvm_env, tmp_object);
+ else
+ class->object = NULL;
if (class->object == NULL)
{
ERROR ("java plugin: cjni_config_load_plugin: "
return (-1);
}
- (*jvm_env)->NewGlobalRef (jvm_env, class->object);
cjni_thread_detach ();
java_classes_list_len++;
int status;
size_t i;
+ jclass class;
+ jmethodID method;
+
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
WARNING ("java plugin: `Plugin' blocks "
return (-1);
}
+ class = (*jvm_env)->GetObjectClass (jvm_env, cbi->object);
+ method = (*jvm_env)->GetMethodID (jvm_env, class,
+ "config", "(Lorg/collectd/api/OConfigItem;)I");
+
status = (*jvm_env)->CallIntMethod (jvm_env,
- cbi->object, cbi->method, o_ocitem);
+ cbi->object, method, o_ocitem);
(*jvm_env)->DeleteLocalRef (jvm_env, o_ocitem);
cjni_thread_detach ();
cjni_callback_info_t *cbi_factory;
const char *name;
jobject o_ci;
+ jobject o_tmp;
int type;
size_t i;
}
/* Then call the factory method so it creates a new object for us. */
- cbi_ret->object = (*jvm_env)->CallObjectMethod (jvm_env,
+ o_tmp = (*jvm_env)->CallObjectMethod (jvm_env,
cbi_factory->object, cbi_factory->method, o_ci);
- if (cbi_ret->object == NULL)
+ if (o_tmp == NULL)
{
ERROR ("java plugin: cjni_match_target_create: CallObjectMethod failed.");
BAIL_OUT (-1);
}
+ cbi_ret->object = (*jvm_env)->NewGlobalRef (jvm_env, o_tmp);
+ if (o_tmp == NULL)
+ {
+ ERROR ("java plugin: cjni_match_target_create: NewGlobalRef failed.");
+ BAIL_OUT (-1);
+ }
+
/* This is the class of the match. It is possibly different from the class of
* the match-factory! */
cbi_ret->class = (*jvm_env)->GetObjectClass (jvm_env, cbi_ret->object);
BAIL_OUT (-1);
}
- /* We have everything we hoped for. Now we add a new global reference so this
- * match isn't freed immediately after we return.. */
- (*jvm_env)->NewGlobalRef (jvm_env, cbi_ret->object);
-
/* Return the newly created match via the user_data pointer. */
*user_data = (void *) cbi_ret;