rjb 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +26 -0
- data/ext/extconf.h +1 -1
- data/ext/extconf.rb +1 -0
- data/ext/jniwrap.h +1 -1
- data/ext/load.c +25 -9
- data/ext/rjb.c +76 -77
- data/ext/rjbexception.c +1 -2
- data/test/test.rb +13 -3
- metadata +41 -48
data/ChangeLog
CHANGED
@@ -1,3 +1,29 @@
|
|
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.
|
1
27
|
Tue Mar 5 Kuwashima
|
2
28
|
*ext/rjb.c
|
3
29
|
*ext/rjb.h
|
data/ext/extconf.h
CHANGED
data/ext/extconf.rb
CHANGED
@@ -33,6 +33,7 @@ if !javahome.nil?
|
|
33
33
|
raise "JAVA_HOME is not directory." unless File.directory?(javahome)
|
34
34
|
p = Path.new
|
35
35
|
inc = p.include(javahome, 'include')
|
36
|
+
inc = p.include(javahome, 'Home/include') unless File.exists?(inc)
|
36
37
|
Dir.open(inc).each do |d|
|
37
38
|
next if d[0] == ?.
|
38
39
|
if File.directory?(p.joint(inc, d))
|
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
|
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
|
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,13 +90,23 @@ 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
|
{
|
@@ -136,7 +153,7 @@ static int load_jvm(char* jvmtype)
|
|
136
153
|
|
137
154
|
jvmdll = rb_funcall(rb_const_get(rb_cObject, rb_intern("DL")), rb_intern("dlopen"), 1, rb_str_new2(libpath));
|
138
155
|
|
139
|
-
|
156
|
+
/* get function pointers of JNI */
|
140
157
|
#if RJB_RUBY_VERSION_CODE < 190
|
141
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);
|
142
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);
|
@@ -211,7 +228,6 @@ int rjb_create_jvm(JNIEnv** pjenv, JavaVMInitArgs* vm_args, char* userpath, VALU
|
|
211
228
|
{ "DUMMY", NULL }, /* for classpath count */
|
212
229
|
};
|
213
230
|
char* newpath;
|
214
|
-
VALUE ptr;
|
215
231
|
int len;
|
216
232
|
int result;
|
217
233
|
GETDEFAULTJAVAVMINITARGS initargs;
|
@@ -223,7 +239,7 @@ int rjb_create_jvm(JNIEnv** pjenv, JavaVMInitArgs* vm_args, char* userpath, VALU
|
|
223
239
|
|
224
240
|
if (!RTEST(jvmdll))
|
225
241
|
{
|
226
|
-
if (!load_jvm(JVM_TYPE))
|
242
|
+
if (!load_jvm(JVM_TYPE) && !load_jvm(ALT_JVM_TYPE))
|
227
243
|
{
|
228
244
|
return -1;
|
229
245
|
}
|
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
|
15
|
+
* $Id: rjb.c 77 2008-08-14 10:22:35Z arton $
|
16
16
|
*/
|
17
17
|
|
18
|
-
#define RJB_VERSION "1.1.
|
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
|
|
@@ -145,6 +160,7 @@ static char* java2jniname(char* jnicls)
|
|
145
160
|
return jnicls;
|
146
161
|
}
|
147
162
|
|
163
|
+
#if 0
|
148
164
|
static char* jni2javaname(char* jnicls)
|
149
165
|
{
|
150
166
|
char* p;
|
@@ -157,6 +173,7 @@ static char* jni2javaname(char* jnicls)
|
|
157
173
|
}
|
158
174
|
return jnicls;
|
159
175
|
}
|
176
|
+
#endif
|
160
177
|
|
161
178
|
static char* next_sig(char* p)
|
162
179
|
{
|
@@ -239,7 +256,7 @@ static VALUE jv2rv_r(JNIEnv* jenv, jvalue val)
|
|
239
256
|
VALUE clsname;
|
240
257
|
VALUE v;
|
241
258
|
struct jv_data* ptr;
|
242
|
-
|
259
|
+
/* object to ruby */
|
243
260
|
if (!val.l) return Qnil;
|
244
261
|
klass = (*jenv)->GetObjectClass(jenv, val.l);
|
245
262
|
|
@@ -517,7 +534,7 @@ static jprimitive_table jpcvt[] = {
|
|
517
534
|
{ "java/lang/Double", "doubleValue", "()D", "(D)V", NULL, 0, 0, jdouble2rv, },
|
518
535
|
{ "java/lang/Boolean", "booleanValue", "()Z", "(Z)Ljava/lang/Boolean;",
|
519
536
|
NULL, 0, 0, jboolean2rv, },
|
520
|
-
{ "java/lang/Character", "charValue", "()C", NULL, NULL, 0, 0,
|
537
|
+
{ "java/lang/Character", "charValue", "()C", NULL, NULL, 0, 0, jchar2rv, },
|
521
538
|
{ "java/lang/Short", "intValue", "()I", NULL, NULL, 0, 0, jint2rv, },
|
522
539
|
{ "java/lang/Byte", "intValue", "()I", NULL, NULL, 0, 0, jint2rv, },
|
523
540
|
{ "java/lang/Float", "doubleValue", "()D", NULL, NULL, 0, 0, jdouble2rv, },
|
@@ -701,7 +718,7 @@ static void rv2jstring(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
|
|
701
718
|
Data_Get_Struct(val, struct jvi_data, ptr);
|
702
719
|
if ((*jenv)->IsInstanceOf(jenv, ptr->obj, j_string))
|
703
720
|
{
|
704
|
-
return;
|
721
|
+
return; /* never delete at this time */
|
705
722
|
}
|
706
723
|
}
|
707
724
|
}
|
@@ -725,7 +742,7 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
|
|
725
742
|
}
|
726
743
|
else if (NIL_P(val))
|
727
744
|
{
|
728
|
-
|
745
|
+
/* no-op */
|
729
746
|
}
|
730
747
|
else if (FIXNUM_P(val))
|
731
748
|
{
|
@@ -751,7 +768,7 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
|
|
751
768
|
case T_DATA:
|
752
769
|
if (RBASIC(val)->klass == rjbi || RBASIC(val)->klass == rjb)
|
753
770
|
{
|
754
|
-
|
771
|
+
/* TODO: check instanceof (class (in psig) ) */
|
755
772
|
struct jvi_data* ptr;
|
756
773
|
Data_Get_Struct(val, struct jvi_data, ptr);
|
757
774
|
jv->l = ptr->obj;
|
@@ -812,7 +829,7 @@ static void check_fixnumarray(VALUE v)
|
|
812
829
|
int i;
|
813
830
|
int len = RARRAY_LEN(v);
|
814
831
|
VALUE* p = RARRAY_PTR(v);
|
815
|
-
|
832
|
+
/* check all fixnum (overflow is permit) */
|
816
833
|
for (i = 0; i < len; i++)
|
817
834
|
{
|
818
835
|
if (!FIXNUM_P(*p++))
|
@@ -829,7 +846,7 @@ static jarray r2barray(JNIEnv* jenv, VALUE v, const char* cls)
|
|
829
846
|
{
|
830
847
|
ary = (*jenv)->NewByteArray(jenv, RSTRING_LEN(v));
|
831
848
|
(*jenv)->SetByteArrayRegion(jenv, ary, 0, RSTRING_LEN(v),
|
832
|
-
RSTRING_PTR(v));
|
849
|
+
(const jbyte*)RSTRING_PTR(v));
|
833
850
|
}
|
834
851
|
else if (TYPE(v) == T_ARRAY)
|
835
852
|
{
|
@@ -1079,7 +1096,7 @@ static void rv2jarray(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int
|
|
1079
1096
|
jarray ja = NULL;
|
1080
1097
|
if (NIL_P(val))
|
1081
1098
|
{
|
1082
|
-
|
1099
|
+
/* no-op, null for an array */
|
1083
1100
|
}
|
1084
1101
|
else if (*(psig + 1) == '[')
|
1085
1102
|
{
|
@@ -1178,7 +1195,7 @@ static J2R get_arrayconv(const char* cname, char* pdepth)
|
|
1178
1195
|
return jcvt[i].ja2r;
|
1179
1196
|
}
|
1180
1197
|
}
|
1181
|
-
return jarray2rv;
|
1198
|
+
return &jarray2rv;
|
1182
1199
|
}
|
1183
1200
|
|
1184
1201
|
static J2R get_j2r(JNIEnv* jenv, jobject cls, char* psig, char* pdepth, char* ppsig, off_t* piv, int static_method)
|
@@ -1333,7 +1350,6 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
|
|
1333
1350
|
{
|
1334
1351
|
struct cls_method* result;
|
1335
1352
|
struct cls_method* pm;
|
1336
|
-
char* param = NULL;
|
1337
1353
|
const char* jname;
|
1338
1354
|
jstring nm;
|
1339
1355
|
jobjectArray parama;
|
@@ -1362,7 +1378,7 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
|
|
1362
1378
|
(*jenv)->DeleteLocalRef(jenv, cls);
|
1363
1379
|
result->static_method = static_method;
|
1364
1380
|
register_methodinfo(result, tbl);
|
1365
|
-
|
1381
|
+
/* create method alias */
|
1366
1382
|
pm = NULL;
|
1367
1383
|
if (strlen(rname) > 3
|
1368
1384
|
&& (*rname == 'g' || *rname == 's') && *(rname + 1) == 'e' && *(rname + 2) == 't')
|
@@ -1409,7 +1425,6 @@ static void create_fieldinfo(JNIEnv* jenv, st_table* tbl, jobject f, int readonl
|
|
1409
1425
|
jobject cls;
|
1410
1426
|
char sigs[256];
|
1411
1427
|
off_t iv = 0;
|
1412
|
-
char sig = 0;
|
1413
1428
|
|
1414
1429
|
result = ALLOC(struct cls_field);
|
1415
1430
|
memset(result, 0, sizeof(struct cls_field));
|
@@ -1525,7 +1540,7 @@ static void load_constants(JNIEnv* jenv, jclass klass, VALUE self, jobjectArray
|
|
1525
1540
|
char sigs[256];
|
1526
1541
|
char* pname;
|
1527
1542
|
|
1528
|
-
|
1543
|
+
/* constants make define directly in the ruby object */
|
1529
1544
|
cls = (*jenv)->CallObjectMethod(jenv, f, field_getType);
|
1530
1545
|
rjb_check_exception(jenv, 0);
|
1531
1546
|
iv = 0;
|
@@ -1673,67 +1688,44 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
|
|
1673
1688
|
main_jenv = jenv;
|
1674
1689
|
}
|
1675
1690
|
|
1676
|
-
jconstructor
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
jmethod
|
1681
|
-
|
1682
|
-
|
1683
|
-
method_getName = (*jenv)->GetMethodID(jenv, jmethod, "getName", "()Ljava/lang/String;");
|
1684
|
-
rjb_check_exception(jenv, 1);
|
1685
|
-
getParameterTypes = (*jenv)->GetMethodID(jenv, jmethod, "getParameterTypes", "()[Ljava/lang/Class;");
|
1686
|
-
rjb_check_exception(jenv, 1);
|
1687
|
-
getReturnType = (*jenv)->GetMethodID(jenv, jmethod, "getReturnType", "()Ljava/lang/Class;");
|
1688
|
-
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;");
|
1689
1698
|
|
1690
|
-
jfield
|
1691
|
-
field_getModifiers
|
1692
|
-
|
1693
|
-
|
1694
|
-
rjb_check_exception(jenv, 1);
|
1695
|
-
field_getType = (*jenv)->GetMethodID(jenv, jfield, "getType", "()Ljava/lang/Class;");
|
1696
|
-
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;");
|
1697
1703
|
|
1698
|
-
j_class
|
1699
|
-
|
1700
|
-
rjb_class_getName = (*jenv)->GetMethodID(jenv, j_class, "getName", "()Ljava/lang/String;");
|
1701
|
-
rjb_check_exception(jenv, 1);
|
1702
|
-
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;");
|
1703
1706
|
|
1704
|
-
rjb_j_throwable
|
1705
|
-
|
1706
|
-
rjb_throwable_getMessage = (*jenv)->GetMethodID(jenv, rjb_j_throwable, "getMessage", "()Ljava/lang/String;");
|
1707
|
-
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;");
|
1708
1709
|
|
1709
|
-
j_string
|
1710
|
-
|
1711
|
-
str_tostring = (*jenv)->GetMethodID(jenv, j_string, "toString", "()Ljava/lang/String;");
|
1712
|
-
rjb_check_exception(jenv, 1);
|
1713
|
-
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;");
|
1714
1712
|
|
1715
|
-
j_object
|
1716
|
-
rjb_check_exception(jenv, 1);
|
1717
|
-
j_object = (*jenv)->NewGlobalRef(jenv, j_object);
|
1713
|
+
RJB_HOLD_CLASS(j_object, "java/lang/Object");
|
1718
1714
|
|
1719
1715
|
for (i = PRM_INT; i < PRM_LAST; i++)
|
1720
1716
|
{
|
1721
1717
|
jclass klass = (*jenv)->FindClass(jenv, jpcvt[i].classname);
|
1722
1718
|
if (i == PRM_BOOLEAN)
|
1723
1719
|
{
|
1724
|
-
|
1725
|
-
klass, "valueOf", jpcvt[i].ctrsig);
|
1726
|
-
rjb_check_exception(jenv, 1);
|
1720
|
+
RJB_LOAD_STATIC_METHOD(jpcvt[i].ctr_id, klass, "valueOf", jpcvt[i].ctrsig);
|
1727
1721
|
}
|
1728
1722
|
else if (jpcvt[i].ctrsig)
|
1729
1723
|
{
|
1730
|
-
|
1731
|
-
"<init>", jpcvt[i].ctrsig);
|
1732
|
-
rjb_check_exception(jenv, 1);
|
1724
|
+
RJB_LOAD_METHOD(jpcvt[i].ctr_id, klass, "<init>", jpcvt[i].ctrsig);
|
1733
1725
|
}
|
1734
|
-
|
1726
|
+
RJB_LOAD_METHOD(jpcvt[i].to_prim_id, klass,
|
1735
1727
|
jpcvt[i].to_prim_method, jpcvt[i].prmsig);
|
1736
|
-
|
1728
|
+
|
1737
1729
|
jpcvt[i].klass = (*jenv)->NewGlobalRef(jenv, klass);
|
1738
1730
|
}
|
1739
1731
|
|
@@ -1749,6 +1741,9 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
|
|
1749
1741
|
*/
|
1750
1742
|
VALUE rjb_load_vm_default()
|
1751
1743
|
{
|
1744
|
+
if (rjb_jvm) return Qfalse;
|
1745
|
+
|
1746
|
+
rb_warning("Rjb::implicit jvm loading");
|
1752
1747
|
return rjb_s_load(0, NULL, 0);
|
1753
1748
|
}
|
1754
1749
|
|
@@ -1766,15 +1761,16 @@ static int clear_classes(VALUE key, VALUE val, VALUE dummy)
|
|
1766
1761
|
}
|
1767
1762
|
static VALUE rjb_s_unload(int argc, VALUE* argv, VALUE self)
|
1768
1763
|
{
|
1764
|
+
int result = 0;
|
1769
1765
|
st_foreach(RHASH_TBL(rjb_loaded_classes), clear_classes, 0);
|
1770
1766
|
if (rjb_jvm)
|
1771
1767
|
{
|
1772
1768
|
JNIEnv* jenv = rjb_attach_current_thread();
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1769
|
+
(*jenv)->ExceptionClear(jenv);
|
1770
|
+
result = (*rjb_jvm)->DestroyJavaVM(rjb_jvm);
|
1771
|
+
rjb_jvm = NULL;
|
1776
1772
|
}
|
1777
|
-
return
|
1773
|
+
return INT2NUM(result);
|
1778
1774
|
}
|
1779
1775
|
|
1780
1776
|
/*
|
@@ -1808,6 +1804,7 @@ static VALUE rjb_s_get_pconversion(VALUE self)
|
|
1808
1804
|
/*
|
1809
1805
|
* free java class
|
1810
1806
|
*/
|
1807
|
+
#if 0
|
1811
1808
|
static void free_constructor(struct cls_constructor* p)
|
1812
1809
|
{
|
1813
1810
|
free(p->arg_convert);
|
@@ -1821,6 +1818,7 @@ static int free_method_item(ID key, struct cls_method* pm, int dummy)
|
|
1821
1818
|
}
|
1822
1819
|
return ST_CONTINUE;
|
1823
1820
|
}
|
1821
|
+
#endif
|
1824
1822
|
|
1825
1823
|
/*
|
1826
1824
|
* finalize Object instance
|
@@ -1996,7 +1994,7 @@ static int check_rtype(JNIEnv* jenv, VALUE v, char* p)
|
|
1996
1994
|
case T_DATA:
|
1997
1995
|
if (RBASIC(v)->klass == rjbi && pcls)
|
1998
1996
|
{
|
1999
|
-
|
1997
|
+
/* imported object */
|
2000
1998
|
jclass cls;
|
2001
1999
|
struct jvi_data* ptr;
|
2002
2000
|
int result = 0;
|
@@ -2010,9 +2008,9 @@ static int check_rtype(JNIEnv* jenv, VALUE v, char* p)
|
|
2010
2008
|
}
|
2011
2009
|
return result;
|
2012
2010
|
}
|
2013
|
-
|
2011
|
+
/* fall down to the next case */
|
2014
2012
|
case T_OBJECT:
|
2015
|
-
|
2013
|
+
/* fall down to the next case */
|
2016
2014
|
default:
|
2017
2015
|
if (pcls || *p == '[')
|
2018
2016
|
{
|
@@ -2129,11 +2127,12 @@ static VALUE rjb_s_bind(VALUE self, VALUE rbobj, VALUE itfname)
|
|
2129
2127
|
{
|
2130
2128
|
VALUE result = Qnil;
|
2131
2129
|
JNIEnv* jenv = NULL;
|
2132
|
-
|
2130
|
+
jclass itf;
|
2131
|
+
|
2133
2132
|
rjb_load_vm_default();
|
2134
2133
|
jenv = rjb_attach_current_thread();
|
2135
2134
|
(*jenv)->ExceptionClear(jenv);
|
2136
|
-
|
2135
|
+
itf = rjb_find_class(jenv, itfname);
|
2137
2136
|
rjb_check_exception(jenv, 1);
|
2138
2137
|
if (itf)
|
2139
2138
|
{
|
@@ -2468,7 +2467,7 @@ static VALUE invoke(JNIEnv* jenv, struct cls_method* pm, struct jvi_data* ptr,
|
|
2468
2467
|
}
|
2469
2468
|
if (!found)
|
2470
2469
|
{
|
2471
|
-
char* tname = rb_id2name(orgpm->name);
|
2470
|
+
const char* tname = rb_id2name(orgpm->name);
|
2472
2471
|
if (sig)
|
2473
2472
|
{
|
2474
2473
|
rb_raise(rb_eRuntimeError, "Fail: unknown method name `%s(\'%s\')'", tname, sig);
|
@@ -2557,7 +2556,7 @@ static VALUE invoke_by_instance(ID rmid, int argc, VALUE* argv,
|
|
2557
2556
|
JNIEnv* jenv = rjb_attach_current_thread();
|
2558
2557
|
struct cls_field* pf;
|
2559
2558
|
struct cls_method* pm;
|
2560
|
-
char* tname = rb_id2name(rmid);
|
2559
|
+
const char* tname = rb_id2name(rmid);
|
2561
2560
|
|
2562
2561
|
if (argc == 0 && st_lookup(ptr->fields, rmid, (st_data_t*)&pf))
|
2563
2562
|
{
|
@@ -2575,7 +2574,7 @@ static VALUE invoke_by_instance(ID rmid, int argc, VALUE* argv,
|
|
2575
2574
|
setter(jenv, pf, ptr, *argv);
|
2576
2575
|
return ret;
|
2577
2576
|
}
|
2578
|
-
|
2577
|
+
/* fall through for the setter alias name */
|
2579
2578
|
}
|
2580
2579
|
if (st_lookup(ptr->methods, rmid, (st_data_t*)&pm))
|
2581
2580
|
{
|
@@ -2623,7 +2622,7 @@ static VALUE invoke_by_class(ID rmid, int argc, VALUE* argv,
|
|
2623
2622
|
struct jv_data* clsptr;
|
2624
2623
|
struct cls_field* pf;
|
2625
2624
|
struct cls_method* pm;
|
2626
|
-
char* tname = rb_id2name(rmid);
|
2625
|
+
const char* tname = rb_id2name(rmid);
|
2627
2626
|
JNIEnv* jenv = rjb_attach_current_thread();
|
2628
2627
|
|
2629
2628
|
Data_Get_Struct(jklass, struct jv_data, clsptr);
|
@@ -2700,7 +2699,7 @@ static VALUE rjb_missing(int argc, VALUE* argv, VALUE self)
|
|
2700
2699
|
{
|
2701
2700
|
struct jv_data* ptr;
|
2702
2701
|
ID rmid = rb_to_id(argv[0]);
|
2703
|
-
char* rmname = rb_id2name(rmid);
|
2702
|
+
const char* rmname = rb_id2name(rmid);
|
2704
2703
|
if (isupper(*rmname))
|
2705
2704
|
{
|
2706
2705
|
VALUE r, args[2];
|
@@ -2832,7 +2831,7 @@ JNIEXPORT jobject JNICALL Java_jp_co_infoseek_hp_arton_rjb_RBridge_call
|
|
2832
2831
|
*(argv + 2) = argc - 3;
|
2833
2832
|
result = rb_protect(safe_funcall, (VALUE)argv, &sstat);
|
2834
2833
|
rv2jobject(jenv, result, &j, NULL, 0);
|
2835
|
-
|
2834
|
+
/* I can't delete this object... */
|
2836
2835
|
break;
|
2837
2836
|
}
|
2838
2837
|
}
|
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 75 2008-08-14 10:03:52Z arton $
|
16
16
|
*/
|
17
17
|
|
18
18
|
#include "ruby.h"
|
@@ -109,7 +109,6 @@ void rjb_check_exception(JNIEnv* jenv, int t)
|
|
109
109
|
(*jenv)->ExceptionDescribe(jenv);
|
110
110
|
}
|
111
111
|
(*jenv)->ExceptionClear(jenv);
|
112
|
-
// if (t)
|
113
112
|
if(1)
|
114
113
|
{
|
115
114
|
char* msg = "unknown exception";
|
data/test/test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/local/env ruby
|
2
|
-
# $Id: test.rb
|
2
|
+
# $Id: test.rb 70 2008-05-26 12:31:35Z arton $
|
3
3
|
|
4
4
|
begin
|
5
5
|
require 'rjb'
|
@@ -27,8 +27,7 @@ class TestRjb < Test::Unit::TestCase
|
|
27
27
|
@jChar = Rjb::import('java.lang.Character')
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
unload
|
30
|
+
def teardown
|
32
31
|
end
|
33
32
|
|
34
33
|
def test_metaclass
|
@@ -616,5 +615,16 @@ class TestRjb < Test::Unit::TestCase
|
|
616
615
|
assert_equal "\0\x1\x2\x3\x4", map.get('abc')
|
617
616
|
assert_equal "\x5\x6\x7\x8\x9", map.get('def')
|
618
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
|
619
629
|
end
|
620
630
|
|
metadata
CHANGED
@@ -1,78 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
2
4
|
name: rjb
|
3
5
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
6
|
+
version: 1.1.4
|
7
|
+
date: 2008-08-14 00:00:00 +09:00
|
8
|
+
summary: Ruby Java bridge
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: artonx@gmail.com
|
12
|
+
homepage: http://rjb.rubyforge.org/
|
13
|
+
rubyforge_project:
|
14
|
+
description: RJB is a bridge program that connect between Ruby and Java with Java Native Interface.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.8.2
|
24
|
+
version:
|
5
25
|
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
6
29
|
authors:
|
7
30
|
- arton
|
8
|
-
autorequire:
|
9
|
-
bindir: bin
|
10
|
-
cert_chain: []
|
11
|
-
|
12
|
-
date: 2008-03-26 00:00:00 +09:00
|
13
|
-
default_executable:
|
14
|
-
dependencies: []
|
15
|
-
|
16
|
-
description: RJB is a bridge program that connect between Ruby and Java with Java Native Interface.
|
17
|
-
email: artonx@gmail.com
|
18
|
-
executables: []
|
19
|
-
|
20
|
-
extensions:
|
21
|
-
- ext/extconf.rb
|
22
|
-
extra_rdoc_files: []
|
23
|
-
|
24
31
|
files:
|
25
32
|
- ext/RBridge.java
|
26
33
|
- ext/load.c
|
27
34
|
- ext/riconv.c
|
28
|
-
- ext/rjb.c
|
29
35
|
- ext/rjbexception.c
|
30
|
-
- ext/
|
36
|
+
- ext/rjb.c
|
31
37
|
- ext/jniwrap.h
|
32
|
-
- ext/jp_co_infoseek_hp_arton_rjb_RBridge.h
|
33
|
-
- ext/riconv.h
|
34
38
|
- ext/rjb.h
|
39
|
+
- ext/riconv.h
|
40
|
+
- ext/jp_co_infoseek_hp_arton_rjb_RBridge.h
|
41
|
+
- ext/extconf.h
|
35
42
|
- ext/depend
|
36
43
|
- data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class
|
37
44
|
- lib/rjb.rb
|
38
45
|
- samples/filechooser.rb
|
39
|
-
- test/gctest.rb
|
40
46
|
- test/test.rb
|
41
|
-
- test/
|
47
|
+
- test/gctest.rb
|
42
48
|
- test/jp/co/infoseek/hp/arton/rjb/ExtBase.class
|
49
|
+
- test/jp/co/infoseek/hp/arton/rjb/Test.class
|
43
50
|
- test/jp/co/infoseek/hp/arton/rjb/IBase.class
|
44
51
|
- test/jp/co/infoseek/hp/arton/rjb/Test$TestTypes.class
|
45
|
-
- test/jp/co/infoseek/hp/arton/rjb/
|
52
|
+
- test/jp/co/infoseek/hp/arton/rjb/Base.class
|
46
53
|
- COPYING
|
47
54
|
- ChangeLog
|
48
55
|
- readme.sj
|
49
56
|
- readme.txt
|
50
|
-
|
51
|
-
|
52
|
-
post_install_message:
|
57
|
+
test_files:
|
58
|
+
- test/test.rb
|
53
59
|
rdoc_options: []
|
54
60
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
version: 1.8.2
|
62
|
-
version:
|
63
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: "0"
|
68
|
-
version:
|
61
|
+
extra_rdoc_files: []
|
62
|
+
|
63
|
+
executables: []
|
64
|
+
|
65
|
+
extensions:
|
66
|
+
- ext/extconf.rb
|
69
67
|
requirements:
|
70
68
|
- none
|
71
69
|
- JDK 5.0
|
72
|
-
|
73
|
-
|
74
|
-
signing_key:
|
75
|
-
specification_version: 2
|
76
|
-
summary: Ruby Java bridge
|
77
|
-
test_files:
|
78
|
-
- test/test.rb
|
70
|
+
dependencies: []
|
71
|
+
|