ext/rjb.c in rjb-1.3.9 vs ext/rjb.c in rjb-1.4.0
- old
+ new
@@ -10,14 +10,14 @@
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
- * $Id: rjb.c 181 2012-01-28 05:28:41Z arton $
+ * $Id: rjb.c 187 2012-04-22 12:35:49Z arton $
*/
-#define RJB_VERSION "1.3.9"
+#define RJB_VERSION "1.4.0"
#include "ruby.h"
#include "extconf.h"
#if RJB_RUBY_VERSION_CODE < 190
#include "st.h"
@@ -84,10 +84,11 @@
static VALUE rjbi;
static VALUE rjbb;
static VALUE rjba;
static ID user_initialize;
+static ID initialize_proxy;
static ID cvar_classpath;
static ID anonymousblock;
static ID id_call;
VALUE rjb_loaded_classes;
@@ -130,10 +131,11 @@
/* URLClassLoader */
static jclass j_url_loader;
static jobject url_loader;
static jmethodID url_loader_new;
static jmethodID url_geturls;
+static jmethodID url_add_url;
/* URL global reference */
static jclass j_url;
static jmethodID url_new;
enum PrimitiveType {
@@ -2097,11 +2099,11 @@
rb_str_new2("instance_eval(&" USER_INITIALIZE ")"));
}
static VALUE register_instance(JNIEnv* jenv, VALUE klass, struct jv_data* org, jobject obj)
{
- VALUE v;
+ volatile VALUE v;
VALUE iproc;
struct jvi_data* ptr = ALLOC(struct jvi_data);
memset(ptr, 0, sizeof(struct jvi_data));
v = Data_Wrap_Struct(rjbi, NULL, rjb_delete_ref, ptr);
ptr->klass = org->idata.obj;
@@ -2112,10 +2114,11 @@
if (iproc != Qnil)
{
rb_ivar_set(v, user_initialize, iproc);
rb_funcall(v, rb_intern("_prepare_proxy"), 0, 0);
}
+ rb_funcall(v, initialize_proxy, 0, 0);
return v;
}
/*
* temporary signature check
@@ -2557,31 +2560,57 @@
"(Ljava/lang/String;)Ljava/lang/Class;");
RJB_LOAD_METHOD(url_loader_new, j_url_loader, "<init>",
"([Ljava/net/URL;Ljava/lang/ClassLoader;)V");
RJB_LOAD_METHOD(url_geturls, j_url_loader, "getURLs",
"()[Ljava/net/URL;");
+ RJB_LOAD_METHOD(url_add_url, j_url_loader, "addURL",
+ "(Ljava/net/URL;)V");
}
- args[0].l = (*jenv)->NewObjectArray(jenv, (count == 0) ? 1 : count, j_url, NULL);
- rjb_check_exception(jenv, 0);
- if (!count)
+ if (!url_loader)
{
- (*jenv)->SetObjectArrayElement(jenv, args[0].l, 0,
+ args[0].l = (*jenv)->NewObjectArray(jenv, (count == 0) ? 1 : count, j_url, NULL);
+ rjb_check_exception(jenv, 0);
+ if (!count)
+ {
+ (*jenv)->SetObjectArrayElement(jenv, args[0].l, 0,
conv_jarname_to_url(jenv, jarname));
+ }
+ else
+ {
+ for (i = 0; i < count; i++) {
+ (*jenv)->SetObjectArrayElement(jenv, args[0].l, i,
+ conv_jarname_to_url(jenv, rb_ary_entry(jarname, i)));
+ }
+ }
+ rjb_check_exception(jenv, 0);
+ args[1].l = get_class_loader(jenv);
+ url_loader = (*jenv)->NewObjectA(jenv, j_url_loader, url_loader_new, args);
+ rjb_check_exception(jenv, 0);
+ (*jenv)->NewGlobalRef(jenv, url_loader);
+ (*jenv)->DeleteLocalRef(jenv, args[0].l);
}
else
{
- for (i = 0; i < count; i++) {
- (*jenv)->SetObjectArrayElement(jenv, args[0].l, i,
- conv_jarname_to_url(jenv, rb_ary_entry(jarname, i)));
+ jvalue v;
+ if (count)
+ {
+ for (i = 0; i < count; i++)
+ {
+ v.l = conv_jarname_to_url(jenv, rb_ary_entry(jarname, i));
+ (*jenv)->CallObjectMethod(jenv, url_loader, url_add_url, v);
+ rjb_check_exception(jenv, 0);
+ (*jenv)->DeleteLocalRef(jenv, v.l);
+ }
}
+ else
+ {
+ v.l = conv_jarname_to_url(jenv, jarname);
+ (*jenv)->CallObjectMethod(jenv, url_loader, url_add_url, v);
+ rjb_check_exception(jenv, 0);
+ (*jenv)->DeleteLocalRef(jenv, v.l);
+ }
}
- rjb_check_exception(jenv, 0);
- args[1].l = get_class_loader(jenv);
- url_loader = (*jenv)->NewObjectA(jenv, j_url_loader, url_loader_new, args);
- rjb_check_exception(jenv, 0);
- (*jenv)->NewGlobalRef(jenv, url_loader);
- (*jenv)->DeleteLocalRef(jenv, args[0].l);
return Qtrue;
}
static VALUE rjb_s_urls(VALUE self)
{
@@ -3157,9 +3186,10 @@
#endif
rb_global_variable(&rjb_loaded_classes);
proxies = rb_ary_new();
rb_global_variable(&proxies);
user_initialize = rb_intern(USER_INITIALIZE);
+ initialize_proxy = rb_intern("initialize_proxy");
rjb = rb_define_module("Rjb");
rb_define_module_function(rjb, "load", rjb_s_load, -1);
rb_define_module_function(rjb, "unload", rjb_s_unload, -1);
rb_define_module_function(rjb, "loaded?", rjb_s_loaded, 0);