rjb 1.0.2-mswin32 → 1.0.3-mswin32
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 +7 -0
- data/ext/jp_co_infoseek_hp_arton_rjb_RBridge.h +12 -12
- data/ext/load.c +10 -13
- data/ext/rjb.c +125 -126
- data/ext/rjb.h +16 -10
- data/ext/rjbexception.c +13 -13
- data/lib/rjbcore.so +0 -0
- metadata +2 -2
data/ChangeLog
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
/* DO NOT EDIT THIS FILE - it is machine generated */
|
2
|
-
#include <jni.h>
|
2
|
+
#include <jni.h>
|
3
3
|
/* Header for class jp_co_infoseek_hp_arton_rjb_RBridge */
|
4
4
|
|
5
5
|
#ifndef _Included_jp_co_infoseek_hp_arton_rjb_RBridge
|
6
|
-
#define _Included_jp_co_infoseek_hp_arton_rjb_RBridge
|
6
|
+
#define _Included_jp_co_infoseek_hp_arton_rjb_RBridge
|
7
7
|
#ifdef __cplusplus
|
8
8
|
extern "C" {
|
9
|
-
#endif
|
10
|
-
/*
|
11
|
-
* Class: jp_co_infoseek_hp_arton_rjb_RBridge
|
12
|
-
* Method: call
|
13
|
-
* Signature: (Ljava/lang/String;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
|
14
|
-
*/
|
15
|
-
JNIEXPORT jobject JNICALL Java_jp_co_infoseek_hp_arton_rjb_RBridge_call
|
9
|
+
#endif
|
10
|
+
/*
|
11
|
+
* Class: jp_co_infoseek_hp_arton_rjb_RBridge
|
12
|
+
* Method: call
|
13
|
+
* Signature: (Ljava/lang/String;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
|
14
|
+
*/
|
15
|
+
JNIEXPORT jobject JNICALL Java_jp_co_infoseek_hp_arton_rjb_RBridge_call
|
16
16
|
(JNIEnv *, jobject, jstring, jobject, jobjectArray);
|
17
|
-
|
17
|
+
|
18
18
|
#ifdef __cplusplus
|
19
19
|
}
|
20
|
-
#endif
|
21
|
-
#endif
|
20
|
+
#endif
|
21
|
+
#endif
|
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
|
15
|
+
* $Id: load.c 8 2006-11-20 19:17:22Z arton $
|
16
16
|
*/
|
17
17
|
|
18
18
|
#include <stdlib.h>
|
@@ -63,9 +63,6 @@
|
|
63
63
|
typedef void (*GETDEFAULTJAVAVMINITARGS)(void*);
|
64
64
|
typedef int (*CREATEJAVAVM)(JavaVM**, void**, void*);
|
65
65
|
|
66
|
-
extern JavaVM* jvm;
|
67
|
-
extern jclass rbridge;
|
68
|
-
extern jmethodID register_bridge;
|
69
66
|
static VALUE jvmdll = Qnil;
|
70
67
|
static VALUE GetDefaultJavaVMInitArgs;
|
71
68
|
static VALUE CreateJavaVM;
|
@@ -119,7 +116,7 @@ static VALUE load_jvm(char* jvmtype)
|
|
119
116
|
return Qtrue;
|
120
117
|
}
|
121
118
|
|
122
|
-
int load_bridge(JNIEnv* jenv)
|
119
|
+
static int load_bridge(JNIEnv* jenv)
|
123
120
|
{
|
124
121
|
JNINativeMethod nmethod[1];
|
125
122
|
jbyte buff[8192];
|
@@ -151,23 +148,23 @@ int load_bridge(JNIEnv* jenv)
|
|
151
148
|
}
|
152
149
|
len = fread(buff, 1, sizeof(buff), f);
|
153
150
|
fclose(f);
|
154
|
-
|
151
|
+
rjb_rbridge = (*jenv)->DefineClass(jenv,
|
155
152
|
"jp/co/infoseek/hp/arton/rjb/RBridge", iloader, buff, len);
|
156
|
-
if (
|
153
|
+
if (rjb_rbridge == NULL)
|
157
154
|
{
|
158
|
-
|
155
|
+
rjb_check_exception(jenv, 1);
|
159
156
|
}
|
160
|
-
|
157
|
+
rjb_register_bridge = (*jenv)->GetMethodID(jenv, rjb_rbridge, "register",
|
161
158
|
"(Ljava/lang/Class;)Ljava/lang/Object;");
|
162
159
|
nmethod[0].name = "call";
|
163
160
|
nmethod[0].signature = "(Ljava/lang/String;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;";
|
164
161
|
nmethod[0].fnPtr = Java_jp_co_infoseek_hp_arton_rjb_RBridge_call;
|
165
|
-
(*jenv)->RegisterNatives(jenv,
|
166
|
-
|
162
|
+
(*jenv)->RegisterNatives(jenv, rjb_rbridge, nmethod, 1);
|
163
|
+
rjb_rbridge = (*jenv)->NewGlobalRef(jenv, rjb_rbridge);
|
167
164
|
return 0;
|
168
165
|
}
|
169
166
|
|
170
|
-
int
|
167
|
+
int rjb_create_jvm(JNIEnv** pjenv, JavaVMInitArgs* vm_args, char* userpath, VALUE argv)
|
171
168
|
{
|
172
169
|
static JavaVMOption soptions[] = {
|
173
170
|
#if defined(__sparc_v9__) || defined(__sparc__)
|
@@ -244,7 +241,7 @@ int create_jvm(JNIEnv** pjenv, JavaVMInitArgs* vm_args, char* userpath, VALUE ar
|
|
244
241
|
vm_args->ignoreUnrecognized = JNI_TRUE;
|
245
242
|
ptr = rb_funcall(CreateJavaVM, rb_intern("to_i"), 0);
|
246
243
|
createjavavm = *(CREATEJAVAVM*)FIX2INT(ptr);
|
247
|
-
result = createjavavm(&
|
244
|
+
result = createjavavm(&rjb_jvm, (void**)pjenv, vm_args);
|
248
245
|
if (!result)
|
249
246
|
{
|
250
247
|
result = load_bridge(*pjenv);
|
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
|
15
|
+
* $Id: rjb.c 8 2006-11-20 19:17:22Z arton $
|
16
16
|
*/
|
17
17
|
|
18
|
-
#define RJB_VERSION "1.0.
|
18
|
+
#define RJB_VERSION "1.0.3"
|
19
19
|
|
20
20
|
#include "ruby.h"
|
21
21
|
#include "st.h"
|
@@ -36,7 +36,6 @@
|
|
36
36
|
#define ACC_VOLATILE 0x0040
|
37
37
|
#define ACC_TRANSIENT 0x0080
|
38
38
|
|
39
|
-
extern int create_jvm(JNIEnv** pjenv, JavaVMInitArgs*, char*, VALUE);
|
40
39
|
static void register_class(VALUE, VALUE);
|
41
40
|
static VALUE import_class(JNIEnv* jenv, jclass, VALUE);
|
42
41
|
static VALUE register_instance(JNIEnv* jenv, struct jvi_data*, jobject);
|
@@ -48,16 +47,16 @@ static jarray r2objarray(JNIEnv* jenv, VALUE v, const char* cls);
|
|
48
47
|
|
49
48
|
static VALUE rjb;
|
50
49
|
static VALUE jklass;
|
51
|
-
VALUE rjbc;
|
52
|
-
VALUE rjbi;
|
53
|
-
VALUE rjbb;
|
50
|
+
static VALUE rjbc;
|
51
|
+
static VALUE rjbi;
|
52
|
+
static VALUE rjbb;
|
54
53
|
|
55
|
-
VALUE
|
54
|
+
VALUE rjb_loaded_classes;
|
56
55
|
static VALUE proxies;
|
57
|
-
JavaVM*
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
JavaVM* rjb_jvm;
|
57
|
+
jclass rjb_rbridge;
|
58
|
+
jmethodID rjb_register_bridge;
|
59
|
+
static JNIEnv* main_jenv;
|
61
60
|
|
62
61
|
/*
|
63
62
|
* Object cache, never destroyed
|
@@ -74,11 +73,11 @@ static jmethodID field_getType;
|
|
74
73
|
/* constructor */
|
75
74
|
static jmethodID ctrGetParameterTypes;
|
76
75
|
/* class */
|
77
|
-
jclass j_class;
|
78
|
-
jmethodID
|
76
|
+
static jclass j_class;
|
77
|
+
jmethodID rjb_class_getName;
|
79
78
|
/* throwable */
|
80
|
-
jclass
|
81
|
-
jmethodID
|
79
|
+
jclass rjb_j_throwable;
|
80
|
+
jmethodID rjb_throwable_getMessage;
|
82
81
|
/* String global reference */
|
83
82
|
static jclass j_string;
|
84
83
|
static jmethodID str_tostring;
|
@@ -112,15 +111,15 @@ typedef struct jobject_ruby_table {
|
|
112
111
|
J2R func;
|
113
112
|
} jprimitive_table;
|
114
113
|
|
115
|
-
JNIEnv*
|
114
|
+
JNIEnv* rjb_attach_current_thread(void)
|
116
115
|
{
|
117
116
|
JNIEnv* env;
|
118
|
-
(*
|
117
|
+
(*rjb_jvm)->AttachCurrentThread(rjb_jvm, (void**)&env, '\0');
|
119
118
|
return env;
|
120
119
|
}
|
121
120
|
|
122
121
|
|
123
|
-
void
|
122
|
+
void rjb_release_string(JNIEnv *jenv, jstring str, const char* chrs)
|
124
123
|
{
|
125
124
|
(*jenv)->ReleaseStringUTFChars(jenv, str, chrs);
|
126
125
|
(*jenv)->DeleteLocalRef(jenv, str);
|
@@ -184,7 +183,7 @@ static VALUE jstring2val(JNIEnv* jenv, jstring s)
|
|
184
183
|
p = (*jenv)->GetStringUTFChars(jenv, s, NULL);
|
185
184
|
v = rb_str_new2(p);
|
186
185
|
v = exticonv_utf8_to_local(v);
|
187
|
-
|
186
|
+
rjb_release_string(jenv, s, p);
|
188
187
|
return v;
|
189
188
|
}
|
190
189
|
|
@@ -211,12 +210,12 @@ static VALUE jv2rclass(JNIEnv* jenv, jclass jc)
|
|
211
210
|
const char* cname;
|
212
211
|
VALUE clsname;
|
213
212
|
VALUE v;
|
214
|
-
jstring nm = (*jenv)->CallObjectMethod(jenv, jc,
|
215
|
-
|
213
|
+
jstring nm = (*jenv)->CallObjectMethod(jenv, jc, rjb_class_getName);
|
214
|
+
rjb_check_exception(jenv, 0);
|
216
215
|
cname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
|
217
216
|
clsname = rb_str_new2(cname);
|
218
|
-
|
219
|
-
v = rb_hash_aref(
|
217
|
+
rjb_release_string(jenv, nm, cname);
|
218
|
+
v = rb_hash_aref(rjb_loaded_classes, clsname);
|
220
219
|
if (v == Qnil)
|
221
220
|
{
|
222
221
|
v = import_class(jenv, jc, clsname);
|
@@ -241,17 +240,17 @@ static VALUE jv2rv(JNIEnv* jenv, jvalue val)
|
|
241
240
|
(*jenv)->DeleteLocalRef(jenv, klass);
|
242
241
|
return jv2rclass(jenv, val.l);
|
243
242
|
}
|
244
|
-
nm = (*jenv)->CallObjectMethod(jenv, klass,
|
245
|
-
|
243
|
+
nm = (*jenv)->CallObjectMethod(jenv, klass, rjb_class_getName);
|
244
|
+
rjb_check_exception(jenv, 0);
|
246
245
|
cname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
|
247
246
|
if (*cname == '[')
|
248
247
|
{
|
249
|
-
|
248
|
+
rjb_release_string(jenv, nm, cname);
|
250
249
|
return jarray2rv(jenv, val);
|
251
250
|
}
|
252
251
|
clsname = rb_str_new2(cname);
|
253
|
-
|
254
|
-
v = rb_hash_aref(
|
252
|
+
rjb_release_string(jenv, nm, cname);
|
253
|
+
v = rb_hash_aref(rjb_loaded_classes, clsname);
|
255
254
|
if (v == Qnil)
|
256
255
|
{
|
257
256
|
v = import_class(jenv, klass, clsname);
|
@@ -639,9 +638,9 @@ static void rv2jstring(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
|
|
639
638
|
jmethodID tostr;
|
640
639
|
jstring js;
|
641
640
|
tostr = (*jenv)->GetMethodID(jenv, ptr->klass, "toString", "()Ljava/lang/String;");
|
642
|
-
|
641
|
+
rjb_check_exception(jenv, 0);
|
643
642
|
js = (*jenv)->CallObjectMethod(jenv, ptr->obj, tostr);
|
644
|
-
|
643
|
+
rjb_check_exception(jenv, 0);
|
645
644
|
jv->l = js;
|
646
645
|
}
|
647
646
|
}
|
@@ -961,7 +960,7 @@ static jarray r2objarray(JNIEnv* jenv, VALUE v, const char* cls)
|
|
961
960
|
{
|
962
961
|
int i;
|
963
962
|
ary = (*jenv)->NewObjectArray(jenv, RARRAY(v)->len, j_object, NULL);
|
964
|
-
|
963
|
+
rjb_check_exception(jenv, 0);
|
965
964
|
for (i = 0; i < RARRAY(v)->len; i++)
|
966
965
|
{
|
967
966
|
jvalue jv;
|
@@ -1043,7 +1042,7 @@ static void rv2jarray(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int
|
|
1043
1042
|
rb_raise(rb_eRuntimeError, "array's rank unmatch");
|
1044
1043
|
}
|
1045
1044
|
ja = (*jenv)->NewObjectArray(jenv, RARRAY(val)->len, j_object, NULL);
|
1046
|
-
|
1045
|
+
rjb_check_exception(jenv, 0);
|
1047
1046
|
for (i = 0; i < RARRAY(val)->len; i++)
|
1048
1047
|
{
|
1049
1048
|
jvalue jv;
|
@@ -1075,8 +1074,8 @@ static R2J get_r2j(JNIEnv* jenv, jobject o, int* siglen, char* sigp)
|
|
1075
1074
|
int len, i;
|
1076
1075
|
const char* cname;
|
1077
1076
|
R2J result = NULL;
|
1078
|
-
jstring nm = (*jenv)->CallObjectMethod(jenv, o,
|
1079
|
-
|
1077
|
+
jstring nm = (*jenv)->CallObjectMethod(jenv, o, rjb_class_getName);
|
1078
|
+
rjb_check_exception(jenv, 0);
|
1080
1079
|
cname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
|
1081
1080
|
if (*cname == '[')
|
1082
1081
|
{
|
@@ -1112,7 +1111,7 @@ static R2J get_r2j(JNIEnv* jenv, jobject o, int* siglen, char* sigp)
|
|
1112
1111
|
result = rv2jobject;
|
1113
1112
|
}
|
1114
1113
|
}
|
1115
|
-
|
1114
|
+
rjb_release_string(jenv, nm, cname);
|
1116
1115
|
return result;
|
1117
1116
|
}
|
1118
1117
|
|
@@ -1122,8 +1121,8 @@ static J2R get_j2r(JNIEnv* jenv, jobject cls, char* psig, char* pdepth, char* pp
|
|
1122
1121
|
J2R result = NULL;
|
1123
1122
|
const char* cname;
|
1124
1123
|
const char* jname = NULL;
|
1125
|
-
jstring nm = (*jenv)->CallObjectMethod(jenv, cls,
|
1126
|
-
|
1124
|
+
jstring nm = (*jenv)->CallObjectMethod(jenv, cls, rjb_class_getName);
|
1125
|
+
rjb_check_exception(jenv, 0);
|
1127
1126
|
cname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
|
1128
1127
|
|
1129
1128
|
if (*cname == '[')
|
@@ -1179,7 +1178,7 @@ static J2R get_j2r(JNIEnv* jenv, jobject cls, char* psig, char* pdepth, char* pp
|
|
1179
1178
|
}
|
1180
1179
|
java2jniname(ppsig);
|
1181
1180
|
}
|
1182
|
-
|
1181
|
+
rjb_release_string(jenv, nm, cname);
|
1183
1182
|
return result;
|
1184
1183
|
}
|
1185
1184
|
|
@@ -1256,20 +1255,20 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
|
|
1256
1255
|
|
1257
1256
|
result = ALLOC(struct cls_method);
|
1258
1257
|
parama = (*jenv)->CallObjectMethod(jenv, m, getParameterTypes);
|
1259
|
-
|
1258
|
+
rjb_check_exception(jenv, 0);
|
1260
1259
|
param_count = (*jenv)->GetArrayLength(jenv, parama);
|
1261
|
-
|
1260
|
+
rjb_check_exception(jenv, 0);
|
1262
1261
|
setup_methodbase(jenv, &result->basic, parama, param_count);
|
1263
1262
|
|
1264
1263
|
nm = (*jenv)->CallObjectMethod(jenv, m, method_getName);
|
1265
|
-
|
1264
|
+
rjb_check_exception(jenv, 0);
|
1266
1265
|
jname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
|
1267
1266
|
result->name = rb_intern(jname);
|
1268
|
-
|
1267
|
+
rjb_release_string(jenv, nm, jname);
|
1269
1268
|
result->basic.id = (*jenv)->FromReflectedMethod(jenv, m);
|
1270
|
-
|
1269
|
+
rjb_check_exception(jenv, 0);
|
1271
1270
|
cls = (*jenv)->CallObjectMethod(jenv, m, getReturnType);
|
1272
|
-
|
1271
|
+
rjb_check_exception(jenv, 0);
|
1273
1272
|
setup_j2r(jenv, cls, result, static_method);
|
1274
1273
|
(*jenv)->DeleteLocalRef(jenv, cls);
|
1275
1274
|
result->static_method = static_method;
|
@@ -1298,14 +1297,14 @@ static void create_fieldinfo(JNIEnv* jenv, st_table* tbl, jobject f, int readonl
|
|
1298
1297
|
result = ALLOC(struct cls_field);
|
1299
1298
|
memset(result, 0, sizeof(struct cls_field));
|
1300
1299
|
nm = (*jenv)->CallObjectMethod(jenv, f, field_getName);
|
1301
|
-
|
1300
|
+
rjb_check_exception(jenv, 0);
|
1302
1301
|
jname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
|
1303
1302
|
result->name = rb_intern(jname);
|
1304
|
-
|
1303
|
+
rjb_release_string(jenv, nm, jname);
|
1305
1304
|
result->id = (*jenv)->FromReflectedField(jenv, f);
|
1306
|
-
|
1305
|
+
rjb_check_exception(jenv, 0);
|
1307
1306
|
cls = (*jenv)->CallObjectMethod(jenv, f, field_getType);
|
1308
|
-
|
1307
|
+
rjb_check_exception(jenv, 0);
|
1309
1308
|
result->value_convert = get_j2r(jenv, cls, &result->result_signature, &result->result_arraydepth, sigs, &iv, 0);
|
1310
1309
|
result->arg_convert = get_r2j(jenv, cls, NULL, NULL);
|
1311
1310
|
(*jenv)->DeleteLocalRef(jenv, cls);
|
@@ -1329,13 +1328,13 @@ static void setup_constructors(JNIEnv* jenv, struct cls_constructor*** pptr, job
|
|
1329
1328
|
jobjectArray parama;
|
1330
1329
|
jsize pcount;
|
1331
1330
|
jobject c = (*jenv)->GetObjectArrayElement(jenv, methods, i);
|
1332
|
-
|
1331
|
+
rjb_check_exception(jenv, 0);
|
1333
1332
|
pc = ALLOC(struct cls_constructor);
|
1334
1333
|
tbl[i] = pc;
|
1335
1334
|
parama = (*jenv)->CallObjectMethod(jenv, c, ctrGetParameterTypes);
|
1336
|
-
|
1335
|
+
rjb_check_exception(jenv, 0);
|
1337
1336
|
pcount = (*jenv)->GetArrayLength(jenv, parama);
|
1338
|
-
|
1337
|
+
rjb_check_exception(jenv, 0);
|
1339
1338
|
setup_methodbase(jenv, pc, parama, pcount);
|
1340
1339
|
pc->id = (*jenv)->FromReflectedMethod(jenv, c);
|
1341
1340
|
(*jenv)->DeleteLocalRef(jenv, c);
|
@@ -1354,7 +1353,7 @@ static void setup_methods(JNIEnv* jenv, st_table** tbl, st_table** static_tbl,
|
|
1354
1353
|
for (i = 0; i < mcount; i++)
|
1355
1354
|
{
|
1356
1355
|
jobject m = (*jenv)->GetObjectArrayElement(jenv, methods, i);
|
1357
|
-
|
1356
|
+
rjb_check_exception(jenv, 0);
|
1358
1357
|
modifier = (*jenv)->CallIntMethod(jenv, m, method_getModifiers);
|
1359
1358
|
if (!(modifier & ACC_STATIC))
|
1360
1359
|
{
|
@@ -1377,7 +1376,7 @@ static void setup_fields(JNIEnv* jenv, st_table** tbl, jobjectArray flds)
|
|
1377
1376
|
for (i = 0; i < fcount; i++)
|
1378
1377
|
{
|
1379
1378
|
jobject f = (*jenv)->GetObjectArrayElement(jenv, flds, i);
|
1380
|
-
|
1379
|
+
rjb_check_exception(jenv, 0);
|
1381
1380
|
modifier = (*jenv)->CallIntMethod(jenv, f, field_getModifiers);
|
1382
1381
|
create_fieldinfo(jenv, *tbl, f, modifier & ACC_FINAL, modifier & ACC_STATIC);
|
1383
1382
|
(*jenv)->DeleteLocalRef(jenv, f);
|
@@ -1392,9 +1391,9 @@ static void load_constants(JNIEnv* jenv, jclass klass, VALUE self, jobjectArray
|
|
1392
1391
|
for (i = 0; i < fcount; i++)
|
1393
1392
|
{
|
1394
1393
|
jobject f = (*jenv)->GetObjectArrayElement(jenv, flds, i);
|
1395
|
-
|
1394
|
+
rjb_check_exception(jenv, 0);
|
1396
1395
|
modifier = (*jenv)->CallIntMethod(jenv, f, field_getModifiers);
|
1397
|
-
|
1396
|
+
rjb_check_exception(jenv, 0);
|
1398
1397
|
if ((modifier & (ACC_PUBLIC | ACC_STATIC | ACC_FINAL)) == (ACC_PUBLIC | ACC_STATIC | ACC_FINAL))
|
1399
1398
|
{
|
1400
1399
|
jstring nm;
|
@@ -1410,18 +1409,18 @@ static void load_constants(JNIEnv* jenv, jclass klass, VALUE self, jobjectArray
|
|
1410
1409
|
|
1411
1410
|
// constants make define directly in the ruby object
|
1412
1411
|
cls = (*jenv)->CallObjectMethod(jenv, f, field_getType);
|
1413
|
-
|
1412
|
+
rjb_check_exception(jenv, 0);
|
1414
1413
|
iv = 0;
|
1415
1414
|
sig = depth = 0;
|
1416
1415
|
j2r = get_j2r(jenv, cls, &sig, &depth, sigs, &iv, 1);
|
1417
1416
|
if (!j2r) j2r = jv2rv;
|
1418
1417
|
(*jenv)->DeleteLocalRef(jenv, cls);
|
1419
1418
|
nm = (*jenv)->CallObjectMethod(jenv, f, field_getName);
|
1420
|
-
|
1419
|
+
rjb_check_exception(jenv, 0);
|
1421
1420
|
cname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
|
1422
|
-
|
1421
|
+
rjb_check_exception(jenv, 0);
|
1423
1422
|
jfid = (*jenv)->GetStaticFieldID(jenv, klass, cname, sigs);
|
1424
|
-
|
1423
|
+
rjb_check_exception(jenv, 0);
|
1425
1424
|
switch (sig)
|
1426
1425
|
{
|
1427
1426
|
case 'D':
|
@@ -1467,7 +1466,7 @@ static void load_constants(JNIEnv* jenv, jclass klass, VALUE self, jobjectArray
|
|
1467
1466
|
rb_define_const(RBASIC(self)->klass, cname, j2r(jenv, jv));
|
1468
1467
|
}
|
1469
1468
|
|
1470
|
-
|
1469
|
+
rjb_release_string(jenv, nm, cname);
|
1471
1470
|
}
|
1472
1471
|
(*jenv)->DeleteLocalRef(jenv, f);
|
1473
1472
|
}
|
@@ -1481,21 +1480,21 @@ static void setup_metadata(JNIEnv* jenv, VALUE self, struct jv_data* ptr, VALUE
|
|
1481
1480
|
|
1482
1481
|
jclass klass = (*jenv)->GetObjectClass(jenv, ptr->idata.obj);
|
1483
1482
|
ptr->idata.klass = (*jenv)->NewGlobalRef(jenv, klass);
|
1484
|
-
|
1483
|
+
rjb_check_exception(jenv, 0);
|
1485
1484
|
mid = (*jenv)->GetMethodID(jenv, klass, "getMethods", "()[Ljava/lang/reflect/Method;");
|
1486
|
-
|
1485
|
+
rjb_check_exception(jenv, 0);
|
1487
1486
|
methods = (*jenv)->CallNonvirtualObjectMethod(jenv, ptr->idata.obj, klass, mid);
|
1488
|
-
|
1487
|
+
rjb_check_exception(jenv, 0);
|
1489
1488
|
setup_methods(jenv, &ptr->idata.methods, &ptr->static_methods, methods);
|
1490
1489
|
mid = (*jenv)->GetMethodID(jenv, klass, "getConstructors", "()[Ljava/lang/reflect/Constructor;");
|
1491
|
-
|
1490
|
+
rjb_check_exception(jenv, 0);
|
1492
1491
|
methods = (*jenv)->CallNonvirtualObjectMethod(jenv, ptr->idata.obj, klass, mid);
|
1493
|
-
|
1492
|
+
rjb_check_exception(jenv, 0);
|
1494
1493
|
setup_constructors(jenv, &ptr->constructors, methods);
|
1495
1494
|
mid = (*jenv)->GetMethodID(jenv, klass, "getFields", "()[Ljava/lang/reflect/Field;");
|
1496
|
-
|
1495
|
+
rjb_check_exception(jenv, 0);
|
1497
1496
|
flds = (*jenv)->CallNonvirtualObjectMethod(jenv, ptr->idata.obj, klass, mid);
|
1498
|
-
|
1497
|
+
rjb_check_exception(jenv, 0);
|
1499
1498
|
setup_fields(jenv, &ptr->idata.fields, flds);
|
1500
1499
|
|
1501
1500
|
register_class(self, classname);
|
@@ -1525,7 +1524,7 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
|
|
1525
1524
|
jclass jfield;
|
1526
1525
|
jclass jconstructor;
|
1527
1526
|
|
1528
|
-
if (
|
1527
|
+
if (rjb_jvm)
|
1529
1528
|
{
|
1530
1529
|
return Qnil;
|
1531
1530
|
}
|
@@ -1547,56 +1546,56 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
|
|
1547
1546
|
Check_Type(vm_argv, T_ARRAY);
|
1548
1547
|
}
|
1549
1548
|
jenv = NULL;
|
1550
|
-
res =
|
1549
|
+
res = rjb_create_jvm(&jenv, &vm_args, userpath, vm_argv);
|
1551
1550
|
if (res < 0)
|
1552
1551
|
{
|
1553
|
-
|
1552
|
+
rjb_jvm = NULL;
|
1554
1553
|
rb_raise(rb_eRuntimeError, "can't create Java VM");
|
1555
1554
|
} else {
|
1556
1555
|
main_jenv = jenv;
|
1557
1556
|
}
|
1558
1557
|
|
1559
1558
|
jconstructor = (*jenv)->FindClass(jenv, "java/lang/reflect/Constructor");
|
1560
|
-
|
1559
|
+
rjb_check_exception(jenv, 1);
|
1561
1560
|
ctrGetParameterTypes = (*jenv)->GetMethodID(jenv, jconstructor, "getParameterTypes", "()[Ljava/lang/Class;");
|
1562
|
-
|
1561
|
+
rjb_check_exception(jenv, 1);
|
1563
1562
|
jmethod = (*jenv)->FindClass(jenv, "java/lang/reflect/Method");
|
1564
1563
|
method_getModifiers = (*jenv)->GetMethodID(jenv, jmethod, "getModifiers", "()I");
|
1565
|
-
|
1564
|
+
rjb_check_exception(jenv, 1);
|
1566
1565
|
method_getName = (*jenv)->GetMethodID(jenv, jmethod, "getName", "()Ljava/lang/String;");
|
1567
|
-
|
1566
|
+
rjb_check_exception(jenv, 1);
|
1568
1567
|
getParameterTypes = (*jenv)->GetMethodID(jenv, jmethod, "getParameterTypes", "()[Ljava/lang/Class;");
|
1569
|
-
|
1568
|
+
rjb_check_exception(jenv, 1);
|
1570
1569
|
getReturnType = (*jenv)->GetMethodID(jenv, jmethod, "getReturnType", "()Ljava/lang/Class;");
|
1571
|
-
|
1570
|
+
rjb_check_exception(jenv, 1);
|
1572
1571
|
|
1573
1572
|
jfield = (*jenv)->FindClass(jenv, "java/lang/reflect/Field");
|
1574
1573
|
field_getModifiers = (*jenv)->GetMethodID(jenv, jfield, "getModifiers", "()I");
|
1575
|
-
|
1574
|
+
rjb_check_exception(jenv, 1);
|
1576
1575
|
field_getName = (*jenv)->GetMethodID(jenv, jfield, "getName", "()Ljava/lang/String;");
|
1577
|
-
|
1576
|
+
rjb_check_exception(jenv, 1);
|
1578
1577
|
field_getType = (*jenv)->GetMethodID(jenv, jfield, "getType", "()Ljava/lang/Class;");
|
1579
|
-
|
1578
|
+
rjb_check_exception(jenv, 1);
|
1580
1579
|
|
1581
1580
|
j_class = (*jenv)->FindClass(jenv, "java/lang/Class");
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1581
|
+
rjb_check_exception(jenv, 1);
|
1582
|
+
rjb_class_getName = (*jenv)->GetMethodID(jenv, j_class, "getName", "()Ljava/lang/String;");
|
1583
|
+
rjb_check_exception(jenv, 1);
|
1585
1584
|
j_class = (*jenv)->NewGlobalRef(jenv, j_class);
|
1586
1585
|
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1586
|
+
rjb_j_throwable = (*jenv)->FindClass(jenv, "java/lang/Throwable");
|
1587
|
+
rjb_check_exception(jenv, 1);
|
1588
|
+
rjb_throwable_getMessage = (*jenv)->GetMethodID(jenv, rjb_j_throwable, "getMessage", "()Ljava/lang/String;");
|
1589
|
+
rjb_check_exception(jenv, 1);
|
1591
1590
|
|
1592
1591
|
j_string = (*jenv)->FindClass(jenv, "java/lang/String");
|
1593
|
-
|
1592
|
+
rjb_check_exception(jenv, 1);
|
1594
1593
|
str_tostring = (*jenv)->GetMethodID(jenv, j_string, "toString", "()Ljava/lang/String;");
|
1595
|
-
|
1594
|
+
rjb_check_exception(jenv, 1);
|
1596
1595
|
j_string = (*jenv)->NewGlobalRef(jenv, j_string);
|
1597
1596
|
|
1598
1597
|
j_object = (*jenv)->FindClass(jenv, "java/lang/Object");
|
1599
|
-
|
1598
|
+
rjb_check_exception(jenv, 1);
|
1600
1599
|
j_object = (*jenv)->NewGlobalRef(jenv, j_object);
|
1601
1600
|
|
1602
1601
|
for (i = PRM_INT; i < PRM_LAST; i++)
|
@@ -1606,17 +1605,17 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
|
|
1606
1605
|
{
|
1607
1606
|
jpcvt[i].ctr_id = (*jenv)->GetStaticMethodID(jenv,
|
1608
1607
|
klass, "valueOf", jpcvt[i].ctrsig);
|
1609
|
-
|
1608
|
+
rjb_check_exception(jenv, 1);
|
1610
1609
|
}
|
1611
1610
|
else if (jpcvt[i].ctrsig)
|
1612
1611
|
{
|
1613
1612
|
jpcvt[i].ctr_id = (*jenv)->GetMethodID(jenv, klass,
|
1614
1613
|
"<init>", jpcvt[i].ctrsig);
|
1615
|
-
|
1614
|
+
rjb_check_exception(jenv, 1);
|
1616
1615
|
}
|
1617
1616
|
jpcvt[i].to_prim_id = (*jenv)->GetMethodID(jenv, klass,
|
1618
1617
|
jpcvt[i].to_prim_method, jpcvt[i].prmsig);
|
1619
|
-
|
1618
|
+
rjb_check_exception(jenv, 1);
|
1620
1619
|
jpcvt[i].klass = (*jenv)->NewGlobalRef(jenv, klass);
|
1621
1620
|
}
|
1622
1621
|
|
@@ -1641,11 +1640,11 @@ static int clear_classes(VALUE key, VALUE val, VALUE dummy)
|
|
1641
1640
|
}
|
1642
1641
|
static VALUE rjb_s_unload(int argc, VALUE* argv, VALUE self)
|
1643
1642
|
{
|
1644
|
-
st_foreach(RHASH(
|
1645
|
-
if (
|
1643
|
+
st_foreach(RHASH(rjb_loaded_classes)->tbl, clear_classes, 0);
|
1644
|
+
if (rjb_jvm)
|
1646
1645
|
{
|
1647
|
-
(*
|
1648
|
-
|
1646
|
+
(*rjb_jvm)->DestroyJavaVM(rjb_jvm);
|
1647
|
+
rjb_jvm = NULL;
|
1649
1648
|
}
|
1650
1649
|
return Qnil;
|
1651
1650
|
}
|
@@ -1657,7 +1656,7 @@ static VALUE rjb_s_unload(int argc, VALUE* argv, VALUE self)
|
|
1657
1656
|
*/
|
1658
1657
|
static VALUE rjb_s_classes(VALUE self)
|
1659
1658
|
{
|
1660
|
-
return
|
1659
|
+
return rjb_loaded_classes;
|
1661
1660
|
}
|
1662
1661
|
|
1663
1662
|
/*
|
@@ -1682,7 +1681,7 @@ static int free_method_item(ID key, struct cls_method* pm, int dummy)
|
|
1682
1681
|
*/
|
1683
1682
|
static VALUE rjb_delete_ref(struct jvi_data* ptr)
|
1684
1683
|
{
|
1685
|
-
JNIEnv* jenv =
|
1684
|
+
JNIEnv* jenv = rjb_attach_current_thread();
|
1686
1685
|
if (jenv)
|
1687
1686
|
{
|
1688
1687
|
(*jenv)->DeleteGlobalRef(jenv, ptr->obj);
|
@@ -1695,7 +1694,7 @@ static VALUE rjb_delete_ref(struct jvi_data* ptr)
|
|
1695
1694
|
*/
|
1696
1695
|
static VALUE rj_bridge_free(struct rj_bridge* ptr)
|
1697
1696
|
{
|
1698
|
-
JNIEnv* jenv =
|
1697
|
+
JNIEnv* jenv = rjb_attach_current_thread();
|
1699
1698
|
(*jenv)->DeleteLocalRef(jenv, ptr->proxy);
|
1700
1699
|
(*jenv)->DeleteLocalRef(jenv, ptr->bridge);
|
1701
1700
|
return Qnil;
|
@@ -1715,7 +1714,7 @@ static void rj_bridge_mark(struct rj_bridge* ptr)
|
|
1715
1714
|
static VALUE rjb_s_free(struct jv_data* ptr)
|
1716
1715
|
{
|
1717
1716
|
/* class never delete
|
1718
|
-
JNIEnv* jenv =
|
1717
|
+
JNIEnv* jenv = rjb_attach_current_thread();
|
1719
1718
|
struct cls_constructor** c;
|
1720
1719
|
|
1721
1720
|
rjb_delete_ref(&ptr->idata);
|
@@ -1733,7 +1732,7 @@ static VALUE rjb_s_free(struct jv_data* ptr)
|
|
1733
1732
|
st_free_table(ptr->idata.methods);
|
1734
1733
|
}
|
1735
1734
|
(*jenv)->DeleteGlobalRef(jenv, ptr->idata.klass);
|
1736
|
-
st_delete(RHASH(
|
1735
|
+
st_delete(RHASH(rjb_loaded_classes)->tbl, clsname, NULL);
|
1737
1736
|
*/
|
1738
1737
|
return Qnil;
|
1739
1738
|
}
|
@@ -1759,7 +1758,7 @@ static VALUE createinstance(JNIEnv* jenv, int argc, VALUE* argv,
|
|
1759
1758
|
obj = (*jenv)->NewObjectA(jenv, org->obj, pc->id, args);
|
1760
1759
|
if (!obj)
|
1761
1760
|
{
|
1762
|
-
|
1761
|
+
rjb_check_exception(jenv, 1);
|
1763
1762
|
}
|
1764
1763
|
psig = pc->method_signature;
|
1765
1764
|
for (i = 0; i < argc; i++)
|
@@ -1885,7 +1884,7 @@ static VALUE rjb_newinstance_s(int argc, VALUE* argv, VALUE self)
|
|
1885
1884
|
char* sig;
|
1886
1885
|
VALUE ret = Qnil;
|
1887
1886
|
struct jv_data* ptr;
|
1888
|
-
JNIEnv* jenv =
|
1887
|
+
JNIEnv* jenv = rjb_attach_current_thread();
|
1889
1888
|
|
1890
1889
|
rb_scan_args(argc, argv, "1*", &vsig, &rest);
|
1891
1890
|
sig = StringValueCStr(vsig);
|
@@ -1911,7 +1910,7 @@ static VALUE rjb_newinstance(int argc, VALUE* argv, VALUE self)
|
|
1911
1910
|
VALUE ret = Qnil;
|
1912
1911
|
struct jv_data* ptr;
|
1913
1912
|
struct cls_constructor** pc;
|
1914
|
-
JNIEnv* jenv =
|
1913
|
+
JNIEnv* jenv = rjb_attach_current_thread();
|
1915
1914
|
|
1916
1915
|
Data_Get_Struct(self, struct jv_data, ptr);
|
1917
1916
|
|
@@ -1948,7 +1947,7 @@ static VALUE rjb_newinstance(int argc, VALUE* argv, VALUE self)
|
|
1948
1947
|
/*
|
1949
1948
|
* find java class from classname
|
1950
1949
|
*/
|
1951
|
-
jclass
|
1950
|
+
jclass rjb_find_class(JNIEnv* jenv, VALUE name)
|
1952
1951
|
{
|
1953
1952
|
char* cname;
|
1954
1953
|
char* jnicls;
|
@@ -1965,24 +1964,24 @@ jclass find_class(JNIEnv* jenv, VALUE name)
|
|
1965
1964
|
static VALUE rjb_s_bind(VALUE self, VALUE rbobj, VALUE itfname)
|
1966
1965
|
{
|
1967
1966
|
VALUE result = Qnil;
|
1968
|
-
JNIEnv* jenv =
|
1967
|
+
JNIEnv* jenv = rjb_attach_current_thread();
|
1969
1968
|
|
1970
|
-
jclass itf =
|
1971
|
-
|
1969
|
+
jclass itf = rjb_find_class(jenv, itfname);
|
1970
|
+
rjb_check_exception(jenv, 1);
|
1972
1971
|
if (itf)
|
1973
1972
|
{
|
1974
1973
|
struct rj_bridge* ptr = ALLOC(struct rj_bridge);
|
1975
1974
|
memset(ptr, 0, sizeof(struct rj_bridge));
|
1976
1975
|
ptr->bridge = (*jenv)->NewGlobalRef(jenv,
|
1977
|
-
(*jenv)->AllocObject(jenv,
|
1976
|
+
(*jenv)->AllocObject(jenv, rjb_rbridge));
|
1978
1977
|
if (!ptr->bridge)
|
1979
1978
|
{
|
1980
1979
|
free(ptr);
|
1981
|
-
|
1980
|
+
rjb_check_exception(jenv, 1);
|
1982
1981
|
return Qnil;
|
1983
1982
|
}
|
1984
1983
|
ptr->proxy = (*jenv)->CallObjectMethod(jenv, ptr->bridge,
|
1985
|
-
|
1984
|
+
rjb_register_bridge, itf);
|
1986
1985
|
ptr->proxy = (*jenv)->NewGlobalRef(jenv, ptr->proxy);
|
1987
1986
|
ptr->wrapped = rbobj;
|
1988
1987
|
result = Data_Wrap_Struct(rjbb, rj_bridge_mark, rj_bridge_free, ptr);
|
@@ -1998,22 +1997,22 @@ static VALUE rjb_s_import(VALUE self, VALUE clsname)
|
|
1998
1997
|
{
|
1999
1998
|
JNIEnv* jenv;
|
2000
1999
|
jclass jcls;
|
2001
|
-
VALUE v = rb_hash_aref(
|
2000
|
+
VALUE v = rb_hash_aref(rjb_loaded_classes, clsname);
|
2002
2001
|
if (v != Qnil)
|
2003
2002
|
{
|
2004
2003
|
return v;
|
2005
2004
|
}
|
2006
2005
|
|
2007
|
-
if (!
|
2006
|
+
if (!rjb_jvm)
|
2008
2007
|
{
|
2009
2008
|
/* auto-load with default setting */
|
2010
2009
|
rjb_s_load(0, NULL, 0);
|
2011
2010
|
}
|
2012
|
-
jenv =
|
2013
|
-
jcls =
|
2011
|
+
jenv = rjb_attach_current_thread();
|
2012
|
+
jcls = rjb_find_class(jenv, clsname);
|
2014
2013
|
if (!jcls)
|
2015
2014
|
{
|
2016
|
-
|
2015
|
+
rjb_check_exception(jenv, 0);
|
2017
2016
|
rb_raise(rb_eRuntimeError, "`%s' not found", StringValueCStr(clsname));
|
2018
2017
|
}
|
2019
2018
|
v = import_class(jenv, jcls, clsname);
|
@@ -2027,7 +2026,7 @@ static void register_class(VALUE self, VALUE clsname)
|
|
2027
2026
|
/*
|
2028
2027
|
* the hash was frozen, so it need to call st_ func directly.
|
2029
2028
|
*/
|
2030
|
-
st_insert(RHASH(
|
2029
|
+
st_insert(RHASH(rjb_loaded_classes)->tbl, clsname, self);
|
2031
2030
|
}
|
2032
2031
|
|
2033
2032
|
/*
|
@@ -2035,12 +2034,12 @@ static void register_class(VALUE self, VALUE clsname)
|
|
2035
2034
|
*/
|
2036
2035
|
static VALUE rjb_i_class(VALUE self)
|
2037
2036
|
{
|
2038
|
-
JNIEnv* jenv =
|
2037
|
+
JNIEnv* jenv = rjb_attach_current_thread();
|
2039
2038
|
struct jvi_data* ptr;
|
2040
2039
|
jstring nm;
|
2041
2040
|
Data_Get_Struct(self, struct jvi_data, ptr);
|
2042
|
-
nm = (*jenv)->CallObjectMethod(jenv, ptr->klass,
|
2043
|
-
|
2041
|
+
nm = (*jenv)->CallObjectMethod(jenv, ptr->klass, rjb_class_getName);
|
2042
|
+
rjb_check_exception(jenv, 0);
|
2044
2043
|
return jstring2val(jenv, nm);
|
2045
2044
|
}
|
2046
2045
|
|
@@ -2354,7 +2353,7 @@ static VALUE invoke(JNIEnv* jenv, struct cls_method* pm, struct jvi_data* ptr,
|
|
2354
2353
|
}
|
2355
2354
|
break;
|
2356
2355
|
}
|
2357
|
-
|
2356
|
+
rjb_check_exception(jenv, 1);
|
2358
2357
|
psig = pm->basic.method_signature;
|
2359
2358
|
for (i = 0; i < argc; i++)
|
2360
2359
|
{
|
@@ -2379,7 +2378,7 @@ static VALUE invoke_by_instance(ID rmid, int argc, VALUE* argv,
|
|
2379
2378
|
struct jvi_data* ptr, char* sig)
|
2380
2379
|
{
|
2381
2380
|
VALUE ret = Qnil;
|
2382
|
-
JNIEnv* jenv =
|
2381
|
+
JNIEnv* jenv = rjb_attach_current_thread();
|
2383
2382
|
struct cls_field* pf;
|
2384
2383
|
struct cls_method* pm;
|
2385
2384
|
char* tname = rb_id2name(rmid);
|
@@ -2448,7 +2447,7 @@ static VALUE invoke_by_class(ID rmid, int argc, VALUE* argv,
|
|
2448
2447
|
struct cls_field* pf;
|
2449
2448
|
struct cls_method* pm;
|
2450
2449
|
char* tname = rb_id2name(rmid);
|
2451
|
-
JNIEnv* jenv =
|
2450
|
+
JNIEnv* jenv = rjb_attach_current_thread();
|
2452
2451
|
|
2453
2452
|
Data_Get_Struct(jklass, struct jv_data, clsptr);
|
2454
2453
|
if (argc == 0 && st_lookup(ptr->idata.fields, rmid, (st_data_t*)&pf))
|
@@ -2567,9 +2566,9 @@ void Init_rjbcore()
|
|
2567
2566
|
{
|
2568
2567
|
rb_protect((VALUE(*)(VALUE))rb_require, (VALUE)"iconv", NULL);
|
2569
2568
|
|
2570
|
-
|
2571
|
-
OBJ_FREEZE(
|
2572
|
-
rb_global_variable(&
|
2569
|
+
rjb_loaded_classes = rb_hash_new();
|
2570
|
+
OBJ_FREEZE(rjb_loaded_classes);
|
2571
|
+
rb_global_variable(&rjb_loaded_classes);
|
2573
2572
|
proxies = rb_ary_new();
|
2574
2573
|
rb_global_variable(&proxies);
|
2575
2574
|
|
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
|
15
|
+
* $Id: rjb.h 8 2006-11-20 19:17:22Z arton $
|
16
16
|
* $Log: rjb.h,v $
|
17
17
|
* Revision 1.1 2005/01/16 17:36:10 arton
|
18
18
|
* Initial revision
|
@@ -34,18 +34,24 @@
|
|
34
34
|
#define _I64_MAX 9223372036854775807i64
|
35
35
|
#endif
|
36
36
|
|
37
|
+
/* in load.c */
|
38
|
+
extern int rjb_create_jvm(JNIEnv** pjenv, JavaVMInitArgs*, char*, VALUE);
|
39
|
+
|
37
40
|
/* in rjb.c */
|
38
|
-
extern
|
39
|
-
extern
|
40
|
-
extern
|
41
|
-
extern
|
42
|
-
extern
|
43
|
-
extern jclass
|
44
|
-
extern
|
41
|
+
extern JavaVM* rjb_jvm;
|
42
|
+
extern jclass rjb_rbridge;
|
43
|
+
extern jmethodID rjb_register_bridge;
|
44
|
+
extern VALUE rjb_loaded_classes;
|
45
|
+
extern jmethodID rjb_class_getName;
|
46
|
+
extern jclass rjb_j_throwable;
|
47
|
+
extern jmethodID rjb_throwable_getMessage;
|
48
|
+
extern JNIEnv* rjb_attach_current_thread(void);
|
49
|
+
extern jclass rjb_find_class(JNIEnv* jenv, VALUE name);
|
50
|
+
extern void rjb_release_string(JNIEnv *jenv, jstring str, const char* chrs);
|
45
51
|
|
46
52
|
/* in rjbexception.c */
|
47
|
-
extern VALUE
|
48
|
-
extern void
|
53
|
+
extern VALUE rjb_get_exception_class(JNIEnv* jenv, jstring str);
|
54
|
+
extern void rjb_check_exception(JNIEnv* jenv, int t);
|
49
55
|
extern VALUE rjb_s_throw(int, VALUE*, VALUE);
|
50
56
|
|
51
57
|
/* conversion functions */
|
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
|
15
|
+
* $Id: rjbexception.c 8 2006-11-20 19:17:22Z arton $
|
16
16
|
*/
|
17
17
|
|
18
18
|
#include "ruby.h"
|
@@ -26,7 +26,7 @@
|
|
26
26
|
* At this time, the Java exception is defined without the package name.
|
27
27
|
* This design may change in future release.
|
28
28
|
*/
|
29
|
-
VALUE
|
29
|
+
VALUE rjb_get_exception_class(JNIEnv* jenv, jstring str)
|
30
30
|
{
|
31
31
|
VALUE rexp;
|
32
32
|
char* pcls;
|
@@ -34,7 +34,7 @@ VALUE get_exception_class(JNIEnv* jenv, jstring str)
|
|
34
34
|
const char* p = (*jenv)->GetStringUTFChars(jenv, str, JNI_FALSE);
|
35
35
|
char* clsname = ALLOCA_N(char, strlen(p) + 1);
|
36
36
|
strcpy(clsname, p);
|
37
|
-
|
37
|
+
rjb_release_string(jenv, str, p);
|
38
38
|
pcls = strrchr(clsname, '.');
|
39
39
|
if (pcls)
|
40
40
|
{
|
@@ -45,11 +45,11 @@ VALUE get_exception_class(JNIEnv* jenv, jstring str)
|
|
45
45
|
pcls = clsname;
|
46
46
|
}
|
47
47
|
cname = rb_str_new2(pcls);
|
48
|
-
rexp = rb_hash_aref(
|
48
|
+
rexp = rb_hash_aref(rjb_loaded_classes, cname);
|
49
49
|
if (rexp == Qnil)
|
50
50
|
{
|
51
51
|
rexp = rb_define_class(pcls, rb_eStandardError);
|
52
|
-
st_insert(RHASH(
|
52
|
+
st_insert(RHASH(rjb_loaded_classes)->tbl, cname, rexp);
|
53
53
|
}
|
54
54
|
return rexp;
|
55
55
|
}
|
@@ -61,10 +61,10 @@ VALUE rjb_s_throw(int argc, VALUE* argv, VALUE self)
|
|
61
61
|
{
|
62
62
|
VALUE klass;
|
63
63
|
VALUE message;
|
64
|
-
JNIEnv* jenv =
|
64
|
+
JNIEnv* jenv = rjb_attach_current_thread();
|
65
65
|
if (rb_scan_args(argc, argv, "11", &klass, &message) == 2)
|
66
66
|
{
|
67
|
-
jclass excep =
|
67
|
+
jclass excep = rjb_find_class(jenv, klass);
|
68
68
|
if (excep == NULL)
|
69
69
|
{
|
70
70
|
rb_raise(rb_eRuntimeError, "`%s' not found", StringValueCStr(klass));
|
@@ -75,7 +75,7 @@ VALUE rjb_s_throw(int argc, VALUE* argv, VALUE self)
|
|
75
75
|
{
|
76
76
|
struct jvi_data* ptr;
|
77
77
|
Data_Get_Struct(klass, struct jvi_data, ptr);
|
78
|
-
if (!(*jenv)->IsInstanceOf(jenv, ptr->obj,
|
78
|
+
if (!(*jenv)->IsInstanceOf(jenv, ptr->obj, rjb_j_throwable))
|
79
79
|
{
|
80
80
|
rb_raise(rb_eRuntimeError, "arg1 must be a throwable");
|
81
81
|
}
|
@@ -87,7 +87,7 @@ VALUE rjb_s_throw(int argc, VALUE* argv, VALUE self)
|
|
87
87
|
return Qnil;
|
88
88
|
}
|
89
89
|
|
90
|
-
void
|
90
|
+
void rjb_check_exception(JNIEnv* jenv, int t)
|
91
91
|
{
|
92
92
|
jthrowable exp = (*jenv)->ExceptionOccurred(jenv);
|
93
93
|
if (exp)
|
@@ -103,18 +103,18 @@ void check_exception(JNIEnv* jenv, int t)
|
|
103
103
|
{
|
104
104
|
char* msg = "unknown exception";
|
105
105
|
jclass cls = (*jenv)->GetObjectClass(jenv, exp);
|
106
|
-
jstring str = (*jenv)->CallObjectMethod(jenv, exp,
|
106
|
+
jstring str = (*jenv)->CallObjectMethod(jenv, exp, rjb_throwable_getMessage);
|
107
107
|
if (str)
|
108
108
|
{
|
109
109
|
const char* p = (*jenv)->GetStringUTFChars(jenv, str, JNI_FALSE);
|
110
110
|
msg = ALLOCA_N(char, strlen(p) + 1);
|
111
111
|
strcpy(msg, p);
|
112
|
-
|
112
|
+
rjb_release_string(jenv, str, p);
|
113
113
|
}
|
114
|
-
str = (*jenv)->CallObjectMethod(jenv, cls,
|
114
|
+
str = (*jenv)->CallObjectMethod(jenv, cls, rjb_class_getName);
|
115
115
|
if (str)
|
116
116
|
{
|
117
|
-
rexp =
|
117
|
+
rexp = rjb_get_exception_class(jenv, str);
|
118
118
|
}
|
119
119
|
if (rexp == Qnil)
|
120
120
|
{
|
data/lib/rjbcore.so
CHANGED
Binary file
|
metadata
CHANGED