rjb 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +16 -0
  3. data/ext/rjb.c +74 -74
  4. data/ext/rjbexception.c +15 -4
  5. data/lib/rjb.rb +20 -1
  6. data/test/test.rb +17 -5
  7. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d1fbaad6b7b8881cdf6ca256139b8447590c578430e1775255fbc457e44f4aa
4
- data.tar.gz: 5a3e4e5142eb5db86af1b9419f72e5128bb19975926a70c94e078e8553d6ccec
3
+ metadata.gz: 8f75da380b876687e4355f11f4637d408ed0aad22b83ed03ff8d766cd96352ba
4
+ data.tar.gz: 30fa4dd4c8e197722cc799a3258a629016067dc16022c4100f934ec7074388b7
5
5
  SHA512:
6
- metadata.gz: b4f7b723db8f2ce2415814e6689d26c4f38b221d75903767a9c0434cb0a1da0ba7c6b53fb58fdf7ba8a8861beea02c7cb80079b787f6702d5f03132b6fc09ea1
7
- data.tar.gz: b1724e95cd003cc140c45f42916340bd90c7ce115933a5e83d1a31d3bf91504e2bea714600f7a430e1939083d8e1dbf29fac273eb26d1c4245ec2407cfb39abb
6
+ metadata.gz: 6637eb828550bf98bc4ed693428d209dc5d24f042e29f8a0f48cde1d32e764c6fb67adb64f1a2e67e5ca5f2e815dfd29bbc9f8bdfe9f18a5ad0e12599c4b0465
7
+ data.tar.gz: 501f7f908fe7e6a3ceb33aa07fa8f4903554ccbbfea22d39ea5e213a85f4e7b7e5fd567ce0b1a43d8afba96aeebd9f718783d21e158d7a4042661f43e5888111
data/ChangeLog CHANGED
@@ -1,3 +1,19 @@
1
+ Wed Jul 17 2019 arton
2
+ * ext/rjb.c
3
+ RJB_VERSION -> 1.6.1
4
+ * lib/rjb.rb
5
+ java_methods and methods return symbol
6
+ implements respond_to? for Java methods
7
+ * ext/rbjexception.c
8
+ delegate to JavaProxy for respond_to? (except for to_str and exception)
9
+ * test/test.rb
10
+ change java_methods test to adjust above change
11
+ add respond_to? test
12
+ Thu Jul 11 2019 arton
13
+ * ext/rjb.c
14
+ RJB_VERSION -> 1.6.0
15
+ * ext/riconv.c
16
+ encode/decode between utf-8 and cesu-8 if char was greater than \uffff
1
17
  Sun Feb 17 2019 lamby / arton
2
18
  * ext/rjb.c
3
19
  RJB_VERSION -> 1.5.9
data/ext/rjb.c CHANGED
@@ -14,7 +14,7 @@
14
14
  *
15
15
  */
16
16
 
17
- #define RJB_VERSION "1.6.0"
17
+ #define RJB_VERSION "1.6.1"
18
18
 
19
19
  #include "ruby.h"
20
20
  #include "extconf.h"
@@ -102,7 +102,7 @@ static VALUE primitive_conversion = Qfalse;
102
102
  /*
103
103
  * Object cache, never destroyed
104
104
  */
105
- /* method */
105
+ /* method */
106
106
  static jmethodID method_getModifiers;
107
107
  static jmethodID method_getName;
108
108
  static jmethodID getParameterTypes;
@@ -229,7 +229,7 @@ static VALUE jstring2val(JNIEnv* jenv, jstring s)
229
229
  const char* p;
230
230
  VALUE v;
231
231
 
232
- if (s == NULL)
232
+ if (s == NULL)
233
233
  {
234
234
  return Qnil;
235
235
  }
@@ -317,7 +317,7 @@ static VALUE jv2rv_r(JNIEnv* jenv, jvalue val)
317
317
  Data_Get_Struct(v, struct jv_data, ptr);
318
318
  v = register_instance(jenv, v, (struct jv_data*)ptr, val.l);
319
319
  (*jenv)->DeleteLocalRef(jenv, klass);
320
- (*jenv)->DeleteLocalRef(jenv, val.l);
320
+ (*jenv)->DeleteLocalRef(jenv, val.l);
321
321
  return v;
322
322
  }
323
323
 
@@ -357,7 +357,7 @@ static VALUE jfloat2rv(JNIEnv* jenv, jvalue val)
357
357
 
358
358
  static VALUE jint2rv(JNIEnv* jenv, jvalue val)
359
359
  {
360
- return INT2NUM(val.i);
360
+ return INT2NUM(val.i);
361
361
  }
362
362
 
363
363
  static VALUE jlong2rv(JNIEnv* jenv, jvalue val)
@@ -393,13 +393,13 @@ static VALUE ja2r(J2R conv, JNIEnv* jenv, jvalue val, int depth)
393
393
  VALUE v;
394
394
  int i;
395
395
  if (!val.l) return Qnil;
396
- if (depth == 1)
396
+ if (depth == 1)
397
397
  {
398
398
  return conv(jenv, val);
399
399
  }
400
400
  len = (*jenv)->GetArrayLength(jenv, val.l);
401
401
  v = rb_ary_new2(len);
402
- for (i = 0; i < len; i++)
402
+ for (i = 0; i < len; i++)
403
403
  {
404
404
  jvalue wrap;
405
405
  wrap.l = (*jenv)->GetObjectArrayElement(jenv, val.l, i);
@@ -454,7 +454,7 @@ static VALUE la2rv(JNIEnv* jenv, void* p)
454
454
  return LL2NUM(*(jlong*)p);
455
455
  #else
456
456
  return LONG2NUM(*(jlong*)p);
457
- #endif
457
+ #endif
458
458
  }
459
459
 
460
460
  static VALUE sa2rv(JNIEnv* jenv, void* p)
@@ -498,7 +498,7 @@ static VALUE jbytearray2rv(JNIEnv* jenv, jvalue val)
498
498
  static VALUE jchararray2rv(JNIEnv* jenv, jvalue val)
499
499
  {
500
500
  jchar* p = (*jenv)->GetCharArrayElements(jenv, val.l, NULL);
501
- return call_conv(jenv, val, sizeof(jchar), p, ca2rv,
501
+ return call_conv(jenv, val, sizeof(jchar), p, ca2rv,
502
502
  offsetof(struct JNINativeInterface_, ReleaseCharArrayElements));
503
503
  }
504
504
  static VALUE jdoublearray2rv(JNIEnv* jenv, jvalue val)
@@ -557,14 +557,14 @@ static VALUE jbooleanarray2rv(JNIEnv* jenv, jvalue val)
557
557
  */
558
558
  static jprimitive_table jpcvt[] = {
559
559
  { "java/lang/Integer", "intValue", "()I", "(I)V", NULL, 0, 0, jint2rv, },
560
- { "java/lang/Long", "longValue", "()J", "(J)V", NULL, 0, 0, jlong2rv, },
560
+ { "java/lang/Long", "longValue", "()J", "(J)V", NULL, 0, 0, jlong2rv, },
561
561
  { "java/lang/Double", "doubleValue", "()D", "(D)V", NULL, 0, 0, jdouble2rv, },
562
562
  { "java/lang/Boolean", "booleanValue", "()Z", "(Z)Ljava/lang/Boolean;",
563
563
  NULL, 0, 0, jboolean2rv, },
564
564
  { "java/lang/Character", "charValue", "()C", NULL, NULL, 0, 0, jchar2rv, },
565
565
  { "java/lang/Short", "intValue", "()I", NULL, NULL, 0, 0, jint2rv, },
566
566
  { "java/lang/Byte", "intValue", "()I", NULL, NULL, 0, 0, jint2rv, },
567
- { "java/lang/Float", "doubleValue", "()D", NULL, NULL, 0, 0, jdouble2rv, },
567
+ { "java/lang/Float", "doubleValue", "()D", NULL, NULL, 0, 0, jdouble2rv, },
568
568
  };
569
569
 
570
570
  /*
@@ -669,7 +669,7 @@ static void rv2jfloat(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int
669
669
  static void rv2jint(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int release)
670
670
  {
671
671
  if (!release)
672
- jv->i = NUM2INT(val);
672
+ jv->i = NUM2INT(val);
673
673
  }
674
674
  static void rv2jlong(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int release)
675
675
  {
@@ -693,7 +693,7 @@ static void rv2jshort(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int
693
693
  if (release) return;
694
694
  if (TYPE(val) == T_FIXNUM)
695
695
  {
696
- int n = FIX2INT(val);
696
+ int n = FIX2INT(val);
697
697
  if (abs(n) < 0x7fff)
698
698
  {
699
699
  jv->s = (short)n;
@@ -814,7 +814,7 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
814
814
  Data_Get_Struct(val, struct rj_bridge, ptr);
815
815
  jv->l = ptr->proxy;
816
816
  }
817
- else if (CLASS_INHERITED(rjbc, rb_obj_class(val)))
817
+ else if (CLASS_INHERITED(rjbc, rb_obj_class(val)))
818
818
  {
819
819
  struct jv_data* ptr;
820
820
  Data_Get_Struct(val, struct jv_data, ptr);
@@ -836,13 +836,13 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
836
836
  case T_ARRAY:
837
837
  jv->l = r2objarray(jenv, val, "Ljava/lang/Object;");
838
838
  break;
839
- #if HAVE_LONG_LONG
839
+ #if HAVE_LONG_LONG
840
840
  case T_BIGNUM:
841
841
  arg.j = rb_big2ll(val);
842
842
  jv->l = (*jenv)->NewObject(jenv, jpcvt[PRM_LONG].klass,
843
843
  jpcvt[PRM_LONG].ctr_id, arg);
844
844
  break;
845
- #endif
845
+ #endif
846
846
  case T_OBJECT:
847
847
  default:
848
848
  #if defined(DEBUG)
@@ -860,7 +860,7 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
860
860
  }
861
861
  else
862
862
  {
863
- switch (TYPE(val))
863
+ switch (TYPE(val))
864
864
  {
865
865
  case T_STRING:
866
866
  case T_FLOAT:
@@ -1287,7 +1287,7 @@ static J2R get_j2r(JNIEnv* jenv, jobject cls, char* psig, char* pdepth, char* pp
1287
1287
  const char* cname;
1288
1288
  const char* jname = NULL;
1289
1289
  jstring nm = (*jenv)->CallObjectMethod(jenv, cls, rjb_class_getName);
1290
- rjb_check_exception(jenv, 0);
1290
+ rjb_check_exception(jenv, 0);
1291
1291
  cname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
1292
1292
 
1293
1293
  if (*cname == '[')
@@ -1391,7 +1391,7 @@ static void setup_methodbase(JNIEnv* jenv, struct cls_constructor* pm,
1391
1391
  static void register_methodinfo(struct cls_method* newpm, st_table* tbl)
1392
1392
  {
1393
1393
  struct cls_method* pm;
1394
-
1394
+
1395
1395
  if (st_lookup(tbl, newpm->name, (st_data_t*)&pm))
1396
1396
  {
1397
1397
  newpm->next = pm->next;
@@ -1434,7 +1434,7 @@ static int make_alias(const char* jname, char* rname)
1434
1434
  static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static_method)
1435
1435
  {
1436
1436
  struct cls_method* result;
1437
- struct cls_method* pm;
1437
+ struct cls_method* pm;
1438
1438
  const char* jname;
1439
1439
  int alias;
1440
1440
  jstring nm;
@@ -1450,12 +1450,12 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
1450
1450
  rjb_check_exception(jenv, 0);
1451
1451
  setup_methodbase(jenv, &result->basic, parama, param_count);
1452
1452
  nm = (*jenv)->CallObjectMethod(jenv, m, method_getName);
1453
- rjb_check_exception(jenv, 0);
1453
+ rjb_check_exception(jenv, 0);
1454
1454
  jname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
1455
1455
  rname = ALLOCA_N(char, strlen(jname) * 2 + 8);
1456
1456
  alias = make_alias(jname, rname);
1457
1457
  result->name = rb_intern(jname);
1458
- rjb_release_string(jenv, nm, jname);
1458
+ rjb_release_string(jenv, nm, jname);
1459
1459
  result->basic.id = (*jenv)->FromReflectedMethod(jenv, m);
1460
1460
  rjb_check_exception(jenv, 0);
1461
1461
  cls = (*jenv)->CallObjectMethod(jenv, m, getReturnType);
@@ -1470,7 +1470,7 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
1470
1470
  && (*rname == 'g' || *rname == 's') && *(rname + 1) == 'e' && *(rname + 2) == 't')
1471
1471
  {
1472
1472
  pm = clone_methodinfo(result);
1473
- if (*rname == 's')
1473
+ if (*rname == 's')
1474
1474
  {
1475
1475
  if (result->basic.arg_count == 1)
1476
1476
  {
@@ -1515,7 +1515,7 @@ static void create_fieldinfo(JNIEnv* jenv, st_table* tbl, jobject f, int readonl
1515
1515
  result = ALLOC(struct cls_field);
1516
1516
  memset(result, 0, sizeof(struct cls_field));
1517
1517
  nm = (*jenv)->CallObjectMethod(jenv, f, field_getName);
1518
- rjb_check_exception(jenv, 0);
1518
+ rjb_check_exception(jenv, 0);
1519
1519
  jname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
1520
1520
  result->name = rb_intern(jname);
1521
1521
  rjb_release_string(jenv, nm, jname);
@@ -1537,7 +1537,7 @@ static void create_fieldinfo(JNIEnv* jenv, st_table* tbl, jobject f, int readonl
1537
1537
  static void setup_constructors(JNIEnv* jenv, struct cls_constructor*** pptr, jobjectArray methods)
1538
1538
  {
1539
1539
  int i;
1540
- struct cls_constructor* pc;
1540
+ struct cls_constructor* pc;
1541
1541
  jsize mcount = (*jenv)->GetArrayLength(jenv, methods);
1542
1542
  struct cls_constructor** tbl = ALLOC_N(struct cls_constructor*, mcount + 1);
1543
1543
  *pptr = tbl;
@@ -1557,21 +1557,21 @@ static void setup_constructors(JNIEnv* jenv, struct cls_constructor*** pptr, job
1557
1557
  pc->id = (*jenv)->FromReflectedMethod(jenv, c);
1558
1558
  (*jenv)->DeleteLocalRef(jenv, c);
1559
1559
  }
1560
- tbl[mcount] = NULL;
1560
+ tbl[mcount] = NULL;
1561
1561
  }
1562
-
1562
+
1563
1563
  static void setup_methods(JNIEnv* jenv, st_table** tbl, st_table** static_tbl,
1564
1564
  jobjectArray methods)
1565
1565
  {
1566
1566
  int i;
1567
- jint modifier;
1567
+ jint modifier;
1568
1568
  jsize mcount = (*jenv)->GetArrayLength(jenv, methods);
1569
1569
  *tbl = st_init_numtable_with_size(mcount);
1570
1570
  *static_tbl = st_init_numtable();
1571
1571
  for (i = 0; i < mcount; i++)
1572
1572
  {
1573
1573
  jobject m = (*jenv)->GetObjectArrayElement(jenv, methods, i);
1574
- rjb_check_exception(jenv, 0);
1574
+ rjb_check_exception(jenv, 0);
1575
1575
  modifier = (*jenv)->CallIntMethod(jenv, m, method_getModifiers);
1576
1576
  if (!(modifier & ACC_STATIC))
1577
1577
  {
@@ -1588,13 +1588,13 @@ static void setup_methods(JNIEnv* jenv, st_table** tbl, st_table** static_tbl,
1588
1588
  static void setup_fields(JNIEnv* jenv, st_table** tbl, jobjectArray flds)
1589
1589
  {
1590
1590
  int i;
1591
- jint modifier;
1591
+ jint modifier;
1592
1592
  jsize fcount = (*jenv)->GetArrayLength(jenv, flds);
1593
1593
  *tbl = st_init_numtable_with_size(fcount);
1594
1594
  for (i = 0; i < fcount; i++)
1595
1595
  {
1596
1596
  jobject f = (*jenv)->GetObjectArrayElement(jenv, flds, i);
1597
- rjb_check_exception(jenv, 0);
1597
+ rjb_check_exception(jenv, 0);
1598
1598
  modifier = (*jenv)->CallIntMethod(jenv, f, field_getModifiers);
1599
1599
  create_fieldinfo(jenv, *tbl, f, modifier & ACC_FINAL, modifier & ACC_STATIC);
1600
1600
  (*jenv)->DeleteLocalRef(jenv, f);
@@ -1640,7 +1640,7 @@ static void load_constants(JNIEnv* jenv, jclass klass, VALUE self, jobjectArray
1640
1640
  rjb_check_exception(jenv, 0);
1641
1641
  jfid = (*jenv)->GetStaticFieldID(jenv, klass, cname, sigs);
1642
1642
  rjb_check_exception(jenv, 0);
1643
- switch (sig)
1643
+ switch (sig)
1644
1644
  {
1645
1645
  case 'D':
1646
1646
  jv.d = (*jenv)->GetStaticDoubleField(jenv, klass, jfid);
@@ -1670,14 +1670,14 @@ static void load_constants(JNIEnv* jenv, jclass klass, VALUE self, jobjectArray
1670
1670
  jv.l = (*jenv)->GetStaticObjectField(jenv, klass, jfid);
1671
1671
  break;
1672
1672
  }
1673
- pname = (char*)cname;
1673
+ pname = (char*)cname;
1674
1674
  if (!isupper(*cname))
1675
1675
  {
1676
1676
  pname = ALLOCA_N(char, strlen(cname) + 1);
1677
1677
  strcpy(pname, cname);
1678
1678
  *pname = toupper(*pname);
1679
- if (!isupper(*pname)
1680
- || rb_const_defined(rb_obj_class(self), rb_intern(pname)))
1679
+ if (!isupper(*pname)
1680
+ || rb_const_defined(rb_obj_class(self), rb_intern(pname)))
1681
1681
  {
1682
1682
  pname = NULL;
1683
1683
  }
@@ -1697,7 +1697,7 @@ static void setup_metadata(JNIEnv* jenv, VALUE self, struct jv_data* ptr, VALUE
1697
1697
  jmethodID mid;
1698
1698
  jobjectArray methods;
1699
1699
  jobjectArray flds;
1700
-
1700
+
1701
1701
  jclass klass = (*jenv)->GetObjectClass(jenv, ptr->idata.obj);
1702
1702
  ptr->idata.klass = (*jenv)->NewGlobalRef(jenv, klass);
1703
1703
  rjb_check_exception(jenv, 0);
@@ -1726,7 +1726,7 @@ static void setup_metadata(JNIEnv* jenv, VALUE self, struct jv_data* ptr, VALUE
1726
1726
  * def load(class_path = '', vmargs = [])
1727
1727
  * class_path: passes for the class dir and jar name
1728
1728
  * vmargs: strng array of vmarg (such as -Xrs)
1729
- *
1729
+ *
1730
1730
  * change in rjb 0.1.7, omit first argument for JNI version.
1731
1731
  * because I misunderstood the number means (JVM but JNI).
1732
1732
  */
@@ -1769,7 +1769,7 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
1769
1769
  rb_funcall(user_path, stradd, 1, rb_ary_entry(classpath, 0));
1770
1770
  }
1771
1771
  userpath = StringValueCStr(user_path);
1772
-
1772
+
1773
1773
  if (!NIL_P(vm_argv))
1774
1774
  {
1775
1775
  Check_Type(vm_argv, T_ARRAY);
@@ -1792,31 +1792,31 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
1792
1792
  RJB_LOAD_METHOD(getParameterTypes, jmethod, "getParameterTypes", "()[Ljava/lang/Class;");
1793
1793
  RJB_LOAD_METHOD(getReturnType, jmethod, "getReturnType", "()Ljava/lang/Class;");
1794
1794
  rjb_check_exception(jenv, 1);
1795
-
1795
+
1796
1796
  RJB_FIND_CLASS(jfield, "java/lang/reflect/Field");
1797
1797
  RJB_LOAD_METHOD(field_getModifiers, jfield, "getModifiers", "()I");
1798
1798
  RJB_LOAD_METHOD(field_getName, jfield, "getName", "()Ljava/lang/String;");
1799
1799
  RJB_LOAD_METHOD(field_getType, jfield, "getType", "()Ljava/lang/Class;");
1800
1800
  rjb_check_exception(jenv, 1);
1801
-
1801
+
1802
1802
  RJB_HOLD_CLASS(j_class, "java/lang/Class");
1803
1803
  RJB_LOAD_METHOD(rjb_class_getName, j_class, "getName", "()Ljava/lang/String;");
1804
1804
  rjb_check_exception(jenv, 1);
1805
-
1805
+
1806
1806
  RJB_HOLD_CLASS(rjb_j_throwable, "java/lang/Throwable");
1807
1807
  RJB_LOAD_METHOD(rjb_throwable_getMessage, rjb_j_throwable, "getMessage", "()Ljava/lang/String;");
1808
- rjb_check_exception(jenv, 1);
1808
+ rjb_check_exception(jenv, 1);
1809
1809
 
1810
1810
  RJB_HOLD_CLASS(j_string, "java/lang/String");
1811
1811
  RJB_LOAD_METHOD(str_tostring, j_string, "toString", "()Ljava/lang/String;");
1812
- rjb_check_exception(jenv, 1);
1812
+ rjb_check_exception(jenv, 1);
1813
1813
 
1814
1814
  RJB_HOLD_CLASS(j_object, "java/lang/Object");
1815
- rjb_check_exception(jenv, 1);
1815
+ rjb_check_exception(jenv, 1);
1816
1816
 
1817
1817
  RJB_HOLD_CLASS(j_url, "java/net/URL");
1818
1818
  RJB_LOAD_METHOD(url_new, j_url, "<init>", "(Ljava/lang/String;)V");
1819
- rjb_check_exception(jenv, 1);
1819
+ rjb_check_exception(jenv, 1);
1820
1820
 
1821
1821
  for (i = PRM_INT; i < PRM_LAST; i++)
1822
1822
  {
@@ -1840,7 +1840,7 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
1840
1840
  rb_define_method(rb_singleton_class(jklass), "forName", rjb_class_forname, -1);
1841
1841
  rb_define_alias(rb_singleton_class(jklass), "for_name", "forName");
1842
1842
  rb_gc_register_address(&jklass);
1843
-
1843
+
1844
1844
  return Qnil;
1845
1845
  }
1846
1846
 
@@ -1874,7 +1874,7 @@ jobject get_systemloader(JNIEnv* jenv)
1874
1874
  RJB_HOLD_CLASS(j_classloader, "java/lang/ClassLoader");
1875
1875
  RJB_LOAD_STATIC_METHOD(get_system_classloader, j_classloader,
1876
1876
  "getSystemClassLoader", "()Ljava/lang/ClassLoader;");
1877
- rjb_check_exception(jenv, 1);
1877
+ rjb_check_exception(jenv, 1);
1878
1878
  }
1879
1879
  return (*jenv)->CallStaticObjectMethod(jenv, j_classloader, get_system_classloader);
1880
1880
  }
@@ -1908,7 +1908,7 @@ static VALUE rjb_s_unload(int argc, VALUE* argv, VALUE self)
1908
1908
  st_foreach(RHASH(rjb_loaded_classes)->tbl, clear_classes, 0);
1909
1909
  #endif
1910
1910
  #endif
1911
-
1911
+
1912
1912
  if (rjb_jvm)
1913
1913
  {
1914
1914
  JNIEnv* jenv = rjb_attach_current_thread();
@@ -1990,10 +1990,10 @@ static VALUE rjb_delete_ref(struct jvi_data* ptr)
1990
1990
  */
1991
1991
  static VALUE rj_bridge_free(struct rj_bridge* ptr)
1992
1992
  {
1993
- JNIEnv* jenv = rjb_attach_current_thread();
1993
+ JNIEnv* jenv = rjb_attach_current_thread();
1994
1994
  if (jenv)
1995
1995
  {
1996
- (*jenv)->DeleteLocalRef(jenv, ptr->proxy);
1996
+ (*jenv)->DeleteLocalRef(jenv, ptr->proxy);
1997
1997
  (*jenv)->DeleteLocalRef(jenv, ptr->bridge);
1998
1998
  }
1999
1999
  return Qnil;
@@ -2015,7 +2015,7 @@ static VALUE rjb_s_free(struct jv_data* ptr)
2015
2015
  /* class never delete
2016
2016
  JNIEnv* jenv = rjb_attach_current_thread();
2017
2017
  struct cls_constructor** c;
2018
-
2018
+
2019
2019
  rjb_delete_ref(&ptr->idata);
2020
2020
  if (ptr->constructors)
2021
2021
  {
@@ -2030,7 +2030,7 @@ static VALUE rjb_s_free(struct jv_data* ptr)
2030
2030
  st_foreach(ptr->idata.methods, (int(*)())free_method_item, 0);
2031
2031
  st_free_table(ptr->idata.methods);
2032
2032
  }
2033
- (*jenv)->DeleteGlobalRef(jenv, ptr->idata.klass);
2033
+ (*jenv)->DeleteGlobalRef(jenv, ptr->idata.klass);
2034
2034
  st_delete(RHASH(rjb_loaded_classes)->tbl, clsname, NULL);
2035
2035
  */
2036
2036
  return Qnil;
@@ -2049,7 +2049,7 @@ static VALUE createinstance(JNIEnv* jenv, int argc, VALUE* argv,
2049
2049
  struct jv_data* jklass;
2050
2050
  struct jvi_data* org;
2051
2051
  jvalue* args = (argc) ? ALLOCA_N(jvalue, argc) : NULL;
2052
-
2052
+
2053
2053
  Data_Get_Struct(self, struct jv_data, jklass);
2054
2054
  org = &jklass->idata;
2055
2055
 
@@ -2087,7 +2087,7 @@ static VALUE import_class(JNIEnv* jenv, jclass jcls, VALUE clsname)
2087
2087
  char* nm = ALLOCA_N(char, strlen(pclsname) + 1);
2088
2088
  strcpy(nm, pclsname);
2089
2089
  *nm = toupper(*nm);
2090
- for (pclsname = nm; *pclsname; pclsname++)
2090
+ for (pclsname = nm; *pclsname; pclsname++)
2091
2091
  {
2092
2092
  if (*pclsname == '.')
2093
2093
  {
@@ -2116,7 +2116,7 @@ static VALUE rjb_a_missing(int argc, VALUE* argv, VALUE self)
2116
2116
 
2117
2117
  static VALUE rjb_i_prepare_proxy(VALUE self)
2118
2118
  {
2119
- return rb_funcall(self, rb_intern("instance_eval"), 1,
2119
+ return rb_funcall(self, rb_intern("instance_eval"), 1,
2120
2120
  rb_str_new2("instance_eval(&" USER_INITIALIZE ")"));
2121
2121
  }
2122
2122
 
@@ -2175,7 +2175,7 @@ static int check_rtype(JNIEnv* jenv, VALUE* pv, char* p)
2175
2175
  if (strchr("IJ", *p)) return SOSO;
2176
2176
  return strchr("BCDFS", *p) != NULL;
2177
2177
  case T_BIGNUM:
2178
- return strchr("BCDFIJS", *p) != NULL;
2178
+ return strchr("BCDFIJS", *p) != NULL;
2179
2179
  case T_FLOAT:
2180
2180
  if (*p == 'D') return SOSO;
2181
2181
  if (*p == 'F') return SATISFIED;
@@ -2298,7 +2298,7 @@ static VALUE rjb_newinstance(int argc, VALUE* argv, VALUE self)
2298
2298
  int weight = 0;
2299
2299
  int cweight;
2300
2300
  JNIEnv* jenv = rjb_prelude();
2301
-
2301
+
2302
2302
  Data_Get_Struct(self, struct jv_data, ptr);
2303
2303
 
2304
2304
  if (ptr->constructors)
@@ -2378,7 +2378,7 @@ jclass rjb_find_class(JNIEnv* jenv, VALUE name)
2378
2378
  {
2379
2379
  char* cname;
2380
2380
  char* jnicls;
2381
-
2381
+
2382
2382
  Check_Type(name, T_STRING);
2383
2383
  cname = StringValueCStr(name);
2384
2384
  jnicls = ALLOCA_N(char, strlen(cname) + 1);
@@ -2455,8 +2455,8 @@ static VALUE rjb_s_bind(VALUE self, VALUE rbobj, VALUE itfname)
2455
2455
  VALUE result = Qnil;
2456
2456
  jclass itf;
2457
2457
  JNIEnv* jenv = rjb_prelude();
2458
-
2459
- itf = rjb_find_class(jenv, itfname);
2458
+
2459
+ itf = rjb_find_class(jenv, itfname);
2460
2460
  rjb_check_exception(jenv, 1);
2461
2461
  if (itf)
2462
2462
  {
@@ -2582,7 +2582,7 @@ static jobject conv_jarname_to_url(JNIEnv* jenv, VALUE jarname)
2582
2582
  #if defined(DOSISH)
2583
2583
  if (strlen(jarp) > 1 && jarp[1] == ':')
2584
2584
  {
2585
- sprintf(urlp, "file:///%s", jarp);
2585
+ sprintf(urlp, "file:///%s", jarp);
2586
2586
  }
2587
2587
  else
2588
2588
  #endif
@@ -2604,7 +2604,7 @@ static jobject conv_jarname_to_url(JNIEnv* jenv, VALUE jarname)
2604
2604
  }
2605
2605
  #endif
2606
2606
  arg.l = (*jenv)->NewStringUTF(jenv, urlp);
2607
- rjb_check_exception(jenv, 0);
2607
+ rjb_check_exception(jenv, 0);
2608
2608
  url = (*jenv)->NewObject(jenv, j_url, url_new, arg);
2609
2609
  rjb_check_exception(jenv, 0);
2610
2610
  return url;
@@ -2657,7 +2657,7 @@ static VALUE rjb_s_add_jar(VALUE self, VALUE jarname)
2657
2657
  if (!url_loader)
2658
2658
  {
2659
2659
  args[0].l = (*jenv)->NewObjectArray(jenv, (jsize)((count == 0) ? 1 : count), j_url, NULL);
2660
- rjb_check_exception(jenv, 0);
2660
+ rjb_check_exception(jenv, 0);
2661
2661
  if (!count)
2662
2662
  {
2663
2663
  (*jenv)->SetObjectArrayElement(jenv, args[0].l, 0,
@@ -2732,7 +2732,7 @@ static VALUE rjb_i_class(VALUE self)
2732
2732
  static VALUE getter(JNIEnv* jenv, struct cls_field* pf, struct jvi_data* ptr)
2733
2733
  {
2734
2734
  jvalue jv;
2735
- switch (pf->result_signature)
2735
+ switch (pf->result_signature)
2736
2736
  {
2737
2737
  case 'D':
2738
2738
  if (pf->static_field)
@@ -2839,7 +2839,7 @@ static void setter(JNIEnv* jenv, struct cls_field* pf, struct jvi_data* ptr, VA
2839
2839
  {
2840
2840
  jvalue jv;
2841
2841
  pf->arg_convert(jenv, val, &jv, pf->field_signature, 0);
2842
- switch (*pf->field_signature)
2842
+ switch (*pf->field_signature)
2843
2843
  {
2844
2844
  case 'D':
2845
2845
  if (pf->static_field)
@@ -2960,7 +2960,7 @@ static VALUE invoke(JNIEnv* jenv, struct cls_method* pm, struct jvi_data* ptr,
2960
2960
  found = 0;
2961
2961
  if (argc == pm->basic.arg_count)
2962
2962
  {
2963
- if (sig && pm->basic.method_signature)
2963
+ if (sig && pm->basic.method_signature)
2964
2964
  {
2965
2965
  if (!strcmp(sig, pm->basic.method_signature))
2966
2966
  {
@@ -2999,7 +2999,7 @@ static VALUE invoke(JNIEnv* jenv, struct cls_method* pm, struct jvi_data* ptr,
2999
2999
  if (!prefer_pm)
3000
3000
  {
3001
3001
  const char* tname = rb_id2name(orgpm->name);
3002
- if (sig)
3002
+ if (sig)
3003
3003
  {
3004
3004
  rb_raise(rb_eRuntimeError, "Fail: unknown method name `%s(\'%s\')'", tname, sig);
3005
3005
  }
@@ -3092,7 +3092,7 @@ static VALUE invoke_by_instance(ID rmid, int argc, VALUE* argv,
3092
3092
  {
3093
3093
  ret = getter(jenv, pf, ptr);
3094
3094
  }
3095
- else
3095
+ else
3096
3096
  {
3097
3097
  if (argc == 1 && *(tname + strlen(tname) - 1) == '=')
3098
3098
  {
@@ -3154,7 +3154,7 @@ static VALUE rjb_i_missing(int argc, VALUE* argv, VALUE self)
3154
3154
  ID rmid = rb_to_id(argv[0]);
3155
3155
 
3156
3156
  Data_Get_Struct(self, struct jvi_data, ptr);
3157
-
3157
+
3158
3158
  return invoke_by_instance(rmid, argc -1, argv + 1, ptr, NULL);
3159
3159
  }
3160
3160
 
@@ -3217,7 +3217,7 @@ static VALUE invoke_by_class(ID rmid, int argc, VALUE* argv,
3217
3217
  rb_raise(rb_eRuntimeError, "Fail: unknown method name `%s'", tname);
3218
3218
  }
3219
3219
  }
3220
-
3220
+
3221
3221
  return ret;
3222
3222
  }
3223
3223
 
@@ -3259,7 +3259,7 @@ static VALUE rjb_missing(int argc, VALUE* argv, VALUE self)
3259
3259
  return r;
3260
3260
  }
3261
3261
  }
3262
-
3262
+
3263
3263
  Data_Get_Struct(self, struct jv_data, ptr);
3264
3264
  return invoke_by_class(rmid, argc - 1, argv + 1, ptr, NULL);
3265
3265
  }
@@ -3293,7 +3293,7 @@ void Init_rjbcore()
3293
3293
  #else
3294
3294
  rb_protect((VALUE(*)(VALUE))rb_require, (VALUE)"iconv", NULL);
3295
3295
  #endif
3296
- #endif
3296
+ #endif
3297
3297
  rjb_loaded_classes = rb_hash_new();
3298
3298
  #ifndef RUBINIUS
3299
3299
  OBJ_FREEZE(rjb_loaded_classes);
@@ -3323,7 +3323,7 @@ void Init_rjbcore()
3323
3323
  rb_define_class_variable(rjb, "@@classpath", rb_ary_new());
3324
3324
  cvar_classpath = rb_intern("@@classpath");
3325
3325
 
3326
- /* Java class object */
3326
+ /* Java class object */
3327
3327
  rjbc = CLASS_NEW(rb_cObject, "Rjb_JavaClass");
3328
3328
  rb_gc_register_address(&rjbc);
3329
3329
  rb_define_method(rjbc, "method_missing", rjb_missing, -1);
@@ -3334,7 +3334,7 @@ void Init_rjbcore()
3334
3334
  /* Java instance object */
3335
3335
  rjbi = CLASS_NEW(rb_cObject, "Rjb_JavaProxy");
3336
3336
  rb_gc_register_address(&rjbi);
3337
- rb_define_method(rjbi, "method_missing", rjb_i_missing, -1);
3337
+ rb_define_method(rjbi, "method_missing", rjb_i_missing, -1);
3338
3338
  rb_define_method(rjbi, "_invoke", rjb_i_invoke, -1);
3339
3339
  rb_define_method(rjbi, "_classname", rjb_i_class, 0);
3340
3340
  rb_define_method(rjbi, "_prepare_proxy", rjb_i_prepare_proxy, 0);
@@ -29,7 +29,7 @@
29
29
  static VALUE missing_delegate(int argc, VALUE* argv, VALUE self)
30
30
  {
31
31
  ID rmid = rb_to_id(argv[0]);
32
- return rb_funcall(rb_ivar_get(self, rb_intern("@cause")), rmid, argc - 1, argv + 1);
32
+ return rb_funcallv(rb_ivar_get(self, rb_intern("@cause")), rmid, argc - 1, argv + 1);
33
33
  }
34
34
 
35
35
  static VALUE get_cause(VALUE self)
@@ -43,7 +43,18 @@ static VALUE ex_respond_to(int argc, VALUE* argv, VALUE self)
43
43
  {
44
44
  rb_raise(rb_eArgError, "respond_to? require 1 or 2 arguments");
45
45
  }
46
- return rb_to_id(argv[0]) == rb_intern("to_str") ? Qfalse : Qtrue;
46
+ if (rb_to_id(argv[0]) == rb_intern("to_str"))
47
+ {
48
+ return Qfalse;
49
+ }
50
+ else if (rb_to_id(argv[0]) == rb_intern("exception"))
51
+ {
52
+ return Qtrue;
53
+ }
54
+ else
55
+ {
56
+ return rb_funcallv(rb_ivar_get(self, rb_intern("@cause")), rb_intern("respond_to?"), argc, argv);
57
+ }
47
58
  }
48
59
 
49
60
  /*
@@ -86,7 +97,7 @@ VALUE rjb_get_exception_class(JNIEnv* jenv, jstring str)
86
97
  st_insert(RHASH(rjb_loaded_classes)->tbl, cname, rexp);
87
98
  #endif
88
99
  #endif
89
-
100
+
90
101
  }
91
102
  return rexp;
92
103
  }
@@ -98,7 +109,7 @@ VALUE rjb_s_throw(int argc, VALUE* argv, VALUE self)
98
109
  {
99
110
  VALUE klass;
100
111
  VALUE message;
101
- JNIEnv* jenv = NULL;
112
+ JNIEnv* jenv = NULL;
102
113
 
103
114
  rjb_load_vm_default();
104
115
 
data/lib/rjb.rb CHANGED
@@ -86,7 +86,7 @@ module Rjb
86
86
  (org + klass.getMethods.select do |m|
87
87
  blk.call(m)
88
88
  end.map do |m|
89
- m.name
89
+ m.name.to_sym
90
90
  end).uniq
91
91
  end
92
92
  def format_sigs(s)
@@ -98,6 +98,19 @@ module Rjb
98
98
  "[#{s.map{|m|m.nil? ? 'void' : m}.join(', ')}]"
99
99
  end
100
100
  end
101
+ def make_snake(nm)
102
+ nm.gsub(/(.)([A-Z])/) { "#{$1}_#{$2.downcase}" }
103
+ end
104
+ alias :rjb_org_respond_to? :respond_to?
105
+ def rjb_respond_to?(sym, klass, priv)
106
+ return true if (klass ? self : getClass).getMethods.select do |m|
107
+ (klass && !instance_method?(m) && (priv || public_method?(m))) ||
108
+ (!klass && instance_method?(m) && (priv || public_method?(m)))
109
+ end.map do |m|
110
+ [m.name.to_sym, make_snake(m.name).to_sym]
111
+ end.flatten.include?(sym.to_sym)
112
+ rjb_org_respond_to?(sym, priv)
113
+ end
101
114
  end
102
115
 
103
116
  class Rjb_JavaClass
@@ -119,6 +132,9 @@ module Rjb
119
132
  "#{m}(#{format_sigs(self.static_sigs(m))})"
120
133
  end
121
134
  end
135
+ def respond_to?(sym, priv = false)
136
+ rjb_respond_to?(sym, true, priv)
137
+ end
122
138
  end
123
139
  class Rjb_JavaProxy
124
140
  include JMethod
@@ -141,6 +157,9 @@ module Rjb
141
157
  "#{m}(#{format_sigs(getClass.sigs(m))})"
142
158
  end
143
159
  end
160
+ def respond_to?(sym, priv = false)
161
+ rjb_respond_to?(sym, false, priv)
162
+ end
144
163
  end
145
164
  class Rjb_JavaBridge
146
165
  def method_missing(name, *args)
@@ -726,19 +726,19 @@ class TestRjb < Test::Unit::TestCase
726
726
  end
727
727
  def test_methods_extension
728
728
  m = @jString.new('').methods
729
- assert m.include?('indexOf')
729
+ assert m.include?(:indexOf)
730
730
  end
731
731
  def test_class_methods_extension
732
732
  m = @jString.methods
733
- assert m.include?('format')
733
+ assert m.include?(:format)
734
734
  end
735
735
  def test_pmethods_extension
736
736
  m = @jString.new('').public_methods
737
- assert m.include?('indexOf')
737
+ assert m.include?(:indexOf)
738
738
  end
739
739
  def test_class_pmethods_extension
740
740
  m = @jString.public_methods
741
- assert m.include?('format')
741
+ assert m.include?(:format)
742
742
  end
743
743
  def test_java_methods
744
744
  indexof = @jString.new('').java_methods.find do |m|
@@ -963,5 +963,17 @@ class TestRjb < Test::Unit::TestCase
963
963
  y = @jString.new('𠮷野家')
964
964
  assert_equal '𠮷野家', y.toString
965
965
  end
966
- end
967
966
 
967
+ def test_respond_to
968
+ str = @jString.new('blabla')
969
+ assert str.respond_to? :substring
970
+ assert_false str.respond_to? :unknown_method
971
+ begin
972
+ @jInteger.parseInt('blabla')
973
+ rescue => e
974
+ assert e.respond_to? :print_stack_trace
975
+ assert e.respond_to? :printStackTrace
976
+ # assert_false e.respond_to? :unknown_method
977
+ end
978
+ end
979
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - arton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-10 00:00:00.000000000 Z
11
+ date: 2019-07-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'RJB is a bridge program that connect between Ruby and Java with Java
14
14
  Native Interface.