rjb 1.0.8-mswin32 → 1.0.9-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,12 @@
1
+ Sun Sep 23 arton
2
+ *rjb.c
3
+ version 1.0.9
4
+ convert to Ruby's type if Rjb::primitive_converion is enalbed and the result type is java.lang.Object
5
+ support the object conversion for a bignum to long.
6
+ Sat Sep 15 arton
7
+ *rjb.c
8
+ version 1.0.8
9
+ correction of 1.0.7, support long type.
1
10
  Fri Sep 14 arton
2
11
  *rjb.c
3
12
  version 1.0.7
@@ -1,11 +1,11 @@
1
- /* DO NOT EDIT THIS FILE - it is machine generated */
1
+ /* DO NOT EDIT THIS FILE - it is machine generated */
2
2
  #include <jni.h>
3
- /* Header for class jp_co_infoseek_hp_arton_rjb_RBridge */
4
-
5
- #ifndef _Included_jp_co_infoseek_hp_arton_rjb_RBridge
3
+ /* Header for class jp_co_infoseek_hp_arton_rjb_RBridge */
4
+
5
+ #ifndef _Included_jp_co_infoseek_hp_arton_rjb_RBridge
6
6
  #define _Included_jp_co_infoseek_hp_arton_rjb_RBridge
7
- #ifdef __cplusplus
8
- extern "C" {
7
+ #ifdef __cplusplus
8
+ extern "C" {
9
9
  #endif
10
10
  /*
11
11
  * Class: jp_co_infoseek_hp_arton_rjb_RBridge
@@ -13,9 +13,9 @@ extern "C" {
13
13
  * Signature: (Ljava/lang/String;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
14
14
  */
15
15
  JNIEXPORT jobject JNICALL Java_jp_co_infoseek_hp_arton_rjb_RBridge_call
16
- (JNIEnv *, jobject, jstring, jobject, jobjectArray);
16
+ (JNIEnv *, jobject, jstring, jobject, jobjectArray);
17
17
 
18
- #ifdef __cplusplus
19
- }
18
+ #ifdef __cplusplus
19
+ }
20
20
  #endif
21
21
  #endif
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 19 2007-09-14 14:59:29Z arton $
15
+ * $Id: rjb.c 25 2007-09-23 00:30:23Z arton $
16
16
  */
17
17
 
18
- #define RJB_VERSION "1.0.8"
18
+ #define RJB_VERSION "1.0.9"
19
19
 
20
20
  #include "ruby.h"
21
21
  #include "st.h"
@@ -520,6 +520,7 @@ static VALUE jv2rv_withprim(JNIEnv* jenv, jobject o)
520
520
  jvalue jv;
521
521
  int i;
522
522
  jclass klass = (*jenv)->GetObjectClass(jenv, o);
523
+ jv.j = 0;
523
524
  for (i = PRM_INT; i < PRM_LAST; i++)
524
525
  {
525
526
  if ((*jenv)->IsSameObject(jenv, jpcvt[i].klass, klass))
@@ -545,9 +546,14 @@ static VALUE jv2rv_withprim(JNIEnv* jenv, jobject o)
545
546
  rb_raise(rb_eRuntimeError, "no convertor defined(%d)", i);
546
547
  break;
547
548
  }
549
+ (*jenv)->DeleteLocalRef(jenv, o);
548
550
  return jpcvt[i].func(jenv, jv);
549
551
  }
550
552
  }
553
+ if ((*jenv)->IsSameObject(jenv, j_string, klass))
554
+ {
555
+ return jstring2val(jenv, o);
556
+ }
551
557
  jv.l = o;
552
558
  return jv2rv_r(jenv, jv);
553
559
  }
@@ -755,11 +761,21 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
755
761
  case T_FLOAT:
756
762
  arg.d = NUM2DBL(val);
757
763
  jv->l = (*jenv)->NewObject(jenv, jpcvt[PRM_DOUBLE].klass,
758
- jpcvt[PRM_DOUBLE].ctr_id, arg);
764
+ jpcvt[PRM_DOUBLE].ctr_id, arg.d);
759
765
  break;
760
766
  case T_ARRAY:
761
767
  jv->l = r2objarray(jenv, val, "Ljava/lang/Object;");
762
768
  break;
769
+ #if HAVE_LONG_LONG
770
+ case T_BIGNUM:
771
+ arg.j = rb_big2ll(val);
772
+ jv->l = (*jenv)->NewObject(jenv, jpcvt[PRM_LONG].klass,
773
+ jpcvt[PRM_LONG].ctr_id, arg);
774
+ break;
775
+ #endif
776
+ default:
777
+ rb_raise(rb_eRuntimeError, "can't convert to java type");
778
+ break;
763
779
  }
764
780
  }
765
781
  }
@@ -770,8 +786,9 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
770
786
  case T_STRING:
771
787
  case T_FLOAT:
772
788
  case T_ARRAY:
773
- (*jenv)->DeleteLocalRef(jenv, jv->l);
774
- break;
789
+ case T_BIGNUM:
790
+ if (jv->l) (*jenv)->DeleteLocalRef(jenv, jv->l);
791
+ break;
775
792
  }
776
793
  }
777
794
  }
data/lib/rjbcore.so CHANGED
Binary file
data/test/test.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/local/env ruby
2
- # $Id: test.rb 19 2007-09-14 14:59:29Z arton $
2
+ # $Id: test.rb 23 2007-09-22 23:07:05Z arton $
3
3
 
4
4
  require 'test/unit'
5
5
  require 'rjb'
@@ -10,6 +10,16 @@ class TestRjb < Test::Unit::TestCase
10
10
  def setup
11
11
  load('.')
12
12
  Rjb::primitive_conversion = false
13
+
14
+ @jString = import('java.lang.String')
15
+ @jInteger = Rjb::import('java.lang.Integer')
16
+ @jShort = Rjb::import('java.lang.Short')
17
+ @jDouble = Rjb::import('java.lang.Double')
18
+ @jFloat = Rjb::import('java.lang.Float')
19
+ @jBoolean = Rjb::import('java.lang.Boolean')
20
+ @jByte = Rjb::import('java.lang.Byte')
21
+ @jLong = Rjb::import('java.lang.Long')
22
+ @jChar = Rjb::import('java.lang.Character')
13
23
  end
14
24
 
15
25
  def tearDown
@@ -24,14 +34,13 @@ class TestRjb < Test::Unit::TestCase
24
34
  end
25
35
 
26
36
  def test_scalar
27
- cls = import('java.lang.String')
28
- assert_equal('java.lang.Class', cls._classname)
29
- assert_equal('class java.lang.String', cls.toString)
30
- str = cls.new
37
+ assert_equal('java.lang.Class', @jString._classname)
38
+ assert_equal('class java.lang.String', @jString.toString)
39
+ str = @jString.new
31
40
  assert_equal('java.lang.String', str._classname)
32
41
  assert_equal(0, str.length)
33
42
  assert_equal('', str.toString)
34
- str = cls.new_with_sig('Ljava.lang.String;', "abcde")
43
+ str = @jString.new_with_sig('Ljava.lang.String;', "abcde")
35
44
  # result integer
36
45
  assert_equal(5, str.length)
37
46
  # result string
@@ -45,14 +54,13 @@ class TestRjb < Test::Unit::TestCase
45
54
  assert_equal('bc', str.substring(1, 3))
46
55
  assert_equal('e', str.substring(4))
47
56
  # float with static
48
- assert_equal('5.23', cls._invoke('valueOf', 'F', 5.23))
49
- assert_equal('25.233', cls._invoke('valueOf', 'D', 25.233))
57
+ assert_equal('5.23', @jString._invoke('valueOf', 'F', 5.23))
58
+ assert_equal('25.233', @jString._invoke('valueOf', 'D', 25.233))
50
59
  # rjb object (String)
51
- str2 = cls.new_with_sig('Ljava.lang.String;', 'fghijk')
60
+ str2 = @jString.new_with_sig('Ljava.lang.String;', 'fghijk')
52
61
  assert_equal('abcdefghijk', str.concat(str2))
53
62
  # rjb object other (implicit toString call is Rjb feature)
54
- jint = import('java.lang.Integer')
55
- i = jint.new_with_sig('I', 35901)
63
+ i = @jInteger.new_with_sig('I', 35901)
56
64
  assert_equal('abcde35901', str.concat(i))
57
65
  # result boolean and argument is rjb object
58
66
  assert_equal(false, i.equals(str))
@@ -60,35 +68,28 @@ class TestRjb < Test::Unit::TestCase
60
68
  assert_equal(true, str.equals("abcde"))
61
69
  assert_equal(true, str.equals(str))
62
70
  # long
63
- lng = import('java.lang.Long')
64
- l = lng.new_with_sig('J', -9223372036854775808)
71
+ l = @jLong.new_with_sig('J', -9223372036854775808)
65
72
  assert_equal(-9223372036854775808, l.longValue)
66
- l = lng.new_with_sig('J', 9223372036854775807)
73
+ l = @jLong.new_with_sig('J', 9223372036854775807)
67
74
  assert_equal(9223372036854775807, l.longValue)
68
75
  # double
69
- dbl = import('java.lang.Double')
70
- d = dbl.new_with_sig('D', 1234.5678901234567890)
76
+ d = @jDouble.new_with_sig('D', 1234.5678901234567890)
71
77
  assert_equal(1234.5678901234567890, d.doubleValue)
72
78
  # byte
73
- byt = import('java.lang.Byte')
74
- b = byt.new_with_sig('B', 13)
79
+ b = @jByte.new_with_sig('B', 13)
75
80
  assert_equal(13, b.byteValue)
76
81
  # float
77
- flt = import('java.lang.Float')
78
- f = flt.new_with_sig('F', 13.5)
82
+ f = @jFloat.new_with_sig('F', 13.5)
79
83
  assert_equal(13.5, f.floatValue)
80
84
  # short
81
- sht = import('java.lang.Short')
82
- s = sht.new_with_sig('S', 1532)
85
+ s = @jShort.new_with_sig('S', 1532)
83
86
  assert_equal(1532, s.shortValue)
84
- chr = import('java.lang.Character')
85
- c = chr.new_with_sig('C', ?A)
87
+ c = @jChar.new_with_sig('C', ?A)
86
88
  assert_equal(?A, c.charValue)
87
89
  end
88
90
 
89
91
  def test_array
90
- cls = import('java.lang.String')
91
- str = cls.new_with_sig('[C', [?a, ?b, ?c, ?d, ?e, ?c, ?f, ?c, ?g])
92
+ str = @jString.new_with_sig('[C', [?a, ?b, ?c, ?d, ?e, ?c, ?f, ?c, ?g])
92
93
  assert_equal('abcdecfcg', str.toString)
93
94
  # conv string array
94
95
  splt = str.split('c')
@@ -113,20 +114,18 @@ class TestRjb < Test::Unit::TestCase
113
114
  else
114
115
  assert_equal(Dir::pwd, props.getProperty('user.dir').gsub('\\', '/'))
115
116
  end
116
- boolean = import('java.lang.Boolean')
117
- assert_equal(boolean.valueOf(true).booleanValue(), true)
118
- assert_equal(boolean.valueOf(false).booleanValue(), false)
119
- assert_equal(boolean.valueOf('true').booleanValue(), true)
120
- assert_equal(boolean.valueOf('false').booleanValue(), false)
117
+ assert_equal(@jBoolean.valueOf(true).booleanValue(), true)
118
+ assert_equal(@jBoolean.valueOf(false).booleanValue(), false)
119
+ assert_equal(@jBoolean.valueOf('true').booleanValue(), true)
120
+ assert_equal(@jBoolean.valueOf('false').booleanValue(), false)
121
121
  end
122
122
 
123
123
  def test_importobjarray()
124
124
  jarray = import('java.util.ArrayList')
125
125
  a = jarray.new()
126
- jint = import('java.lang.Integer')
127
- a.add(jint.new_with_sig('I', 1))
128
- a.add(jint.new_with_sig('I', 2))
129
- a.add(jint.new_with_sig('I', 3))
126
+ a.add(@jInteger.new_with_sig('I', 1))
127
+ a.add(@jInteger.new_with_sig('I', 2))
128
+ a.add(@jInteger.new_with_sig('I', 3))
130
129
  oa = a.toArray
131
130
  assert_equal(3, oa.size)
132
131
  assert_equal(1, oa[0].intValue)
@@ -136,20 +135,18 @@ class TestRjb < Test::Unit::TestCase
136
135
 
137
136
  def test_kjconv()
138
137
  $KCODE = 'euc'
139
- cls = import('java.lang.String')
140
138
  euc_kj = "\xb4\xc1\xbb\xfa\xa5\xc6\xa5\xad\xa5\xb9\xa5\xc8"
141
- s = cls.new(euc_kj)
139
+ s = @jString.new(euc_kj)
142
140
  assert_equal(s.toString(), euc_kj)
143
141
  $KCODE = 'sjis'
144
142
  sjis_kj = "\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67"
145
- s = cls.new(sjis_kj)
143
+ s = @jString.new(sjis_kj)
146
144
  assert_equal(s.toString(), sjis_kj)
147
145
  end
148
146
 
149
147
  def test_constants()
150
- lng = import('java.lang.Long')
151
- assert_equal(0x7fffffffffffffff, lng.MAX_VALUE)
152
- assert_equal(-9223372036854775808, lng.MIN_VALUE)
148
+ assert_equal(0x7fffffffffffffff, @jLong.MAX_VALUE)
149
+ assert_equal(-9223372036854775808, @jLong.MIN_VALUE)
153
150
  end
154
151
 
155
152
  class TestIter
@@ -195,9 +192,8 @@ class TestRjb < Test::Unit::TestCase
195
192
  # assert_raise is useless in this test, because NumberFormatException may be defined in
196
193
  # its block.
197
194
  def test_exception()
198
- it = import('java.lang.Integer')
199
195
  begin
200
- it.parseInt('blabla')
196
+ @jInteger.parseInt('blabla')
201
197
  flunk('no exception')
202
198
  rescue NumberFormatException => e
203
199
  # OK
@@ -265,7 +261,7 @@ class TestRjb < Test::Unit::TestCase
265
261
  rescue TypeError => e
266
262
  end
267
263
  begin
268
- throw(import('java.lang.String').new('a'))
264
+ throw(@jString.new('a'))
269
265
  flunk('no exception')
270
266
  rescue RuntimeError => e
271
267
  assert_equal('arg1 must be a throwable', e.message)
@@ -289,9 +285,8 @@ class TestRjb < Test::Unit::TestCase
289
285
 
290
286
  def test_instancemethod_from_class()
291
287
  begin
292
- cls = import('java.lang.String')
293
- assert_equal('true', cls.valueOf(true))
294
- cls.length
288
+ assert_equal('true', @jString.valueOf(true))
289
+ @jString.length
295
290
  flunk('no exception')
296
291
  rescue RuntimeError => e
297
292
  assert_equal('instance method `length\' for class', e.message)
@@ -414,9 +409,8 @@ class TestRjb < Test::Unit::TestCase
414
409
  end
415
410
 
416
411
  def test_failed_constructor_call()
417
- test = import('java.lang.String')
418
412
  begin
419
- s = test.new('a', 'b', 'c')
413
+ s = @jString.new('a', 'b', 'c')
420
414
  flunk('no exception')
421
415
  rescue RuntimeError => e
422
416
  assert(e)
@@ -441,24 +435,69 @@ class TestRjb < Test::Unit::TestCase
441
435
  assert_equal(false, Rjb::primitive_conversion)
442
436
  Rjb::primitive_conversion = true
443
437
  assert_equal(true, Rjb::primitive_conversion)
444
- jInteger = Rjb::import('java.lang.Integer')
445
- assert_equal(1, jInteger.valueOf('1'))
446
- assert_equal(-1, jInteger.valueOf('-1'))
447
- jShort = Rjb::import('java.lang.Short')
448
- assert_equal(2, jShort.valueOf('2'))
449
- assert_equal(-2, jShort.valueOf('-2'))
450
- jDouble = Rjb::import('java.lang.Double')
451
- assert_equal(3.1, jDouble.valueOf('3.1'))
452
- jFloat = Rjb::import('java.lang.Float')
453
- assert_equal(4.5, jFloat.valueOf('4.5'))
454
- jBoolean = Rjb::import('java.lang.Boolean')
455
- assert(jBoolean.TRUE)
456
- jByte = Rjb::import('java.lang.Byte')
457
- assert_equal(5, jByte.valueOf('5'))
458
- assert_equal(-6, jByte.valueOf('-6'))
459
- jLong = Rjb::import('java.lang.Long')
460
- assert_equal(500000, jLong.valueOf('500000'))
461
- assert_equal(-600000, jLong.valueOf('-600000'))
438
+ assert_equal(1, @jInteger.valueOf('1'))
439
+ assert_equal(-1, @jInteger.valueOf('-1'))
440
+ assert_equal(2, @jShort.valueOf('2'))
441
+ assert_equal(-2, @jShort.valueOf('-2'))
442
+ assert_equal(3.1, @jDouble.valueOf('3.1'))
443
+ assert_equal(4.5, @jFloat.valueOf('4.5'))
444
+ assert(@jBoolean.TRUE)
445
+ assert_equal(5, @jByte.valueOf('5'))
446
+ assert_equal(-6, @jByte.valueOf('-6'))
447
+ assert_equal(0x7000000000000000, @jLong.valueOf('8070450532247928832'))
448
+ assert_equal(-9223372036854775807, @jLong.valueOf('-9223372036854775807'))
449
+ assert_equal(?A, @jChar.valueOf(?A))
450
+ end
451
+
452
+ def test_obj_to_primitive
453
+ ar = Rjb::import('java.util.ArrayList')
454
+ a = ar.new
455
+ a.add @jString.new('abcdef')
456
+ a.add @jInteger.valueOf('1')
457
+ a.add @jShort.valueOf('2')
458
+ a.add @jDouble.valueOf('3.1')
459
+ a.add @jFloat.valueOf('4.5')
460
+ a.add @jBoolean.TRUE
461
+ a.add @jByte.valueOf('5')
462
+ a.add @jLong.valueOf('8070450532247928832')
463
+ a.add @jChar.valueOf(?A)
464
+
465
+ Rjb::primitive_conversion = true
466
+
467
+ assert_equal 'abcdef', a.get(0)
468
+ assert_equal 1, a.get(1)
469
+ assert_equal 2, a.get(2)
470
+ assert_equal 3.1, a.get(3)
471
+ assert_equal 4.5, a.get(4)
472
+ assert a.get(5)
473
+ assert_equal 5, a.get(6)
474
+ assert_equal 8070450532247928832, a.get(7)
475
+ assert_equal ?A, a.get(8)
476
+ end
477
+
478
+ def test_primitive_to_obj
479
+ Rjb::primitive_conversion = true
480
+
481
+ ar = Rjb::import('java.util.ArrayList')
482
+ a = ar.new
483
+ a.add @jString.new('abcdef')
484
+ a.add @jInteger.valueOf('1')
485
+ a.add @jShort.valueOf('2')
486
+ a.add @jDouble.valueOf('3.1')
487
+ a.add @jFloat.valueOf('4.5')
488
+ a.add @jBoolean.TRUE
489
+ a.add @jByte.valueOf('5')
490
+ a.add @jLong.valueOf('8070450532247928832')
491
+ a.add @jChar.valueOf(?A)
492
+ assert_equal 'abcdef', a.get(0)
493
+ assert_equal 1, a.get(1)
494
+ assert_equal 2, a.get(2)
495
+ assert_equal 3.1, a.get(3)
496
+ assert_equal 4.5, a.get(4)
497
+ assert a.get(5)
498
+ assert_equal 5, a.get(6)
499
+ assert_equal 8070450532247928832, a.get(7)
500
+ assert_equal ?A, a.get(8)
462
501
  end
463
502
  end
464
503
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: rjb
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.8
7
- date: 2007-09-15 00:00:00 +09:00
6
+ version: 1.0.9
7
+ date: 2007-09-23 00:00:00 +09:00
8
8
  summary: Ruby Java bridge
9
9
  require_paths:
10
10
  - lib