rjb 1.1.2-x86-mswin32-60 → 1.1.4-x86-mswin32-60

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,52 @@
1
+ Thu Aug 14 arton
2
+ *ext/rjb.c, load.c, etc
3
+ change comment line // -> /* */ because AIX's compiler
4
+ add _AIX for load.c (this patch from Ittay Dror, thanks)
5
+ *ext/load.c
6
+ add ALT_JVM_TYPE for alternative jvm directory (by Kumar)
7
+ Sun Jul 13 arton
8
+ *ext/rjb.c
9
+ display warning when Rjb load jvm implicitly if $DEBUG or $VERBOSE.
10
+ Mon May 26 arton
11
+ *ext/rjb.c
12
+ correct char primitive conversion for Bigendian machine.
13
+ use macroes for loading classes
14
+ *ext/load.c
15
+ adjust OS X's directory
16
+ *ext/extconf.rb
17
+ adjust OS X's directory if Home exists
18
+ Thu Mar 27 arton
19
+ *ext/rjb.c
20
+ mark version 1.1.4 for the next release.
21
+ *test/test.rb
22
+ remove unload, because it fails.
23
+ It's more important to assert each functions.
24
+ Thu Mar 27 arton
25
+ *ext/riconv.c
26
+ activate conv tables for getenv configuration.
27
+ Tue Mar 5 Kuwashima
28
+ *ext/rjb.c
29
+ *ext/rjb.h
30
+ *ext/rjbexception.c
31
+ add auto load method.
32
+ Tue Mar 4 Kuwashima
33
+ *ext/rjbexception.c
34
+ *ext/rjb.c
35
+ *test/test.rb
36
+ clear(ignore) exception in current java thread, before some operation.
37
+ *ext/rjbexception.c
38
+ *ext/rjb.c
39
+ add auto load for Rjb::bind, Rjb::throw
40
+ *ext/rjb.c
41
+ *test/test.rb
42
+ add Rjb::unbind
43
+ *test/test.rb
44
+ add loading rubygems
45
+ Sat Feb 23 arton
46
+ *test/test.rb
47
+ let test_field metod use Test.class instead of Point.class
48
+ *test/Test.java
49
+ add a public field for testing
1
50
  Fri Feb 22 arton
2
51
  *ext/rjb.c
3
52
  mark version 1.1.3 for the next release.
data/ext/extconf.h CHANGED
@@ -4,5 +4,5 @@
4
4
  #define HAVE_DL_H 1
5
5
  #define HAVE_SETLOCALE 1
6
6
  #define HAVE_GETENV 1
7
- #define RJB_RUBY_VERSION_CODE 186
7
+ #define RJB_RUBY_VERSION_CODE 187
8
8
  #endif
data/ext/jniwrap.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: jniwrap.h 60 2008-02-21 20:11:37Z arton $
15
+ * $Id: jniwrap.h 78 2008-08-14 10:47:31Z arton $
16
16
  */
17
17
  #ifndef _Included_jniwrap
18
18
  #define _Included_jniwrap
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 77 2008-08-14 10:22:35Z arton $
16
16
  */
17
17
 
18
18
  #include <stdlib.h>
@@ -33,6 +33,7 @@
33
33
  #include "rjb.h"
34
34
 
35
35
  #define JVM_TYPE "client"
36
+ #define ALT_JVM_TYPE "classic"
36
37
 
37
38
  #if defined(_WIN32) || defined(__CYGWIN__)
38
39
  #if defined(__CYGWIN__)
@@ -47,6 +48,12 @@
47
48
  #define JVMDLL "%s/Libraries/libjvm_compat.dylib"
48
49
  #define DIRSEPARATOR '/'
49
50
  #define CLASSPATH_SEP ':'
51
+ #define HOME_NAME "/Home"
52
+ #define HOME_NAME_LEN strlen(HOME_NAME)
53
+ #define DEFAULT_HOME "/System/Library/Frameworks/JavaVM.framework"
54
+ #elif defined(_AIX)
55
+ #define ARCH "ppc"
56
+ #define JVM_TYPE "j9vm"
50
57
  #else /* defined(_WIN32) || defined(__CYGWIN__) */
51
58
  #if defined(__sparc_v9__)
52
59
  #define ARCH "sparcv9"
@@ -83,16 +90,30 @@ static int load_jvm(char* jvmtype)
83
90
  char* libpath;
84
91
  char* java_home;
85
92
  char* jh;
86
- VALUE dl;
87
- VALUE importer;
88
93
 
89
- #if defined(__APPLE__) && defined(__MACH__)
90
- jh = "/System/Library/Frameworks/JavaVM.framework";
91
- #else
92
94
  jh = getenv("JAVA_HOME");
95
+ #if defined(__APPLE__) && defined(__MACH__)
96
+ if (!jh)
97
+ {
98
+ jh = DEFAULT_HOME;
99
+ }
100
+ else
101
+ {
102
+ if (strlen(jh) > HOME_NAME_LEN
103
+ && strcasecmp(jh + strlen(jh) - HOME_NAME_LEN, HOME_NAME) == 0)
104
+ {
105
+ char* p = ALLOCA_N(char, strlen(jh) + 8);
106
+ sprintf(p, "%s/..", jh);
107
+ jh = p;
108
+ }
109
+ }
93
110
  #endif
94
111
  if (!jh)
95
112
  {
113
+ if (RTEST(ruby_verbose))
114
+ {
115
+ fprintf(stderr, "no JAVA_HOME environment\n");
116
+ }
96
117
  return 0;
97
118
  }
98
119
  #if defined(_WIN32)
@@ -132,6 +153,7 @@ static int load_jvm(char* jvmtype)
132
153
 
133
154
  jvmdll = rb_funcall(rb_const_get(rb_cObject, rb_intern("DL")), rb_intern("dlopen"), 1, rb_str_new2(libpath));
134
155
 
156
+ /* get function pointers of JNI */
135
157
  #if RJB_RUBY_VERSION_CODE < 190
136
158
  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
159
  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);
@@ -206,7 +228,6 @@ int rjb_create_jvm(JNIEnv** pjenv, JavaVMInitArgs* vm_args, char* userpath, VALU
206
228
  { "DUMMY", NULL }, /* for classpath count */
207
229
  };
208
230
  char* newpath;
209
- VALUE ptr;
210
231
  int len;
211
232
  int result;
212
233
  GETDEFAULTJAVAVMINITARGS initargs;
@@ -218,7 +239,7 @@ int rjb_create_jvm(JNIEnv** pjenv, JavaVMInitArgs* vm_args, char* userpath, VALU
218
239
 
219
240
  if (!RTEST(jvmdll))
220
241
  {
221
- if (!load_jvm(JVM_TYPE))
242
+ if (!load_jvm(JVM_TYPE) && !load_jvm(ALT_JVM_TYPE))
222
243
  {
223
244
  return -1;
224
245
  }
@@ -281,6 +302,10 @@ int rjb_create_jvm(JNIEnv** pjenv, JavaVMInitArgs* vm_args, char* userpath, VALU
281
302
  if (!result)
282
303
  {
283
304
  result = load_bridge(*pjenv);
305
+ if (RTEST(ruby_verbose) && result < 0)
306
+ {
307
+ fprintf(stderr, "failed to load the bridge class\n");
308
+ }
284
309
  }
285
310
  return result;
286
311
  }
data/ext/riconv.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: 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
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * Rjb - Ruby <-> Java Bridge
3
- * Copyright(c) 2004,2005,2006,2007 arton
3
+ * Copyright(c) 2004,2005,2006,2007,2008 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 60 2008-02-21 20:11:37Z arton $
15
+ * $Id: rjb.c 77 2008-08-14 10:22:35Z arton $
16
16
  */
17
17
 
18
- #define RJB_VERSION "1.1.2"
18
+ #define RJB_VERSION "1.1.4"
19
19
 
20
20
  #include "ruby.h"
21
21
  #include "extconf.h"
@@ -28,6 +28,7 @@
28
28
  #include "jp_co_infoseek_hp_arton_rjb_RBridge.h"
29
29
  #include "riconv.h"
30
30
  #include "rjb.h"
31
+ #include "ctype.h"
31
32
 
32
33
  /*
33
34
  * Method Modifier Flag defined in
@@ -41,6 +42,20 @@
41
42
  #define ACC_VOLATILE 0x0040
42
43
  #define ACC_TRANSIENT 0x0080
43
44
 
45
+ #define RJB_FIND_CLASS(var, name) \
46
+ var = (*jenv)->FindClass(jenv, name); \
47
+ rjb_check_exception(jenv, 1)
48
+ #define RJB_HOLD_CLASS(var, name) \
49
+ var = (*jenv)->FindClass(jenv, name); \
50
+ rjb_check_exception(jenv, 1); \
51
+ var = (*jenv)->NewGlobalRef(jenv, var)
52
+ #define RJB_LOAD_METHOD(var, obj, name, sig) \
53
+ var = (*jenv)->GetMethodID(jenv, obj, name, sig); \
54
+ rjb_check_exception(jenv, 1)
55
+ #define RJB_LOAD_STATIC_METHOD(var, obj, name, sig) \
56
+ var = (*jenv)->GetStaticMethodID(jenv, obj, name, sig); \
57
+ rjb_check_exception(jenv, 1)
58
+
44
59
  static void register_class(VALUE, VALUE);
45
60
  static VALUE import_class(JNIEnv* jenv, jclass, VALUE);
46
61
  static VALUE register_instance(JNIEnv* jenv, struct jvi_data*, jobject);
@@ -101,7 +116,7 @@ enum PrimitiveType {
101
116
  PRM_SHORT,
102
117
  PRM_BYTE,
103
118
  PRM_FLOAT,
104
- //
119
+ /* */
105
120
  PRM_LAST
106
121
  };
107
122
 
@@ -126,7 +141,6 @@ JNIEnv* rjb_attach_current_thread(void)
126
141
  return env;
127
142
  }
128
143
 
129
-
130
144
  void rjb_release_string(JNIEnv *jenv, jstring str, const char* chrs)
131
145
  {
132
146
  (*jenv)->ReleaseStringUTFChars(jenv, str, chrs);
@@ -146,6 +160,7 @@ static char* java2jniname(char* jnicls)
146
160
  return jnicls;
147
161
  }
148
162
 
163
+ #if 0
149
164
  static char* jni2javaname(char* jnicls)
150
165
  {
151
166
  char* p;
@@ -158,6 +173,7 @@ static char* jni2javaname(char* jnicls)
158
173
  }
159
174
  return jnicls;
160
175
  }
176
+ #endif
161
177
 
162
178
  static char* next_sig(char* p)
163
179
  {
@@ -240,7 +256,7 @@ static VALUE jv2rv_r(JNIEnv* jenv, jvalue val)
240
256
  VALUE clsname;
241
257
  VALUE v;
242
258
  struct jv_data* ptr;
243
- // object to ruby
259
+ /* object to ruby */
244
260
  if (!val.l) return Qnil;
245
261
  klass = (*jenv)->GetObjectClass(jenv, val.l);
246
262
 
@@ -518,7 +534,7 @@ static jprimitive_table jpcvt[] = {
518
534
  { "java/lang/Double", "doubleValue", "()D", "(D)V", NULL, 0, 0, jdouble2rv, },
519
535
  { "java/lang/Boolean", "booleanValue", "()Z", "(Z)Ljava/lang/Boolean;",
520
536
  NULL, 0, 0, jboolean2rv, },
521
- { "java/lang/Character", "charValue", "()C", NULL, NULL, 0, 0, jint2rv, },
537
+ { "java/lang/Character", "charValue", "()C", NULL, NULL, 0, 0, jchar2rv, },
522
538
  { "java/lang/Short", "intValue", "()I", NULL, NULL, 0, 0, jint2rv, },
523
539
  { "java/lang/Byte", "intValue", "()I", NULL, NULL, 0, 0, jint2rv, },
524
540
  { "java/lang/Float", "doubleValue", "()D", NULL, NULL, 0, 0, jdouble2rv, },
@@ -702,7 +718,7 @@ static void rv2jstring(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
702
718
  Data_Get_Struct(val, struct jvi_data, ptr);
703
719
  if ((*jenv)->IsInstanceOf(jenv, ptr->obj, j_string))
704
720
  {
705
- return; // never delete at this time
721
+ return; /* never delete at this time */
706
722
  }
707
723
  }
708
724
  }
@@ -726,7 +742,7 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
726
742
  }
727
743
  else if (NIL_P(val))
728
744
  {
729
- // no-op
745
+ /* no-op */
730
746
  }
731
747
  else if (FIXNUM_P(val))
732
748
  {
@@ -752,7 +768,7 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
752
768
  case T_DATA:
753
769
  if (RBASIC(val)->klass == rjbi || RBASIC(val)->klass == rjb)
754
770
  {
755
- // TODO: check instanceof (class (in psig) )
771
+ /* TODO: check instanceof (class (in psig) ) */
756
772
  struct jvi_data* ptr;
757
773
  Data_Get_Struct(val, struct jvi_data, ptr);
758
774
  jv->l = ptr->obj;
@@ -813,7 +829,7 @@ static void check_fixnumarray(VALUE v)
813
829
  int i;
814
830
  int len = RARRAY_LEN(v);
815
831
  VALUE* p = RARRAY_PTR(v);
816
- // check all fixnum (overflow is permit)
832
+ /* check all fixnum (overflow is permit) */
817
833
  for (i = 0; i < len; i++)
818
834
  {
819
835
  if (!FIXNUM_P(*p++))
@@ -830,7 +846,7 @@ static jarray r2barray(JNIEnv* jenv, VALUE v, const char* cls)
830
846
  {
831
847
  ary = (*jenv)->NewByteArray(jenv, RSTRING_LEN(v));
832
848
  (*jenv)->SetByteArrayRegion(jenv, ary, 0, RSTRING_LEN(v),
833
- RSTRING_PTR(v));
849
+ (const jbyte*)RSTRING_PTR(v));
834
850
  }
835
851
  else if (TYPE(v) == T_ARRAY)
836
852
  {
@@ -1080,7 +1096,7 @@ static void rv2jarray(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int
1080
1096
  jarray ja = NULL;
1081
1097
  if (NIL_P(val))
1082
1098
  {
1083
- // no-op, null for an array
1099
+ /* no-op, null for an array */
1084
1100
  }
1085
1101
  else if (*(psig + 1) == '[')
1086
1102
  {
@@ -1179,7 +1195,7 @@ static J2R get_arrayconv(const char* cname, char* pdepth)
1179
1195
  return jcvt[i].ja2r;
1180
1196
  }
1181
1197
  }
1182
- return jarray2rv;
1198
+ return &jarray2rv;
1183
1199
  }
1184
1200
 
1185
1201
  static J2R get_j2r(JNIEnv* jenv, jobject cls, char* psig, char* pdepth, char* ppsig, off_t* piv, int static_method)
@@ -1334,7 +1350,6 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
1334
1350
  {
1335
1351
  struct cls_method* result;
1336
1352
  struct cls_method* pm;
1337
- char* param = NULL;
1338
1353
  const char* jname;
1339
1354
  jstring nm;
1340
1355
  jobjectArray parama;
@@ -1363,7 +1378,7 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
1363
1378
  (*jenv)->DeleteLocalRef(jenv, cls);
1364
1379
  result->static_method = static_method;
1365
1380
  register_methodinfo(result, tbl);
1366
- // create method alias
1381
+ /* create method alias */
1367
1382
  pm = NULL;
1368
1383
  if (strlen(rname) > 3
1369
1384
  && (*rname == 'g' || *rname == 's') && *(rname + 1) == 'e' && *(rname + 2) == 't')
@@ -1410,7 +1425,6 @@ static void create_fieldinfo(JNIEnv* jenv, st_table* tbl, jobject f, int readonl
1410
1425
  jobject cls;
1411
1426
  char sigs[256];
1412
1427
  off_t iv = 0;
1413
- char sig = 0;
1414
1428
 
1415
1429
  result = ALLOC(struct cls_field);
1416
1430
  memset(result, 0, sizeof(struct cls_field));
@@ -1526,7 +1540,7 @@ static void load_constants(JNIEnv* jenv, jclass klass, VALUE self, jobjectArray
1526
1540
  char sigs[256];
1527
1541
  char* pname;
1528
1542
 
1529
- // constants make define directly in the ruby object
1543
+ /* constants make define directly in the ruby object */
1530
1544
  cls = (*jenv)->CallObjectMethod(jenv, f, field_getType);
1531
1545
  rjb_check_exception(jenv, 0);
1532
1546
  iv = 0;
@@ -1674,67 +1688,44 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
1674
1688
  main_jenv = jenv;
1675
1689
  }
1676
1690
 
1677
- jconstructor = (*jenv)->FindClass(jenv, "java/lang/reflect/Constructor");
1678
- rjb_check_exception(jenv, 1);
1679
- ctrGetParameterTypes = (*jenv)->GetMethodID(jenv, jconstructor, "getParameterTypes", "()[Ljava/lang/Class;");
1680
- rjb_check_exception(jenv, 1);
1681
- jmethod = (*jenv)->FindClass(jenv, "java/lang/reflect/Method");
1682
- method_getModifiers = (*jenv)->GetMethodID(jenv, jmethod, "getModifiers", "()I");
1683
- rjb_check_exception(jenv, 1);
1684
- method_getName = (*jenv)->GetMethodID(jenv, jmethod, "getName", "()Ljava/lang/String;");
1685
- rjb_check_exception(jenv, 1);
1686
- getParameterTypes = (*jenv)->GetMethodID(jenv, jmethod, "getParameterTypes", "()[Ljava/lang/Class;");
1687
- rjb_check_exception(jenv, 1);
1688
- getReturnType = (*jenv)->GetMethodID(jenv, jmethod, "getReturnType", "()Ljava/lang/Class;");
1689
- rjb_check_exception(jenv, 1);
1691
+ RJB_FIND_CLASS(jconstructor, "java/lang/reflect/Constructor");
1692
+ RJB_LOAD_METHOD(ctrGetParameterTypes, jconstructor, "getParameterTypes", "()[Ljava/lang/Class;");
1693
+ RJB_FIND_CLASS(jmethod, "java/lang/reflect/Method");
1694
+ RJB_LOAD_METHOD(method_getModifiers, jmethod, "getModifiers", "()I");
1695
+ RJB_LOAD_METHOD(method_getName, jmethod, "getName", "()Ljava/lang/String;");
1696
+ RJB_LOAD_METHOD(getParameterTypes, jmethod, "getParameterTypes", "()[Ljava/lang/Class;");
1697
+ RJB_LOAD_METHOD(getReturnType, jmethod, "getReturnType", "()Ljava/lang/Class;");
1690
1698
 
1691
- jfield = (*jenv)->FindClass(jenv, "java/lang/reflect/Field");
1692
- field_getModifiers = (*jenv)->GetMethodID(jenv, jfield, "getModifiers", "()I");
1693
- rjb_check_exception(jenv, 1);
1694
- field_getName = (*jenv)->GetMethodID(jenv, jfield, "getName", "()Ljava/lang/String;");
1695
- rjb_check_exception(jenv, 1);
1696
- field_getType = (*jenv)->GetMethodID(jenv, jfield, "getType", "()Ljava/lang/Class;");
1697
- rjb_check_exception(jenv, 1);
1699
+ RJB_FIND_CLASS(jfield, "java/lang/reflect/Field");
1700
+ RJB_LOAD_METHOD(field_getModifiers, jfield, "getModifiers", "()I");
1701
+ RJB_LOAD_METHOD(field_getName, jfield, "getName", "()Ljava/lang/String;");
1702
+ RJB_LOAD_METHOD(field_getType, jfield, "getType", "()Ljava/lang/Class;");
1698
1703
 
1699
- j_class = (*jenv)->FindClass(jenv, "java/lang/Class");
1700
- rjb_check_exception(jenv, 1);
1701
- rjb_class_getName = (*jenv)->GetMethodID(jenv, j_class, "getName", "()Ljava/lang/String;");
1702
- rjb_check_exception(jenv, 1);
1703
- j_class = (*jenv)->NewGlobalRef(jenv, j_class);
1704
+ RJB_HOLD_CLASS(j_class, "java/lang/Class");
1705
+ RJB_LOAD_METHOD(rjb_class_getName, j_class, "getName", "()Ljava/lang/String;");
1704
1706
 
1705
- rjb_j_throwable = (*jenv)->FindClass(jenv, "java/lang/Throwable");
1706
- rjb_check_exception(jenv, 1);
1707
- rjb_throwable_getMessage = (*jenv)->GetMethodID(jenv, rjb_j_throwable, "getMessage", "()Ljava/lang/String;");
1708
- rjb_check_exception(jenv, 1);
1707
+ RJB_HOLD_CLASS(rjb_j_throwable, "java/lang/Throwable");
1708
+ RJB_LOAD_METHOD(rjb_throwable_getMessage, rjb_j_throwable, "getMessage", "()Ljava/lang/String;");
1709
1709
 
1710
- j_string = (*jenv)->FindClass(jenv, "java/lang/String");
1711
- rjb_check_exception(jenv, 1);
1712
- str_tostring = (*jenv)->GetMethodID(jenv, j_string, "toString", "()Ljava/lang/String;");
1713
- rjb_check_exception(jenv, 1);
1714
- j_string = (*jenv)->NewGlobalRef(jenv, j_string);
1710
+ RJB_HOLD_CLASS(j_string, "java/lang/String");
1711
+ RJB_LOAD_METHOD(str_tostring, j_string, "toString", "()Ljava/lang/String;");
1715
1712
 
1716
- j_object = (*jenv)->FindClass(jenv, "java/lang/Object");
1717
- rjb_check_exception(jenv, 1);
1718
- j_object = (*jenv)->NewGlobalRef(jenv, j_object);
1713
+ RJB_HOLD_CLASS(j_object, "java/lang/Object");
1719
1714
 
1720
1715
  for (i = PRM_INT; i < PRM_LAST; i++)
1721
1716
  {
1722
1717
  jclass klass = (*jenv)->FindClass(jenv, jpcvt[i].classname);
1723
1718
  if (i == PRM_BOOLEAN)
1724
1719
  {
1725
- jpcvt[i].ctr_id = (*jenv)->GetStaticMethodID(jenv,
1726
- klass, "valueOf", jpcvt[i].ctrsig);
1727
- rjb_check_exception(jenv, 1);
1720
+ RJB_LOAD_STATIC_METHOD(jpcvt[i].ctr_id, klass, "valueOf", jpcvt[i].ctrsig);
1728
1721
  }
1729
1722
  else if (jpcvt[i].ctrsig)
1730
1723
  {
1731
- jpcvt[i].ctr_id = (*jenv)->GetMethodID(jenv, klass,
1732
- "<init>", jpcvt[i].ctrsig);
1733
- rjb_check_exception(jenv, 1);
1724
+ RJB_LOAD_METHOD(jpcvt[i].ctr_id, klass, "<init>", jpcvt[i].ctrsig);
1734
1725
  }
1735
- jpcvt[i].to_prim_id = (*jenv)->GetMethodID(jenv, klass,
1726
+ RJB_LOAD_METHOD(jpcvt[i].to_prim_id, klass,
1736
1727
  jpcvt[i].to_prim_method, jpcvt[i].prmsig);
1737
- rjb_check_exception(jenv, 1);
1728
+
1738
1729
  jpcvt[i].klass = (*jenv)->NewGlobalRef(jenv, klass);
1739
1730
  }
1740
1731
 
@@ -1745,6 +1736,17 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
1745
1736
  return Qnil;
1746
1737
  }
1747
1738
 
1739
+ /*
1740
+ * load Java Virtual Machine with default arguments.
1741
+ */
1742
+ VALUE rjb_load_vm_default()
1743
+ {
1744
+ if (rjb_jvm) return Qfalse;
1745
+
1746
+ rb_warning("Rjb::implicit jvm loading");
1747
+ return rjb_s_load(0, NULL, 0);
1748
+ }
1749
+
1748
1750
  /*
1749
1751
  * unload Java Virtual Machine
1750
1752
  *
@@ -1759,13 +1761,16 @@ static int clear_classes(VALUE key, VALUE val, VALUE dummy)
1759
1761
  }
1760
1762
  static VALUE rjb_s_unload(int argc, VALUE* argv, VALUE self)
1761
1763
  {
1764
+ int result = 0;
1762
1765
  st_foreach(RHASH_TBL(rjb_loaded_classes), clear_classes, 0);
1763
1766
  if (rjb_jvm)
1764
1767
  {
1765
- (*rjb_jvm)->DestroyJavaVM(rjb_jvm);
1766
- rjb_jvm = NULL;
1768
+ JNIEnv* jenv = rjb_attach_current_thread();
1769
+ (*jenv)->ExceptionClear(jenv);
1770
+ result = (*rjb_jvm)->DestroyJavaVM(rjb_jvm);
1771
+ rjb_jvm = NULL;
1767
1772
  }
1768
- return Qnil;
1773
+ return INT2NUM(result);
1769
1774
  }
1770
1775
 
1771
1776
  /*
@@ -1799,6 +1804,7 @@ static VALUE rjb_s_get_pconversion(VALUE self)
1799
1804
  /*
1800
1805
  * free java class
1801
1806
  */
1807
+ #if 0
1802
1808
  static void free_constructor(struct cls_constructor* p)
1803
1809
  {
1804
1810
  free(p->arg_convert);
@@ -1812,6 +1818,7 @@ static int free_method_item(ID key, struct cls_method* pm, int dummy)
1812
1818
  }
1813
1819
  return ST_CONTINUE;
1814
1820
  }
1821
+ #endif
1815
1822
 
1816
1823
  /*
1817
1824
  * finalize Object instance
@@ -1987,7 +1994,7 @@ static int check_rtype(JNIEnv* jenv, VALUE v, char* p)
1987
1994
  case T_DATA:
1988
1995
  if (RBASIC(v)->klass == rjbi && pcls)
1989
1996
  {
1990
- // imported object
1997
+ /* imported object */
1991
1998
  jclass cls;
1992
1999
  struct jvi_data* ptr;
1993
2000
  int result = 0;
@@ -2001,9 +2008,9 @@ static int check_rtype(JNIEnv* jenv, VALUE v, char* p)
2001
2008
  }
2002
2009
  return result;
2003
2010
  }
2004
- // fall down to the next case
2011
+ /* fall down to the next case */
2005
2012
  case T_OBJECT:
2006
- // fall down to the next case
2013
+ /* fall down to the next case */
2007
2014
  default:
2008
2015
  if (pcls || *p == '[')
2009
2016
  {
@@ -2022,8 +2029,12 @@ static VALUE rjb_newinstance_s(int argc, VALUE* argv, VALUE self)
2022
2029
  char* sig;
2023
2030
  VALUE ret = Qnil;
2024
2031
  struct jv_data* ptr;
2025
- JNIEnv* jenv = rjb_attach_current_thread();
2026
2032
  int found = 0;
2033
+ JNIEnv* jenv = NULL;
2034
+
2035
+ rjb_load_vm_default();
2036
+ jenv = rjb_attach_current_thread();
2037
+ (*jenv)->ExceptionClear(jenv);
2027
2038
 
2028
2039
  rb_scan_args(argc, argv, "1*", &vsig, &rest);
2029
2040
  sig = StringValueCStr(vsig);
@@ -2053,8 +2064,12 @@ static VALUE rjb_newinstance(int argc, VALUE* argv, VALUE self)
2053
2064
  VALUE ret = Qnil;
2054
2065
  struct jv_data* ptr;
2055
2066
  struct cls_constructor** pc;
2056
- JNIEnv* jenv = rjb_attach_current_thread();
2057
2067
  int found = 0;
2068
+ JNIEnv* jenv = NULL;
2069
+
2070
+ rjb_load_vm_default();
2071
+ jenv = rjb_attach_current_thread();
2072
+ (*jenv)->ExceptionClear(jenv);
2058
2073
 
2059
2074
  Data_Get_Struct(self, struct jv_data, ptr);
2060
2075
 
@@ -2111,9 +2126,13 @@ jclass rjb_find_class(JNIEnv* jenv, VALUE name)
2111
2126
  static VALUE rjb_s_bind(VALUE self, VALUE rbobj, VALUE itfname)
2112
2127
  {
2113
2128
  VALUE result = Qnil;
2114
- JNIEnv* jenv = rjb_attach_current_thread();
2129
+ JNIEnv* jenv = NULL;
2130
+ jclass itf;
2115
2131
 
2116
- jclass itf = rjb_find_class(jenv, itfname);
2132
+ rjb_load_vm_default();
2133
+ jenv = rjb_attach_current_thread();
2134
+ (*jenv)->ExceptionClear(jenv);
2135
+ itf = rjb_find_class(jenv, itfname);
2117
2136
  rjb_check_exception(jenv, 1);
2118
2137
  if (itf)
2119
2138
  {
@@ -2137,6 +2156,18 @@ static VALUE rjb_s_bind(VALUE self, VALUE rbobj, VALUE itfname)
2137
2156
  return result;
2138
2157
  }
2139
2158
 
2159
+ /*
2160
+ * jclass Rjb::bind(rbobj, interface_name)
2161
+ */
2162
+ static VALUE rjb_s_unbind(VALUE self, VALUE rbobj)
2163
+ {
2164
+ JNIEnv* jenv;
2165
+ rjb_load_vm_default();
2166
+ jenv = rjb_attach_current_thread();
2167
+ (*jenv)->ExceptionClear(jenv);
2168
+ return rb_ary_delete(proxies, rbobj);
2169
+ }
2170
+
2140
2171
  /*
2141
2172
  * Jclass Rjb::import(classname)
2142
2173
  */
@@ -2150,12 +2181,9 @@ static VALUE rjb_s_import(VALUE self, VALUE clsname)
2150
2181
  return v;
2151
2182
  }
2152
2183
 
2153
- if (!rjb_jvm)
2154
- {
2155
- /* auto-load with default setting */
2156
- rjb_s_load(0, NULL, 0);
2157
- }
2184
+ rjb_load_vm_default();
2158
2185
  jenv = rjb_attach_current_thread();
2186
+ (*jenv)->ExceptionClear(jenv);
2159
2187
  jcls = rjb_find_class(jenv, clsname);
2160
2188
  if (!jcls)
2161
2189
  {
@@ -2439,7 +2467,7 @@ static VALUE invoke(JNIEnv* jenv, struct cls_method* pm, struct jvi_data* ptr,
2439
2467
  }
2440
2468
  if (!found)
2441
2469
  {
2442
- char* tname = rb_id2name(orgpm->name);
2470
+ const char* tname = rb_id2name(orgpm->name);
2443
2471
  if (sig)
2444
2472
  {
2445
2473
  rb_raise(rb_eRuntimeError, "Fail: unknown method name `%s(\'%s\')'", tname, sig);
@@ -2528,7 +2556,7 @@ static VALUE invoke_by_instance(ID rmid, int argc, VALUE* argv,
2528
2556
  JNIEnv* jenv = rjb_attach_current_thread();
2529
2557
  struct cls_field* pf;
2530
2558
  struct cls_method* pm;
2531
- char* tname = rb_id2name(rmid);
2559
+ const char* tname = rb_id2name(rmid);
2532
2560
 
2533
2561
  if (argc == 0 && st_lookup(ptr->fields, rmid, (st_data_t*)&pf))
2534
2562
  {
@@ -2546,7 +2574,7 @@ static VALUE invoke_by_instance(ID rmid, int argc, VALUE* argv,
2546
2574
  setter(jenv, pf, ptr, *argv);
2547
2575
  return ret;
2548
2576
  }
2549
- // fall through for the setter alias name
2577
+ /* fall through for the setter alias name */
2550
2578
  }
2551
2579
  if (st_lookup(ptr->methods, rmid, (st_data_t*)&pm))
2552
2580
  {
@@ -2594,7 +2622,7 @@ static VALUE invoke_by_class(ID rmid, int argc, VALUE* argv,
2594
2622
  struct jv_data* clsptr;
2595
2623
  struct cls_field* pf;
2596
2624
  struct cls_method* pm;
2597
- char* tname = rb_id2name(rmid);
2625
+ const char* tname = rb_id2name(rmid);
2598
2626
  JNIEnv* jenv = rjb_attach_current_thread();
2599
2627
 
2600
2628
  Data_Get_Struct(jklass, struct jv_data, clsptr);
@@ -2671,7 +2699,7 @@ static VALUE rjb_missing(int argc, VALUE* argv, VALUE self)
2671
2699
  {
2672
2700
  struct jv_data* ptr;
2673
2701
  ID rmid = rb_to_id(argv[0]);
2674
- char* rmname = rb_id2name(rmid);
2702
+ const char* rmname = rb_id2name(rmid);
2675
2703
  if (isupper(*rmname))
2676
2704
  {
2677
2705
  VALUE r, args[2];
@@ -2725,6 +2753,7 @@ void Init_rjbcore()
2725
2753
  rb_define_module_function(rjb, "unload", rjb_s_unload, -1);
2726
2754
  rb_define_module_function(rjb, "import", rjb_s_import, 1);
2727
2755
  rb_define_module_function(rjb, "bind", rjb_s_bind, 2);
2756
+ rb_define_module_function(rjb, "unbind", rjb_s_unbind, 1);
2728
2757
  rb_define_module_function(rjb, "classes", rjb_s_classes, 0);
2729
2758
  rb_define_module_function(rjb, "throw", rjb_s_throw, -1);
2730
2759
  rb_define_module_function(rjb, "primitive_conversion=", rjb_s_set_pconversion, 1);
@@ -2802,7 +2831,7 @@ JNIEXPORT jobject JNICALL Java_jp_co_infoseek_hp_arton_rjb_RBridge_call
2802
2831
  *(argv + 2) = argc - 3;
2803
2832
  result = rb_protect(safe_funcall, (VALUE)argv, &sstat);
2804
2833
  rv2jobject(jenv, result, &j, NULL, 0);
2805
- // I can't delete this object...
2834
+ /* I can't delete this object... */
2806
2835
  break;
2807
2836
  }
2808
2837
  }
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);
data/ext/rjbexception.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: rjbexception.c 47 2007-12-28 06:39:43Z arton $
15
+ * $Id: rjbexception.c 75 2008-08-14 10:03:52Z arton $
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);
@@ -103,7 +109,6 @@ void rjb_check_exception(JNIEnv* jenv, int t)
103
109
  (*jenv)->ExceptionDescribe(jenv);
104
110
  }
105
111
  (*jenv)->ExceptionClear(jenv);
106
- // if (t)
107
112
  if(1)
108
113
  {
109
114
  char* msg = "unknown exception";
data/lib/rjbcore.so CHANGED
Binary file
data/test/test.rb CHANGED
@@ -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 70 2008-05-26 12:31:35Z arton $
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
@@ -22,8 +27,7 @@ class TestRjb < Test::Unit::TestCase
22
27
  @jChar = Rjb::import('java.lang.Character')
23
28
  end
24
29
 
25
- def tearDown
26
- unload
30
+ def teardown
27
31
  end
28
32
 
29
33
  def test_metaclass
@@ -226,6 +230,12 @@ class TestRjb < Test::Unit::TestCase
226
230
  assert("43210", a.concat(it))
227
231
  end
228
232
 
233
+ def test_unbind()
234
+ it = TestIter.new
235
+ it = bind(it, 'java.util.Iterator')
236
+ assert(it, unbind(it))
237
+ end
238
+
229
239
  class TestComparator
230
240
  def compare(o1, o2)
231
241
  o1.to_i - o2.to_i
@@ -330,13 +340,46 @@ class TestRjb < Test::Unit::TestCase
330
340
  end
331
341
  end
332
342
 
343
+ def test_throw_clear()
344
+ assert_nothing_raised {
345
+ begin
346
+ Rjb::throw('java.util.NoSuchElementException', 'test exception')
347
+ rescue #drop ruby exception
348
+ end
349
+ test = import('jp.co.infoseek.hp.arton.rjb.Test')
350
+ begin
351
+ Rjb::throw('java.util.NoSuchElementException', 'test exception')
352
+ rescue #drop ruby exception
353
+ end
354
+ test.new
355
+ begin
356
+ Rjb::throw('java.util.NoSuchElementException', 'test exception')
357
+ rescue #drop ruby exception
358
+ end
359
+ @jString.new_with_sig('Ljava.lang.String;', "abcde")
360
+ begin
361
+ Rjb::throw('java.util.NoSuchElementException', 'test exception')
362
+ rescue #drop ruby exception
363
+ end
364
+ it = TestIterator.new(0)
365
+ it = bind(it, 'java.util.Iterator')
366
+ begin
367
+ Rjb::throw('java.util.NoSuchElementException', 'test exception')
368
+ rescue NoSuchElementException
369
+ end
370
+ begin
371
+ Rjb::throw('java.lang.IllegalAccessException', 'test exception')
372
+ rescue IllegalAccessException
373
+ end
374
+ unbind(it)
375
+ }
376
+ end
377
+
333
378
  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)
379
+ test = import('jp.co.infoseek.hp.arton.rjb.Test').new
380
+ assert_equal('Hello World !!', test.helloData)
381
+ test.helloData = 'Goodby World !'
382
+ assert_equal('Goodby World !', test.helloData)
340
383
  end
341
384
 
342
385
  def test_instancemethod_from_class()
@@ -572,5 +615,16 @@ class TestRjb < Test::Unit::TestCase
572
615
  assert_equal "\0\x1\x2\x3\x4", map.get('abc')
573
616
  assert_equal "\x5\x6\x7\x8\x9", map.get('def')
574
617
  end
618
+
619
+ def x_test_zzunload
620
+ # this test should run at the last
621
+ unload
622
+ begin
623
+ load('.')
624
+ fail 'no exception'
625
+ rescue
626
+ assert_equal "can't create Java VM", $!.message
627
+ end
628
+ end
575
629
  end
576
630
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.4
5
5
  platform: x86-mswin32-60
6
6
  authors:
7
7
  - arton
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-22 00:00:00 +09:00
12
+ date: 2008-08-14 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -25,24 +25,24 @@ files:
25
25
  - ext/RBridge.java
26
26
  - ext/load.c
27
27
  - ext/riconv.c
28
- - ext/rjb.c
29
28
  - ext/rjbexception.c
30
- - ext/extconf.h
29
+ - ext/rjb.c
31
30
  - ext/jniwrap.h
32
- - ext/jp_co_infoseek_hp_arton_rjb_RBridge.h
33
- - ext/riconv.h
34
31
  - ext/rjb.h
32
+ - ext/riconv.h
33
+ - ext/jp_co_infoseek_hp_arton_rjb_RBridge.h
34
+ - ext/extconf.h
35
35
  - ext/depend
36
36
  - data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class
37
37
  - lib/rjb.rb
38
38
  - samples/filechooser.rb
39
- - test/gctest.rb
40
39
  - test/test.rb
41
- - test/jp/co/infoseek/hp/arton/rjb/Base.class
40
+ - test/gctest.rb
42
41
  - test/jp/co/infoseek/hp/arton/rjb/ExtBase.class
42
+ - test/jp/co/infoseek/hp/arton/rjb/Test.class
43
43
  - test/jp/co/infoseek/hp/arton/rjb/IBase.class
44
44
  - test/jp/co/infoseek/hp/arton/rjb/Test$TestTypes.class
45
- - test/jp/co/infoseek/hp/arton/rjb/Test.class
45
+ - test/jp/co/infoseek/hp/arton/rjb/Base.class
46
46
  - COPYING
47
47
  - ChangeLog
48
48
  - readme.sj
@@ -72,7 +72,7 @@ requirements:
72
72
  - JDK 5.0
73
73
  - " VC6 version of Ruby"
74
74
  rubyforge_project:
75
- rubygems_version: 1.0.1
75
+ rubygems_version: 1.2.0
76
76
  signing_key:
77
77
  specification_version: 2
78
78
  summary: Ruby Java bridge