Index: test/test.rb =================================================================== --- test/test.rb (revision 62) +++ test/test.rb (working copy) @@ -1,6 +1,7 @@ #!/usr/local/env ruby # $Id$ +puts "No gems" rescue require 'rubygems' require 'test/unit' require 'rjb' @@ -226,6 +227,12 @@ assert("43210", a.concat(it)) end + def test_unbind() + it = TestIter.new + it = bind(it, 'java.util.Iterator') + assert(it, unbind(it)) + end + class TestComparator def compare(o1, o2) o1.to_i - o2.to_i Index: ext/load.c =================================================================== --- ext/load.c (revision 62) +++ ext/load.c (working copy) @@ -132,6 +132,7 @@ jvmdll = rb_funcall(rb_const_get(rb_cObject, rb_intern("DL")), rb_intern("dlopen"), 1, rb_str_new2(libpath)); + //get function pointers of JNI #if RJB_RUBY_VERSION_CODE < 190 getdefaultjavavminitargsfunc = rb_funcall(rb_funcall(rb_funcall(jvmdll, rb_intern("[]"), 2, rb_str_new2("JNI_GetDefaultJavaVMInitArgs"), rb_str_new2("IP")), rb_intern("to_ptr"), 0), rb_intern("to_i"), 0); createjavavmfunc = rb_funcall(rb_funcall(rb_funcall(jvmdll, rb_intern("[]"), 2, rb_str_new2("JNI_CreateJavaVM"), rb_str_new2("IPPP")), rb_intern("to_ptr"), 0), rb_intern("to_i"), 0); Index: ext/rjbexception.c =================================================================== --- ext/rjbexception.c (revision 62) +++ ext/rjbexception.c (working copy) @@ -67,6 +67,13 @@ VALUE klass; VALUE message; JNIEnv* jenv = rjb_attach_current_thread(); + + if (!rjb_jvm) + { + /* auto-load with default setting */ + rjb_s_load(0, NULL, 0); + } + if (rb_scan_args(argc, argv, "11", &klass, &message) == 2) { jclass excep = rjb_find_class(jenv, klass); Index: ext/rjb.c =================================================================== --- ext/rjb.c (revision 62) +++ ext/rjb.c (working copy) @@ -66,6 +66,14 @@ static JNIEnv* main_jenv; static VALUE primitive_conversion = Qfalse; +/* auto-load with default setting */\ +#define rjb_load_vm_default() do {\ + if (!rjb_jvm) \ + {\ + rjb_s_load(0, NULL, 0);\ + }\ +} while (0) + /* * Object cache, never destroyed */ @@ -1762,6 +1770,8 @@ st_foreach(RHASH_TBL(rjb_loaded_classes), clear_classes, 0); if (rjb_jvm) { + JNIEnv* jenv = rjb_attach_current_thread(); + (*jenv)->ExceptionClear(jenv); (*rjb_jvm)->DestroyJavaVM(rjb_jvm); rjb_jvm = NULL; } @@ -2022,9 +2032,13 @@ char* sig; VALUE ret = Qnil; struct jv_data* ptr; - JNIEnv* jenv = rjb_attach_current_thread(); int found = 0; + JNIEnv* jenv = NULL; + rjb_load_vm_default(); + jenv = rjb_attach_current_thread(); + (*jenv)->ExceptionClear(jenv); + rb_scan_args(argc, argv, "1*", &vsig, &rest); sig = StringValueCStr(vsig); Data_Get_Struct(self, struct jv_data, ptr); @@ -2053,8 +2067,12 @@ VALUE ret = Qnil; struct jv_data* ptr; struct cls_constructor** pc; - JNIEnv* jenv = rjb_attach_current_thread(); int found = 0; + JNIEnv* jenv = NULL; + + rjb_load_vm_default(); + jenv = rjb_attach_current_thread(); + (*jenv)->ExceptionClear(jenv); Data_Get_Struct(self, struct jv_data, ptr); @@ -2111,8 +2129,11 @@ static VALUE rjb_s_bind(VALUE self, VALUE rbobj, VALUE itfname) { VALUE result = Qnil; - JNIEnv* jenv = rjb_attach_current_thread(); - + JNIEnv* jenv = NULL; + + rjb_load_vm_default(); + jenv = rjb_attach_current_thread(); + (*jenv)->ExceptionClear(jenv); jclass itf = rjb_find_class(jenv, itfname); rjb_check_exception(jenv, 1); if (itf) @@ -2138,6 +2159,18 @@ } /* + * jclass Rjb::bind(rbobj, interface_name) + */ +static VALUE rjb_s_unbind(VALUE self, VALUE rbobj) +{ + JNIEnv* jenv; + rjb_load_vm_default(); + jenv = rjb_attach_current_thread(); + (*jenv)->ExceptionClear(jenv); + return rb_ary_delete(proxies, rbobj); +} + +/* * Jclass Rjb::import(classname) */ static VALUE rjb_s_import(VALUE self, VALUE clsname) @@ -2150,12 +2183,9 @@ return v; } - if (!rjb_jvm) - { - /* auto-load with default setting */ - rjb_s_load(0, NULL, 0); - } + rjb_load_vm_default(); jenv = rjb_attach_current_thread(); + (*jenv)->ExceptionClear(jenv); jcls = rjb_find_class(jenv, clsname); if (!jcls) { @@ -2725,6 +2755,7 @@ rb_define_module_function(rjb, "unload", rjb_s_unload, -1); rb_define_module_function(rjb, "import", rjb_s_import, 1); rb_define_module_function(rjb, "bind", rjb_s_bind, 2); + rb_define_module_function(rjb, "unbind", rjb_s_unbind, 1); rb_define_module_function(rjb, "classes", rjb_s_classes, 0); rb_define_module_function(rjb, "throw", rjb_s_throw, -1); rb_define_module_function(rjb, "primitive_conversion=", rjb_s_set_pconversion, 1); Index: ChangeLog =================================================================== --- ChangeLog (revision 62) +++ ChangeLog (working copy) @@ -1,3 +1,13 @@ +Tue Mar 4 Kuwashima + *ext/rjbexception.c + *ext/rjb.c + *ext/load.c + clear(ignore) exception in current java thread, before some operation. +Wed Feb 27 Kuwashima + *ext/rjb.c + *test/Test.rb + add auto load for Rjb::bind,Rjb::throw + add Rjb::unbind Sat Feb 23 arton *test/test.rb let test_field metod use Test.class instead of Point.class