rjb 1.0.4-mswin32 → 1.0.6-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,4 +1,6 @@
1
1
  Tue Nov 21 arton
2
+ *rjb.c
3
+ Skip the constant registering process, if the constant was already defined.
2
4
  *load.c
3
5
  *rjb.c
4
6
  *rjbexception.c
@@ -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
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * Rjb - Ruby <-> Java Bridge
3
- * Copyright(c) 2004,2005,2006 arton
3
+ * Copyright(c) 2004,2005,2006,2007 arton
4
4
  *
5
5
  * This library is free software; you can redistribute it and/or
6
6
  * modify it under the terms of the GNU Lesser General Public
@@ -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 11 2007-05-06 10:02:52Z arton $
15
+ * $Id: rjb.c 15 2007-06-16 18:00:13Z arton $
16
16
  */
17
17
 
18
- #define RJB_VERSION "1.0.4"
18
+ #define RJB_VERSION "1.0.6"
19
19
 
20
20
  #include "ruby.h"
21
21
  #include "st.h"
@@ -1241,7 +1241,47 @@ static void setup_methodbase(JNIEnv* jenv, struct cls_constructor* pm,
1241
1241
  fill_convert(jenv, pm, parama, pcount);
1242
1242
  }
1243
1243
  }
1244
-
1244
+
1245
+ static void register_methodinfo(struct cls_method* newpm, st_table* tbl)
1246
+ {
1247
+ struct cls_method* pm;
1248
+
1249
+ if (st_lookup(tbl, newpm->name, (st_data_t*)&pm))
1250
+ {
1251
+ newpm->next = pm->next;
1252
+ pm->next = newpm;
1253
+ }
1254
+ else
1255
+ {
1256
+ newpm->next = NULL;
1257
+ st_insert(tbl, newpm->name, (VALUE)newpm);
1258
+ }
1259
+ }
1260
+
1261
+ static struct cls_method* clone_methodinfo(struct cls_method* pm)
1262
+ {
1263
+ struct cls_method* result = ALLOC(struct cls_method);
1264
+ memcpy(result, pm, sizeof(struct cls_method));
1265
+ return result;
1266
+ }
1267
+
1268
+ static void make_alias(const char* jname, char* rname)
1269
+ {
1270
+ while (*jname)
1271
+ {
1272
+ if (isupper(*jname))
1273
+ {
1274
+ *rname++ = '_';
1275
+ *rname++ = tolower(*jname++);
1276
+ }
1277
+ else
1278
+ {
1279
+ *rname++ = *jname++;
1280
+ }
1281
+ }
1282
+ *rname = '\0';
1283
+ }
1284
+
1245
1285
  static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static_method)
1246
1286
  {
1247
1287
  struct cls_method* result;
@@ -1252,6 +1292,7 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
1252
1292
  jobjectArray parama;
1253
1293
  jobject cls;
1254
1294
  jsize param_count;
1295
+ char* rname;
1255
1296
 
1256
1297
  result = ALLOC(struct cls_method);
1257
1298
  parama = (*jenv)->CallObjectMethod(jenv, m, getParameterTypes);
@@ -1259,12 +1300,13 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
1259
1300
  param_count = (*jenv)->GetArrayLength(jenv, parama);
1260
1301
  rjb_check_exception(jenv, 0);
1261
1302
  setup_methodbase(jenv, &result->basic, parama, param_count);
1262
-
1263
1303
  nm = (*jenv)->CallObjectMethod(jenv, m, method_getName);
1264
1304
  rjb_check_exception(jenv, 0);
1265
1305
  jname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
1306
+ rname = ALLOCA_N(char, strlen(jname) * 2 + 8);
1307
+ make_alias(jname, rname);
1266
1308
  result->name = rb_intern(jname);
1267
- rjb_release_string(jenv, nm, jname);
1309
+ rjb_release_string(jenv, nm, jname);
1268
1310
  result->basic.id = (*jenv)->FromReflectedMethod(jenv, m);
1269
1311
  rjb_check_exception(jenv, 0);
1270
1312
  cls = (*jenv)->CallObjectMethod(jenv, m, getReturnType);
@@ -1272,15 +1314,43 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
1272
1314
  setup_j2r(jenv, cls, result, static_method);
1273
1315
  (*jenv)->DeleteLocalRef(jenv, cls);
1274
1316
  result->static_method = static_method;
1275
- if (st_lookup(tbl, result->name, (st_data_t*)&pm))
1317
+ register_methodinfo(result, tbl);
1318
+ // create method alias
1319
+ pm = NULL;
1320
+ if (strlen(rname) > 3
1321
+ && (*rname == 'g' || *rname == 's') && *(rname + 1) == 'e' && *(rname + 2) == 't')
1322
+ {
1323
+ pm = clone_methodinfo(result);
1324
+ if (*rname == 's')
1325
+ {
1326
+ if (result->basic.arg_count == 1)
1327
+ {
1328
+ rname += 3;
1329
+ strcat(rname, "=");
1330
+ }
1331
+ }
1332
+ else
1333
+ {
1334
+ rname += 3;
1335
+ }
1336
+ if (*rname == '_') rname++;
1337
+ }
1338
+ else if (strlen(rname) > 2 && result->basic.result_signature == 'Z'
1339
+ && *rname == 'i' && *(rname + 1) == 's')
1276
1340
  {
1277
- result->next = pm->next;
1278
- pm->next = result;
1341
+ pm = clone_methodinfo(result);
1342
+ rname += 2;
1343
+ if (*rname == '_') rname++;
1344
+ strcat(rname, "?");
1279
1345
  }
1280
1346
  else
1281
1347
  {
1282
- result->next = NULL;
1283
- st_insert(tbl, result->name, (VALUE)result);
1348
+ pm = clone_methodinfo(result);
1349
+ }
1350
+ if (pm)
1351
+ {
1352
+ pm->name = rb_intern(rname);
1353
+ register_methodinfo(pm, tbl);
1284
1354
  }
1285
1355
  }
1286
1356
 
@@ -1406,6 +1476,7 @@ static void load_constants(JNIEnv* jenv, jclass klass, VALUE self, jobjectArray
1406
1476
  jvalue jv;
1407
1477
  jfieldID jfid;
1408
1478
  char sigs[256];
1479
+ char* pname;
1409
1480
 
1410
1481
  // constants make define directly in the ruby object
1411
1482
  cls = (*jenv)->CallObjectMethod(jenv, f, field_getType);
@@ -1451,21 +1522,22 @@ static void load_constants(JNIEnv* jenv, jclass klass, VALUE self, jobjectArray
1451
1522
  jv.l = (*jenv)->GetStaticObjectField(jenv, klass, jfid);
1452
1523
  break;
1453
1524
  }
1525
+ pname = (char*)cname;
1454
1526
  if (!isupper(*cname))
1455
1527
  {
1456
- char* p = ALLOCA_N(char, strlen(cname) + 1);
1457
- strcpy(p, cname);
1458
- *p = toupper(*p);
1459
- if (isupper(*p))
1528
+ pname = ALLOCA_N(char, strlen(cname) + 1);
1529
+ strcpy(pname, cname);
1530
+ *pname = toupper(*pname);
1531
+ if (!isupper(*pname)
1532
+ || rb_const_defined(RBASIC(self)->klass, rb_intern(pname)))
1460
1533
  {
1461
- rb_define_const(RBASIC(self)->klass, p, j2r(jenv, jv));
1534
+ pname = NULL;
1462
1535
  }
1463
1536
  }
1464
- else
1537
+ if (pname)
1465
1538
  {
1466
- rb_define_const(RBASIC(self)->klass, cname, j2r(jenv, jv));
1539
+ rb_define_const(RBASIC(self)->klass, pname, j2r(jenv, jv));
1467
1540
  }
1468
-
1469
1541
  rjb_release_string(jenv, nm, cname);
1470
1542
  }
1471
1543
  (*jenv)->DeleteLocalRef(jenv, f);
@@ -1498,7 +1570,6 @@ static void setup_metadata(JNIEnv* jenv, VALUE self, struct jv_data* ptr, VALUE
1498
1570
  setup_fields(jenv, &ptr->idata.fields, flds);
1499
1571
 
1500
1572
  register_class(self, classname);
1501
-
1502
1573
  load_constants(jenv, ptr->idata.obj, self, flds);
1503
1574
  }
1504
1575
 
@@ -2404,13 +2475,11 @@ static VALUE invoke_by_instance(ID rmid, int argc, VALUE* argv,
2404
2475
  if (st_lookup(ptr->fields, rb_intern(fname), (st_data_t*)&pf))
2405
2476
  {
2406
2477
  setter(jenv, pf, ptr, *argv);
2478
+ return ret;
2407
2479
  }
2408
- else
2409
- {
2410
- rb_raise(rb_eRuntimeError, "Fail: unknown field name `%s'", fname);
2411
- }
2480
+ // fall through for the setter alias name
2412
2481
  }
2413
- else if (st_lookup(ptr->methods, rmid, (st_data_t*)&pm))
2482
+ if (st_lookup(ptr->methods, rmid, (st_data_t*)&pm))
2414
2483
  {
2415
2484
  ret = invoke(jenv, pm, ptr, argc, argv, sig);
2416
2485
  }
Binary file
@@ -1,5 +1,5 @@
1
1
  #!/usr/local/env ruby
2
- # $Id: test.rb 11 2007-05-06 10:02:52Z arton $
2
+ # $Id: test.rb 16 2007-06-16 18:00:49Z arton $
3
3
 
4
4
  require 'test/unit'
5
5
  require 'rjb'
@@ -421,5 +421,19 @@ class TestRjb < Test::Unit::TestCase
421
421
  assert(e)
422
422
  end
423
423
  end
424
+
425
+ def test_rubyize
426
+ loader = Rjb::import('java.lang.ClassLoader')
427
+ cls = import('java.lang.Class')
428
+ b = cls.for_name('jp.co.infoseek.hp.arton.rjb.IBase', true, loader.system_class_loader)
429
+ assert(b.interface?)
430
+ stringbuffer = Rjb::import('java.lang.StringBuffer')
431
+ sb = stringbuffer.new('abc')
432
+ assert_equal(1, sb.index_of('bc'))
433
+ sb.set_char_at(1, ?B)
434
+ assert_equal('aBc', sb.to_string)
435
+ sb.length = 2
436
+ assert_equal('aB', sb.to_string)
437
+ end
424
438
  end
425
439
 
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ 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.4
7
- date: 2007-05-06 00:00:00 +09:00
6
+ version: 1.0.6
7
+ date: 2007-06-17 00:00:00 +09:00
8
8
  summary: Ruby Java bridge
9
9
  require_paths:
10
10
  - lib
@@ -42,8 +42,8 @@ files:
42
42
  - data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class
43
43
  - lib/rjb.rb
44
44
  - samples/filechooser.rb
45
- - test/gctest.rb
46
45
  - test/test.rb
46
+ - test/gctest.rb
47
47
  - test/jp/co/infoseek/hp/arton/rjb/ExtBase.class
48
48
  - test/jp/co/infoseek/hp/arton/rjb/Test.class
49
49
  - test/jp/co/infoseek/hp/arton/rjb/IBase.class