rjb 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog CHANGED
@@ -1,3 +1,29 @@
1
+ Tue Mar 5 Kuwashima
2
+ *ext/rjb.c
3
+ *ext/rjb.h
4
+ *ext/rjbexception.c
5
+ add auto load method.
6
+ Tue Mar 4 Kuwashima
7
+ *ext/rjbexception.c
8
+ *ext/rjb.c
9
+ *test/test.rb
10
+ clear(ignore) exception in current java thread, before some operation.
11
+ *ext/rjbexception.c
12
+ *ext/rjb.c
13
+ add auto load for Rjb::bind, Rjb::throw
14
+ *ext/rjb.c
15
+ *test/test.rb
16
+ add Rjb::unbind
17
+ *test/test.rb
18
+ add loading rubygems
19
+ Sat Feb 23 arton
20
+ *test/test.rb
21
+ let test_field metod use Test.class instead of Point.class
22
+ *test/Test.java
23
+ add a public field for testing
24
+ Fri Feb 22 arton
25
+ *ext/rjb.c
26
+ mark version 1.1.3 for the next release.
1
27
  Fri Feb 22 arton
2
28
  *ext/rjb.c
3
29
  fix field reference (bug# 18238)
data/ext/load.c CHANGED
@@ -12,7 +12,7 @@
12
12
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
13
  * Lesser General Public License for more details.
14
14
  *
15
- * $Id: load.c 43 2007-12-26 18:55:04Z kuwa1 $
15
+ * $Id: load.c 65 2008-03-26 13:19:29Z arton $
16
16
  */
17
17
 
18
18
  #include <stdlib.h>
@@ -93,6 +93,10 @@ static int load_jvm(char* jvmtype)
93
93
  #endif
94
94
  if (!jh)
95
95
  {
96
+ if (RTEST(ruby_verbose))
97
+ {
98
+ fprintf(stderr, "no JAVA_HOME environment\n");
99
+ }
96
100
  return 0;
97
101
  }
98
102
  #if defined(_WIN32)
@@ -132,6 +136,7 @@ static int load_jvm(char* jvmtype)
132
136
 
133
137
  jvmdll = rb_funcall(rb_const_get(rb_cObject, rb_intern("DL")), rb_intern("dlopen"), 1, rb_str_new2(libpath));
134
138
 
139
+ //get function pointers of JNI
135
140
  #if RJB_RUBY_VERSION_CODE < 190
136
141
  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);
137
142
  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);
@@ -281,6 +286,10 @@ int rjb_create_jvm(JNIEnv** pjenv, JavaVMInitArgs* vm_args, char* userpath, VALU
281
286
  if (!result)
282
287
  {
283
288
  result = load_bridge(*pjenv);
289
+ if (RTEST(ruby_verbose) && result < 0)
290
+ {
291
+ fprintf(stderr, "failed to load the bridge class\n");
292
+ }
284
293
  }
285
294
  return result;
286
295
  }
@@ -12,7 +12,7 @@
12
12
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
13
  * Lesser General Public License for more details.
14
14
  *
15
- * $Id: riconv.c 58 2008-01-14 08:25:07Z kuwa1 $
15
+ * $Id: riconv.c 65 2008-03-26 13:19:29Z arton $
16
16
  */
17
17
 
18
18
  #include "ruby.h"
@@ -30,10 +30,10 @@ static const char* const NL_SJIS_TABLE[] = { "SHIFT_JIS", "SHIFT_JISX0213", "WIN
30
30
 
31
31
  #if defined HAVE_SETLOCALE
32
32
  #include <locale.h>
33
+ #endif
33
34
  static const char* const LOCALE_EUC_TABLE[] = { "japanese", "ja_JP.eucJP", "japanese.euc", "ja_JP", "ja_JP.ujis" };
34
35
  static const char* const LOCALE_SJIS_TABLE[] = { "japanese.sjis", "ja_JP.SJIS" };
35
36
  static const char* const LOCALE_UTF8_TABLE[] = { "ja_JP.UTF-8", "ja_JP.utf8" };
36
- #endif
37
37
 
38
38
  #include "riconv.h"
39
39
 
@@ -108,7 +108,6 @@ static const char* get_charcode_name()
108
108
  setlocale(LC_ALL, ""); //initialize
109
109
  result = get_charcode_name_by_locale(setlocale(LC_ALL, NULL));
110
110
  #elif defined HAVE_GETENV
111
- printf("HAVE_GETENV\n");
112
111
  if (result = get_charcode_name_by_locale(getenv("LC_ALL")))
113
112
  ;
114
113
  else if (result = get_charcode_name_by_locale(getenv("LC_CTYPE")))
data/ext/rjb.c CHANGED
@@ -12,10 +12,10 @@
12
12
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
13
  * Lesser General Public License for more details.
14
14
  *
15
- * $Id: rjb.c 59 2008-02-21 19:37:15Z arton $
15
+ * $Id: rjb.c 64 2008-03-05 14:24:22Z kuwa1 $
16
16
  */
17
17
 
18
- #define RJB_VERSION "1.1.2"
18
+ #define RJB_VERSION "1.1.3"
19
19
 
20
20
  #include "ruby.h"
21
21
  #include "extconf.h"
@@ -126,7 +126,6 @@ JNIEnv* rjb_attach_current_thread(void)
126
126
  return env;
127
127
  }
128
128
 
129
-
130
129
  void rjb_release_string(JNIEnv *jenv, jstring str, const char* chrs)
131
130
  {
132
131
  (*jenv)->ReleaseStringUTFChars(jenv, str, chrs);
@@ -1745,6 +1744,14 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
1745
1744
  return Qnil;
1746
1745
  }
1747
1746
 
1747
+ /*
1748
+ * load Java Virtual Machine with default arguments.
1749
+ */
1750
+ VALUE rjb_load_vm_default()
1751
+ {
1752
+ return rjb_s_load(0, NULL, 0);
1753
+ }
1754
+
1748
1755
  /*
1749
1756
  * unload Java Virtual Machine
1750
1757
  *
@@ -1762,6 +1769,8 @@ static VALUE rjb_s_unload(int argc, VALUE* argv, VALUE self)
1762
1769
  st_foreach(RHASH_TBL(rjb_loaded_classes), clear_classes, 0);
1763
1770
  if (rjb_jvm)
1764
1771
  {
1772
+ JNIEnv* jenv = rjb_attach_current_thread();
1773
+ (*jenv)->ExceptionClear(jenv);
1765
1774
  (*rjb_jvm)->DestroyJavaVM(rjb_jvm);
1766
1775
  rjb_jvm = NULL;
1767
1776
  }
@@ -2022,8 +2031,12 @@ static VALUE rjb_newinstance_s(int argc, VALUE* argv, VALUE self)
2022
2031
  char* sig;
2023
2032
  VALUE ret = Qnil;
2024
2033
  struct jv_data* ptr;
2025
- JNIEnv* jenv = rjb_attach_current_thread();
2026
2034
  int found = 0;
2035
+ JNIEnv* jenv = NULL;
2036
+
2037
+ rjb_load_vm_default();
2038
+ jenv = rjb_attach_current_thread();
2039
+ (*jenv)->ExceptionClear(jenv);
2027
2040
 
2028
2041
  rb_scan_args(argc, argv, "1*", &vsig, &rest);
2029
2042
  sig = StringValueCStr(vsig);
@@ -2053,8 +2066,12 @@ static VALUE rjb_newinstance(int argc, VALUE* argv, VALUE self)
2053
2066
  VALUE ret = Qnil;
2054
2067
  struct jv_data* ptr;
2055
2068
  struct cls_constructor** pc;
2056
- JNIEnv* jenv = rjb_attach_current_thread();
2057
2069
  int found = 0;
2070
+ JNIEnv* jenv = NULL;
2071
+
2072
+ rjb_load_vm_default();
2073
+ jenv = rjb_attach_current_thread();
2074
+ (*jenv)->ExceptionClear(jenv);
2058
2075
 
2059
2076
  Data_Get_Struct(self, struct jv_data, ptr);
2060
2077
 
@@ -2111,8 +2128,11 @@ jclass rjb_find_class(JNIEnv* jenv, VALUE name)
2111
2128
  static VALUE rjb_s_bind(VALUE self, VALUE rbobj, VALUE itfname)
2112
2129
  {
2113
2130
  VALUE result = Qnil;
2114
- JNIEnv* jenv = rjb_attach_current_thread();
2115
-
2131
+ JNIEnv* jenv = NULL;
2132
+
2133
+ rjb_load_vm_default();
2134
+ jenv = rjb_attach_current_thread();
2135
+ (*jenv)->ExceptionClear(jenv);
2116
2136
  jclass itf = rjb_find_class(jenv, itfname);
2117
2137
  rjb_check_exception(jenv, 1);
2118
2138
  if (itf)
@@ -2137,6 +2157,18 @@ static VALUE rjb_s_bind(VALUE self, VALUE rbobj, VALUE itfname)
2137
2157
  return result;
2138
2158
  }
2139
2159
 
2160
+ /*
2161
+ * jclass Rjb::bind(rbobj, interface_name)
2162
+ */
2163
+ static VALUE rjb_s_unbind(VALUE self, VALUE rbobj)
2164
+ {
2165
+ JNIEnv* jenv;
2166
+ rjb_load_vm_default();
2167
+ jenv = rjb_attach_current_thread();
2168
+ (*jenv)->ExceptionClear(jenv);
2169
+ return rb_ary_delete(proxies, rbobj);
2170
+ }
2171
+
2140
2172
  /*
2141
2173
  * Jclass Rjb::import(classname)
2142
2174
  */
@@ -2150,12 +2182,9 @@ static VALUE rjb_s_import(VALUE self, VALUE clsname)
2150
2182
  return v;
2151
2183
  }
2152
2184
 
2153
- if (!rjb_jvm)
2154
- {
2155
- /* auto-load with default setting */
2156
- rjb_s_load(0, NULL, 0);
2157
- }
2185
+ rjb_load_vm_default();
2158
2186
  jenv = rjb_attach_current_thread();
2187
+ (*jenv)->ExceptionClear(jenv);
2159
2188
  jcls = rjb_find_class(jenv, clsname);
2160
2189
  if (!jcls)
2161
2190
  {
@@ -2725,6 +2754,7 @@ void Init_rjbcore()
2725
2754
  rb_define_module_function(rjb, "unload", rjb_s_unload, -1);
2726
2755
  rb_define_module_function(rjb, "import", rjb_s_import, 1);
2727
2756
  rb_define_module_function(rjb, "bind", rjb_s_bind, 2);
2757
+ rb_define_module_function(rjb, "unbind", rjb_s_unbind, 1);
2728
2758
  rb_define_module_function(rjb, "classes", rjb_s_classes, 0);
2729
2759
  rb_define_module_function(rjb, "throw", rjb_s_throw, -1);
2730
2760
  rb_define_module_function(rjb, "primitive_conversion=", rjb_s_set_pconversion, 1);
data/ext/rjb.h CHANGED
@@ -12,7 +12,7 @@
12
12
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
13
  * Lesser General Public License for more details.
14
14
  *
15
- * $Id: rjb.h 53 2008-01-09 11:13:33Z arton $
15
+ * $Id: rjb.h 64 2008-03-05 14:24:22Z kuwa1 $
16
16
  * $Log: rjb.h,v $
17
17
  * Revision 1.1 2005/01/16 17:36:10 arton
18
18
  * Initial revision
@@ -68,6 +68,7 @@ extern jmethodID rjb_throwable_getMessage;
68
68
  extern JNIEnv* rjb_attach_current_thread(void);
69
69
  extern jclass rjb_find_class(JNIEnv* jenv, VALUE name);
70
70
  extern void rjb_release_string(JNIEnv *jenv, jstring str, const char* chrs);
71
+ extern VALUE rjb_load_vm_default();
71
72
 
72
73
  /* in rjbexception.c */
73
74
  extern VALUE rjb_get_exception_class(JNIEnv* jenv, jstring str);
@@ -12,7 +12,7 @@
12
12
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
13
  * Lesser General Public License for more details.
14
14
  *
15
- * $Id: rjbexception.c 47 2007-12-28 06:39:43Z arton $
15
+ * $Id: rjbexception.c 64 2008-03-05 14:24:22Z kuwa1 $
16
16
  */
17
17
 
18
18
  #include "ruby.h"
@@ -66,7 +66,13 @@ VALUE rjb_s_throw(int argc, VALUE* argv, VALUE self)
66
66
  {
67
67
  VALUE klass;
68
68
  VALUE message;
69
- JNIEnv* jenv = rjb_attach_current_thread();
69
+ JNIEnv* jenv = NULL;
70
+
71
+ rjb_load_vm_default();
72
+
73
+ jenv = rjb_attach_current_thread();
74
+ (*jenv)->ExceptionClear(jenv);
75
+
70
76
  if (rb_scan_args(argc, argv, "11", &klass, &message) == 2)
71
77
  {
72
78
  jclass excep = rjb_find_class(jenv, klass);
@@ -1,8 +1,13 @@
1
1
  #!/usr/local/env ruby
2
- # $Id: test.rb 58 2008-01-14 08:25:07Z kuwa1 $
2
+ # $Id: test.rb 63 2008-03-04 15:34:24Z kuwa1 $
3
3
 
4
+ begin
5
+ require 'rjb'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rjb'
9
+ end
4
10
  require 'test/unit'
5
- require 'rjb'
6
11
 
7
12
  puts "start RJB(#{Rjb::VERSION}) test"
8
13
  class TestRjb < Test::Unit::TestCase
@@ -226,6 +231,12 @@ class TestRjb < Test::Unit::TestCase
226
231
  assert("43210", a.concat(it))
227
232
  end
228
233
 
234
+ def test_unbind()
235
+ it = TestIter.new
236
+ it = bind(it, 'java.util.Iterator')
237
+ assert(it, unbind(it))
238
+ end
239
+
229
240
  class TestComparator
230
241
  def compare(o1, o2)
231
242
  o1.to_i - o2.to_i
@@ -330,13 +341,46 @@ class TestRjb < Test::Unit::TestCase
330
341
  end
331
342
  end
332
343
 
344
+ def test_throw_clear()
345
+ assert_nothing_raised {
346
+ begin
347
+ Rjb::throw('java.util.NoSuchElementException', 'test exception')
348
+ rescue #drop ruby exception
349
+ end
350
+ test = import('jp.co.infoseek.hp.arton.rjb.Test')
351
+ begin
352
+ Rjb::throw('java.util.NoSuchElementException', 'test exception')
353
+ rescue #drop ruby exception
354
+ end
355
+ test.new
356
+ begin
357
+ Rjb::throw('java.util.NoSuchElementException', 'test exception')
358
+ rescue #drop ruby exception
359
+ end
360
+ @jString.new_with_sig('Ljava.lang.String;', "abcde")
361
+ begin
362
+ Rjb::throw('java.util.NoSuchElementException', 'test exception')
363
+ rescue #drop ruby exception
364
+ end
365
+ it = TestIterator.new(0)
366
+ it = bind(it, 'java.util.Iterator')
367
+ begin
368
+ Rjb::throw('java.util.NoSuchElementException', 'test exception')
369
+ rescue NoSuchElementException
370
+ end
371
+ begin
372
+ Rjb::throw('java.lang.IllegalAccessException', 'test exception')
373
+ rescue IllegalAccessException
374
+ end
375
+ unbind(it)
376
+ }
377
+ end
378
+
333
379
  def test_field()
334
- point = import('java.awt.Point')
335
- pnt = point.new(11, 13)
336
- assert_equal(11, pnt.x)
337
- assert_equal(13, pnt.y)
338
- pnt.x = 32
339
- assert_equal(32, pnt.x)
380
+ test = import('jp.co.infoseek.hp.arton.rjb.Test').new
381
+ assert_equal('Hello World !!', test.helloData)
382
+ test.helloData = 'Goodby World !'
383
+ assert_equal('Goodby World !', test.helloData)
340
384
  end
341
385
 
342
386
  def test_instancemethod_from_class()
metadata CHANGED
@@ -1,71 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
3
- specification_version: 1
4
2
  name: rjb
5
3
  version: !ruby/object:Gem::Version
6
- version: 1.1.2
7
- date: 2008-02-22 00:00:00 +09:00
8
- summary: Ruby Java bridge
9
- require_paths:
10
- - lib
11
- email: artonx@gmail.com
12
- homepage: http://rjb.rubyforge.org/
13
- rubyforge_project:
14
- description: RJB is a bridge program that connect between Ruby and Java with Java Native Interface.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: false
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.8.2
24
- version:
4
+ version: 1.1.3
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - arton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-03-26 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: RJB is a bridge program that connect between Ruby and Java with Java Native Interface.
17
+ email: artonx@gmail.com
18
+ executables: []
19
+
20
+ extensions:
21
+ - ext/extconf.rb
22
+ extra_rdoc_files: []
23
+
31
24
  files:
32
25
  - ext/RBridge.java
33
26
  - ext/load.c
34
- - ext/rjbexception.c
35
27
  - ext/riconv.c
36
28
  - ext/rjb.c
29
+ - ext/rjbexception.c
30
+ - ext/extconf.h
37
31
  - ext/jniwrap.h
38
- - ext/rjb.h
39
- - ext/riconv.h
40
32
  - ext/jp_co_infoseek_hp_arton_rjb_RBridge.h
41
- - ext/extconf.h
33
+ - ext/riconv.h
34
+ - ext/rjb.h
42
35
  - ext/depend
43
36
  - data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class
44
37
  - lib/rjb.rb
45
38
  - samples/filechooser.rb
46
39
  - test/gctest.rb
47
40
  - test/test.rb
41
+ - test/jp/co/infoseek/hp/arton/rjb/Base.class
48
42
  - test/jp/co/infoseek/hp/arton/rjb/ExtBase.class
49
- - test/jp/co/infoseek/hp/arton/rjb/Test.class
50
43
  - test/jp/co/infoseek/hp/arton/rjb/IBase.class
51
- - test/jp/co/infoseek/hp/arton/rjb/Base.class
52
44
  - test/jp/co/infoseek/hp/arton/rjb/Test$TestTypes.class
45
+ - test/jp/co/infoseek/hp/arton/rjb/Test.class
53
46
  - COPYING
54
47
  - ChangeLog
55
48
  - readme.sj
56
49
  - readme.txt
57
- test_files:
58
- - test/test.rb
50
+ has_rdoc: false
51
+ homepage: http://rjb.rubyforge.org/
52
+ post_install_message:
59
53
  rdoc_options: []
60
54
 
61
- extra_rdoc_files: []
62
-
63
- executables: []
64
-
65
- extensions:
66
- - ext/extconf.rb
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.2
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
67
69
  requirements:
68
70
  - none
69
71
  - JDK 5.0
70
- dependencies: []
71
-
72
+ rubyforge_project:
73
+ rubygems_version: 1.0.1
74
+ signing_key:
75
+ specification_version: 2
76
+ summary: Ruby Java bridge
77
+ test_files:
78
+ - test/test.rb