rjb 1.2.0-x86-mswin32-60 → 1.2.1-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +18 -0
- data/ext/jp_co_infoseek_hp_arton_rjb_RBridge.h +21 -21
- data/ext/load.c +3 -3
- data/ext/riconv.c +3 -3
- data/ext/rjb.c +141 -44
- data/lib/rjb.rb +2 -1
- data/lib/rjbcore.so +0 -0
- data/test/Base.class +0 -0
- data/test/ExtBase.class +0 -0
- data/test/IBase.class +0 -0
- data/test/JTest.class +0 -0
- data/test/Test$TestTypes.class +0 -0
- data/test/Test.class +0 -0
- data/test/test.rb +52 -9
- data/test/tx.rb +52 -0
- metadata +16 -9
data/ChangeLog
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
Tue May 11 arton
|
2
|
+
*ext/rjb.c
|
3
|
+
fix duplicate method registering while no alias.
|
4
|
+
add class methods for inspecting method signatures.
|
5
|
+
add class_eval method for extending Java class
|
6
|
+
*test/test.rb
|
7
|
+
add class methods test for inspecting method signatures.
|
8
|
+
add mixin tests
|
9
|
+
Tue May 4 arton
|
10
|
+
*ext/load.c
|
11
|
+
corrected wrong function signature (BUG#28088), pointed and fixed by Romulo A. Ceccon (thanks)
|
12
|
+
*ext/rjb.c
|
13
|
+
using inheritance check while inspecting a object is RJB's instance (for extending it).
|
14
|
+
Tue Mar 16 arton
|
15
|
+
*ext/riconv.c
|
16
|
+
change locale setting "" to "C", fixed by Fabien Sartor (rjb-Bugs-27968)
|
17
|
+
*ext/rjb.c
|
18
|
+
RJB_VERSION -> 1.2.1
|
1
19
|
Sun Nov 1 arton
|
2
20
|
*ext/load.c
|
3
21
|
load jvm pointed by JVM_LIB environment variable first (suggested by Ittay Dror).
|
@@ -1,21 +1,21 @@
|
|
1
|
-
/* DO NOT EDIT THIS FILE - it is machine generated */
|
2
|
-
#include <jni.h>
|
3
|
-
/* Header for class jp_co_infoseek_hp_arton_rjb_RBridge */
|
4
|
-
|
5
|
-
#ifndef _Included_jp_co_infoseek_hp_arton_rjb_RBridge
|
6
|
-
#define _Included_jp_co_infoseek_hp_arton_rjb_RBridge
|
7
|
-
#ifdef __cplusplus
|
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
|
16
|
-
(JNIEnv *, jobject, jstring, jobject, jobjectArray);
|
17
|
-
|
18
|
-
#ifdef __cplusplus
|
19
|
-
}
|
20
|
-
#endif
|
21
|
-
#endif
|
1
|
+
/* DO NOT EDIT THIS FILE - it is machine generated */
|
2
|
+
#include <jni.h>
|
3
|
+
/* Header for class jp_co_infoseek_hp_arton_rjb_RBridge */
|
4
|
+
|
5
|
+
#ifndef _Included_jp_co_infoseek_hp_arton_rjb_RBridge
|
6
|
+
#define _Included_jp_co_infoseek_hp_arton_rjb_RBridge
|
7
|
+
#ifdef __cplusplus
|
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
|
16
|
+
(JNIEnv *, jobject, jstring, jobject, jobjectArray);
|
17
|
+
|
18
|
+
#ifdef __cplusplus
|
19
|
+
}
|
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 105 2010-05-04 00:01:26Z arton $
|
16
16
|
*/
|
17
17
|
|
18
18
|
#include <stdlib.h>
|
@@ -90,8 +90,8 @@
|
|
90
90
|
#define GETDEFAULTJVMINITARGS "JNI_GetDefaultJavaVMInitArgs"
|
91
91
|
#endif
|
92
92
|
|
93
|
-
typedef int (*GETDEFAULTJAVAVMINITARGS)(void*);
|
94
|
-
typedef int (*CREATEJAVAVM)(JavaVM**, JNIEnv**, void*);
|
93
|
+
typedef int (JNICALL *GETDEFAULTJAVAVMINITARGS)(void*);
|
94
|
+
typedef int (JNICALL *CREATEJAVAVM)(JavaVM**, JNIEnv**, void*);
|
95
95
|
|
96
96
|
|
97
97
|
static VALUE jvmdll = Qnil;
|
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
|
15
|
+
* $Id: riconv.c 104 2010-03-16 12:19:18Z arton $
|
16
16
|
*/
|
17
17
|
|
18
18
|
#include "ruby.h"
|
@@ -98,14 +98,14 @@ static const char* get_charcode_name()
|
|
98
98
|
#if defined _WIN32 || defined __CYGWIN__
|
99
99
|
if (932 == GetACP()) result = CS_CP932;
|
100
100
|
#elif defined HAVE_NL_LANGINFO
|
101
|
-
setlocale(LC_ALL, ""); //initialize
|
101
|
+
setlocale(LC_ALL, "C"); //initialize
|
102
102
|
lang = nl_langinfo(CODESET);
|
103
103
|
if (find_table(lang, NL_EUC_TABLE))
|
104
104
|
result = CS_EUCJP;
|
105
105
|
else if (find_table(lang, NL_SJIS_TABLE))
|
106
106
|
result = CS_SJIS;
|
107
107
|
#elif defined HAVE_SETLOCALE
|
108
|
-
setlocale(LC_ALL, ""); //initialize
|
108
|
+
setlocale(LC_ALL, "C"); //initialize
|
109
109
|
result = get_charcode_name_by_locale(setlocale(LC_ALL, NULL));
|
110
110
|
#elif defined HAVE_GETENV
|
111
111
|
if (result = get_charcode_name_by_locale(getenv("LC_ALL")))
|
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 109 2010-05-11 13:04:25Z arton $
|
16
16
|
*/
|
17
17
|
|
18
|
-
#define RJB_VERSION "1.2.
|
18
|
+
#define RJB_VERSION "1.2.1"
|
19
19
|
|
20
20
|
#include "ruby.h"
|
21
21
|
#include "extconf.h"
|
@@ -55,10 +55,12 @@
|
|
55
55
|
#define RJB_LOAD_STATIC_METHOD(var, obj, name, sig) \
|
56
56
|
var = (*jenv)->GetStaticMethodID(jenv, obj, name, sig); \
|
57
57
|
rjb_check_exception(jenv, 1)
|
58
|
+
#define IS_RJB_OBJECT(v) (rb_class_inherited(rjbi, RBASIC(v)->klass) || RBASIC(v)->klass == rjb)
|
59
|
+
#define USER_INITIALIZE "@user_initialize"
|
58
60
|
|
59
61
|
static void register_class(VALUE, VALUE);
|
60
62
|
static VALUE import_class(JNIEnv* jenv, jclass, VALUE);
|
61
|
-
static VALUE register_instance(JNIEnv* jenv, struct
|
63
|
+
static VALUE register_instance(JNIEnv* jenv, VALUE klass, struct jv_data*, jobject);
|
62
64
|
static VALUE rjb_s_free(struct jv_data*);
|
63
65
|
static VALUE rjb_class_forname(int argc, VALUE* argv, VALUE self);
|
64
66
|
static void setup_metadata(JNIEnv* jenv, VALUE self, struct jv_data*, VALUE classname);
|
@@ -73,6 +75,8 @@ static VALUE rjbc;
|
|
73
75
|
static VALUE rjbi;
|
74
76
|
static VALUE rjbb;
|
75
77
|
|
78
|
+
static ID user_initialize;
|
79
|
+
|
76
80
|
VALUE rjb_loaded_classes;
|
77
81
|
static VALUE proxies;
|
78
82
|
JavaVM* rjb_jvm;
|
@@ -286,7 +290,7 @@ static VALUE jv2rv_r(JNIEnv* jenv, jvalue val)
|
|
286
290
|
v = import_class(jenv, klass, clsname);
|
287
291
|
}
|
288
292
|
Data_Get_Struct(v, struct jv_data, ptr);
|
289
|
-
v = register_instance(jenv, (struct
|
293
|
+
v = register_instance(jenv, v, (struct jv_data*)ptr, val.l);
|
290
294
|
(*jenv)->DeleteLocalRef(jenv, klass);
|
291
295
|
(*jenv)->DeleteLocalRef(jenv, val.l);
|
292
296
|
return v;
|
@@ -673,8 +677,7 @@ static void rv2jstring(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
|
|
673
677
|
{
|
674
678
|
if (!release)
|
675
679
|
{
|
676
|
-
if (TYPE(val) == T_DATA
|
677
|
-
&& (RBASIC(val)->klass == rjbi || RBASIC(val)->klass == rjb))
|
680
|
+
if (TYPE(val) == T_DATA && IS_RJB_OBJECT(val))
|
678
681
|
{
|
679
682
|
struct jvi_data* ptr;
|
680
683
|
Data_Get_Struct(val, struct jvi_data, ptr);
|
@@ -710,7 +713,7 @@ static void rv2jstring(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
|
|
710
713
|
{
|
711
714
|
if (TYPE(val) == T_DATA)
|
712
715
|
{
|
713
|
-
|
716
|
+
if (IS_RJB_OBJECT(val))
|
714
717
|
{
|
715
718
|
struct jvi_data* ptr;
|
716
719
|
Data_Get_Struct(val, struct jvi_data, ptr);
|
@@ -764,9 +767,9 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
|
|
764
767
|
switch (TYPE(val))
|
765
768
|
{
|
766
769
|
case T_DATA:
|
767
|
-
|
770
|
+
if (IS_RJB_OBJECT(val))
|
768
771
|
{
|
769
|
-
|
772
|
+
/* TODO: check instanceof (class (in psig) ) */
|
770
773
|
struct jvi_data* ptr;
|
771
774
|
Data_Get_Struct(val, struct jvi_data, ptr);
|
772
775
|
jv->l = ptr->obj;
|
@@ -1327,14 +1330,16 @@ static struct cls_method* clone_methodinfo(struct cls_method* pm)
|
|
1327
1330
|
return result;
|
1328
1331
|
}
|
1329
1332
|
|
1330
|
-
static
|
1333
|
+
static int make_alias(const char* jname, char* rname)
|
1331
1334
|
{
|
1335
|
+
int ret = 0;
|
1332
1336
|
while (*jname)
|
1333
1337
|
{
|
1334
1338
|
if (isupper(*jname))
|
1335
1339
|
{
|
1336
1340
|
*rname++ = '_';
|
1337
1341
|
*rname++ = tolower(*jname++);
|
1342
|
+
ret = 1;
|
1338
1343
|
}
|
1339
1344
|
else
|
1340
1345
|
{
|
@@ -1342,6 +1347,7 @@ static void make_alias(const char* jname, char* rname)
|
|
1342
1347
|
}
|
1343
1348
|
}
|
1344
1349
|
*rname = '\0';
|
1350
|
+
return ret;
|
1345
1351
|
}
|
1346
1352
|
|
1347
1353
|
static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static_method)
|
@@ -1349,6 +1355,7 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
|
|
1349
1355
|
struct cls_method* result;
|
1350
1356
|
struct cls_method* pm;
|
1351
1357
|
const char* jname;
|
1358
|
+
int alias;
|
1352
1359
|
jstring nm;
|
1353
1360
|
jobjectArray parama;
|
1354
1361
|
jobject cls;
|
@@ -1365,7 +1372,7 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
|
|
1365
1372
|
rjb_check_exception(jenv, 0);
|
1366
1373
|
jname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
|
1367
1374
|
rname = ALLOCA_N(char, strlen(jname) * 2 + 8);
|
1368
|
-
make_alias(jname, rname);
|
1375
|
+
alias = make_alias(jname, rname);
|
1369
1376
|
result->name = rb_intern(jname);
|
1370
1377
|
rjb_release_string(jenv, nm, jname);
|
1371
1378
|
result->basic.id = (*jenv)->FromReflectedMethod(jenv, m);
|
@@ -1404,7 +1411,7 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
|
|
1404
1411
|
if (*rname == '_') rname++;
|
1405
1412
|
strcat(rname, "?");
|
1406
1413
|
}
|
1407
|
-
else
|
1414
|
+
else if (alias)
|
1408
1415
|
{
|
1409
1416
|
pm = clone_methodinfo(result);
|
1410
1417
|
}
|
@@ -1729,6 +1736,7 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
|
|
1729
1736
|
|
1730
1737
|
jklass = import_class(jenv, j_class, rb_str_new2("java.lang.Class"));
|
1731
1738
|
rb_define_method(RBASIC(jklass)->klass, "forName", rjb_class_forname, -1);
|
1739
|
+
rb_define_method(RBASIC(jklass)->klass, "for_name", rjb_class_forname, -1);
|
1732
1740
|
rb_gc_register_address(&jklass);
|
1733
1741
|
|
1734
1742
|
return Qnil;
|
@@ -1745,6 +1753,18 @@ VALUE rjb_load_vm_default()
|
|
1745
1753
|
return rjb_s_load(0, NULL, 0);
|
1746
1754
|
}
|
1747
1755
|
|
1756
|
+
/*
|
1757
|
+
* common prelude
|
1758
|
+
*/
|
1759
|
+
JNIEnv* rjb_prelude()
|
1760
|
+
{
|
1761
|
+
JNIEnv* jenv = NULL;
|
1762
|
+
rjb_load_vm_default();
|
1763
|
+
jenv = rjb_attach_current_thread();
|
1764
|
+
(*jenv)->ExceptionClear(jenv);
|
1765
|
+
return jenv;
|
1766
|
+
}
|
1767
|
+
|
1748
1768
|
/*
|
1749
1769
|
* unload Java Virtual Machine
|
1750
1770
|
*
|
@@ -1883,14 +1903,19 @@ static VALUE rjb_s_free(struct jv_data* ptr)
|
|
1883
1903
|
* create new instance of this class
|
1884
1904
|
*/
|
1885
1905
|
static VALUE createinstance(JNIEnv* jenv, int argc, VALUE* argv,
|
1886
|
-
|
1906
|
+
VALUE self, struct cls_constructor* pc)
|
1887
1907
|
{
|
1888
1908
|
int i;
|
1889
1909
|
char* psig = pc->method_signature;
|
1890
1910
|
jobject obj = NULL;
|
1891
1911
|
VALUE result;
|
1892
|
-
|
1912
|
+
struct jv_data* jklass;
|
1913
|
+
struct jvi_data* org;
|
1893
1914
|
jvalue* args = (argc) ? ALLOCA_N(jvalue, argc) : NULL;
|
1915
|
+
|
1916
|
+
Data_Get_Struct(self, struct jv_data, jklass);
|
1917
|
+
org = &jklass->idata;
|
1918
|
+
|
1894
1919
|
for (i = 0; i < argc; i++)
|
1895
1920
|
{
|
1896
1921
|
R2J pr2j = *(pc->arg_convert + i);
|
@@ -1911,7 +1936,7 @@ static VALUE createinstance(JNIEnv* jenv, int argc, VALUE* argv,
|
|
1911
1936
|
psig = next_sig(psig);
|
1912
1937
|
}
|
1913
1938
|
|
1914
|
-
result = register_instance(jenv,
|
1939
|
+
result = register_instance(jenv, self, jklass, obj);
|
1915
1940
|
(*jenv)->DeleteLocalRef(jenv, obj);
|
1916
1941
|
return result;
|
1917
1942
|
}
|
@@ -1941,16 +1966,29 @@ static VALUE import_class(JNIEnv* jenv, jclass jcls, VALUE clsname)
|
|
1941
1966
|
return v;
|
1942
1967
|
}
|
1943
1968
|
|
1944
|
-
static VALUE
|
1969
|
+
static VALUE rjb_i_prepare_proxy(VALUE self)
|
1970
|
+
{
|
1971
|
+
return rb_funcall(self, rb_intern("instance_eval"), 1,
|
1972
|
+
rb_str_new2("instance_eval &" USER_INITIALIZE));
|
1973
|
+
}
|
1974
|
+
|
1975
|
+
static VALUE register_instance(JNIEnv* jenv, VALUE klass, struct jv_data* org, jobject obj)
|
1945
1976
|
{
|
1946
1977
|
VALUE v;
|
1978
|
+
VALUE iproc;
|
1947
1979
|
struct jvi_data* ptr = ALLOC(struct jvi_data);
|
1948
1980
|
memset(ptr, 0, sizeof(struct jvi_data));
|
1949
1981
|
v = Data_Wrap_Struct(rjbi, NULL, rjb_delete_ref, ptr);
|
1950
|
-
ptr->klass = org->obj;
|
1982
|
+
ptr->klass = org->idata.obj;
|
1951
1983
|
ptr->obj = (*jenv)->NewGlobalRef(jenv, obj);
|
1952
|
-
ptr->methods = org->methods;
|
1953
|
-
ptr->fields = org->fields;
|
1984
|
+
ptr->methods = org->idata.methods;
|
1985
|
+
ptr->fields = org->idata.fields;
|
1986
|
+
iproc = rb_ivar_get(klass, user_initialize);
|
1987
|
+
if (iproc != Qnil)
|
1988
|
+
{
|
1989
|
+
rb_ivar_set(v, user_initialize, iproc);
|
1990
|
+
rb_funcall(v, rb_intern("_prepare_proxy"), 0, 0);
|
1991
|
+
}
|
1954
1992
|
return v;
|
1955
1993
|
}
|
1956
1994
|
|
@@ -1990,7 +2028,7 @@ static int check_rtype(JNIEnv* jenv, VALUE v, char* p)
|
|
1990
2028
|
case T_ARRAY:
|
1991
2029
|
return *p == '[';
|
1992
2030
|
case T_DATA:
|
1993
|
-
if (
|
2031
|
+
if (IS_RJB_OBJECT(v) && pcls)
|
1994
2032
|
{
|
1995
2033
|
/* imported object */
|
1996
2034
|
jclass cls;
|
@@ -2028,11 +2066,7 @@ static VALUE rjb_newinstance_s(int argc, VALUE* argv, VALUE self)
|
|
2028
2066
|
VALUE ret = Qnil;
|
2029
2067
|
struct jv_data* ptr;
|
2030
2068
|
int found = 0;
|
2031
|
-
JNIEnv* jenv =
|
2032
|
-
|
2033
|
-
rjb_load_vm_default();
|
2034
|
-
jenv = rjb_attach_current_thread();
|
2035
|
-
(*jenv)->ExceptionClear(jenv);
|
2069
|
+
JNIEnv* jenv = rjb_prelude();
|
2036
2070
|
|
2037
2071
|
rb_scan_args(argc, argv, "1*", &vsig, &rest);
|
2038
2072
|
sig = StringValueCStr(vsig);
|
@@ -2046,7 +2080,7 @@ static VALUE rjb_newinstance_s(int argc, VALUE* argv, VALUE self)
|
|
2046
2080
|
&& !strcmp(sig, (*pc)->method_signature))
|
2047
2081
|
{
|
2048
2082
|
found = 1;
|
2049
|
-
ret = createinstance(jenv, argc - 1, argv + 1,
|
2083
|
+
ret = createinstance(jenv, argc - 1, argv + 1, self, *pc);
|
2050
2084
|
break;
|
2051
2085
|
}
|
2052
2086
|
}
|
@@ -2063,12 +2097,8 @@ static VALUE rjb_newinstance(int argc, VALUE* argv, VALUE self)
|
|
2063
2097
|
struct jv_data* ptr;
|
2064
2098
|
struct cls_constructor** pc;
|
2065
2099
|
int found = 0;
|
2066
|
-
JNIEnv* jenv =
|
2100
|
+
JNIEnv* jenv = rjb_prelude();
|
2067
2101
|
|
2068
|
-
rjb_load_vm_default();
|
2069
|
-
jenv = rjb_attach_current_thread();
|
2070
|
-
(*jenv)->ExceptionClear(jenv);
|
2071
|
-
|
2072
2102
|
Data_Get_Struct(self, struct jv_data, ptr);
|
2073
2103
|
|
2074
2104
|
if (ptr->constructors)
|
@@ -2092,7 +2122,7 @@ static VALUE rjb_newinstance(int argc, VALUE* argv, VALUE self)
|
|
2092
2122
|
}
|
2093
2123
|
if (found)
|
2094
2124
|
{
|
2095
|
-
ret = createinstance(jenv, argc, argv,
|
2125
|
+
ret = createinstance(jenv, argc, argv, self, *pc);
|
2096
2126
|
break;
|
2097
2127
|
}
|
2098
2128
|
}
|
@@ -2118,18 +2148,71 @@ jclass rjb_find_class(JNIEnv* jenv, VALUE name)
|
|
2118
2148
|
return (*jenv)->FindClass(jenv, java2jniname(jnicls));
|
2119
2149
|
}
|
2120
2150
|
|
2151
|
+
/*
|
2152
|
+
* get specified method signature
|
2153
|
+
*/
|
2154
|
+
static VALUE get_signatures(VALUE mname, st_table* st)
|
2155
|
+
{
|
2156
|
+
VALUE ret;
|
2157
|
+
struct cls_method* pm;
|
2158
|
+
ID rmid = rb_to_id(mname);
|
2159
|
+
|
2160
|
+
if (!st_lookup(st, rmid, (st_data_t*)&pm))
|
2161
|
+
{
|
2162
|
+
const char* tname = rb_id2name(rmid);
|
2163
|
+
rb_raise(rb_eRuntimeError, "Fail: unknown method name `%s'", tname);
|
2164
|
+
}
|
2165
|
+
ret = rb_ary_new();
|
2166
|
+
for (; pm; pm = pm->next)
|
2167
|
+
{
|
2168
|
+
rb_ary_push(ret, rb_str_new2(pm->basic.method_signature));
|
2169
|
+
}
|
2170
|
+
return ret;
|
2171
|
+
}
|
2172
|
+
|
2173
|
+
static VALUE rjb_get_signatures(VALUE self, VALUE mname)
|
2174
|
+
{
|
2175
|
+
struct jv_data* ptr;
|
2176
|
+
|
2177
|
+
Data_Get_Struct(self, struct jv_data, ptr);
|
2178
|
+
return get_signatures(mname, ptr->idata.methods);
|
2179
|
+
}
|
2180
|
+
|
2181
|
+
static VALUE rjb_get_static_signatures(VALUE self, VALUE mname)
|
2182
|
+
{
|
2183
|
+
struct jv_data* ptr;
|
2184
|
+
|
2185
|
+
Data_Get_Struct(self, struct jv_data, ptr);
|
2186
|
+
return get_signatures(mname, ptr->static_methods);
|
2187
|
+
}
|
2188
|
+
|
2189
|
+
static VALUE rjb_get_ctor_signatures(VALUE self)
|
2190
|
+
{
|
2191
|
+
VALUE ret;
|
2192
|
+
struct jv_data* ptr;
|
2193
|
+
struct cls_constructor** pc;
|
2194
|
+
|
2195
|
+
Data_Get_Struct(self, struct jv_data, ptr);
|
2196
|
+
ret = rb_ary_new();
|
2197
|
+
if (ptr->constructors)
|
2198
|
+
{
|
2199
|
+
for (pc = ptr->constructors; *pc; pc++)
|
2200
|
+
{
|
2201
|
+
rb_ary_push(ret, rb_str_new2((*pc)->method_signature));
|
2202
|
+
}
|
2203
|
+
}
|
2204
|
+
return ret;
|
2205
|
+
}
|
2206
|
+
|
2121
2207
|
/*
|
2122
2208
|
* jclass Rjb::bind(rbobj, interface_name)
|
2123
2209
|
*/
|
2124
2210
|
static VALUE rjb_s_bind(VALUE self, VALUE rbobj, VALUE itfname)
|
2125
2211
|
{
|
2126
2212
|
VALUE result = Qnil;
|
2127
|
-
JNIEnv* jenv = NULL;
|
2128
2213
|
jclass itf;
|
2214
|
+
JNIEnv* jenv = rjb_prelude();
|
2129
2215
|
|
2130
|
-
rjb_load_vm_default();
|
2131
|
-
jenv = rjb_attach_current_thread();
|
2132
|
-
(*jenv)->ExceptionClear(jenv);
|
2133
2216
|
itf = rjb_find_class(jenv, itfname);
|
2134
2217
|
rjb_check_exception(jenv, 1);
|
2135
2218
|
if (itf)
|
@@ -2154,15 +2237,24 @@ static VALUE rjb_s_bind(VALUE self, VALUE rbobj, VALUE itfname)
|
|
2154
2237
|
return result;
|
2155
2238
|
}
|
2156
2239
|
|
2240
|
+
/*
|
2241
|
+
* Rjb's class is not Class but Object, so add class_eval for the Java class.
|
2242
|
+
*/
|
2243
|
+
static VALUE rjb_class_eval(int argc, VALUE* argv, VALUE self)
|
2244
|
+
{
|
2245
|
+
if (rb_block_given_p())
|
2246
|
+
{
|
2247
|
+
rb_ivar_set(self, user_initialize, rb_block_proc());
|
2248
|
+
}
|
2249
|
+
return self;
|
2250
|
+
}
|
2251
|
+
|
2157
2252
|
/*
|
2158
2253
|
* jclass Rjb::bind(rbobj, interface_name)
|
2159
2254
|
*/
|
2160
2255
|
static VALUE rjb_s_unbind(VALUE self, VALUE rbobj)
|
2161
2256
|
{
|
2162
|
-
JNIEnv* jenv;
|
2163
|
-
rjb_load_vm_default();
|
2164
|
-
jenv = rjb_attach_current_thread();
|
2165
|
-
(*jenv)->ExceptionClear(jenv);
|
2257
|
+
JNIEnv* jenv = rjb_prelude();
|
2166
2258
|
return rb_ary_delete(proxies, rbobj);
|
2167
2259
|
}
|
2168
2260
|
|
@@ -2179,9 +2271,7 @@ static VALUE rjb_s_import(VALUE self, VALUE clsname)
|
|
2179
2271
|
return v;
|
2180
2272
|
}
|
2181
2273
|
|
2182
|
-
|
2183
|
-
jenv = rjb_attach_current_thread();
|
2184
|
-
(*jenv)->ExceptionClear(jenv);
|
2274
|
+
jenv = rjb_prelude();
|
2185
2275
|
jcls = rjb_find_class(jenv, clsname);
|
2186
2276
|
if (!jcls)
|
2187
2277
|
{
|
@@ -2196,6 +2286,10 @@ static void register_class(VALUE self, VALUE clsname)
|
|
2196
2286
|
{
|
2197
2287
|
rb_define_singleton_method(self, "new", rjb_newinstance, -1);
|
2198
2288
|
rb_define_singleton_method(self, "new_with_sig", rjb_newinstance_s, -1);
|
2289
|
+
rb_define_singleton_method(self, "class_eval", rjb_class_eval, -1);
|
2290
|
+
rb_define_singleton_method(self, "sigs", rjb_get_signatures, 1);
|
2291
|
+
rb_define_singleton_method(self, "static_sigs", rjb_get_static_signatures, 1);
|
2292
|
+
rb_define_singleton_method(self, "ctor_sigs", rjb_get_ctor_signatures, 0);
|
2199
2293
|
/*
|
2200
2294
|
* the hash was frozen, so it need to call st_ func directly.
|
2201
2295
|
*/
|
@@ -2745,6 +2839,7 @@ void Init_rjbcore()
|
|
2745
2839
|
rb_global_variable(&rjb_loaded_classes);
|
2746
2840
|
proxies = rb_ary_new();
|
2747
2841
|
rb_global_variable(&proxies);
|
2842
|
+
user_initialize = rb_intern(USER_INITIALIZE);
|
2748
2843
|
|
2749
2844
|
rjb = rb_define_module("Rjb");
|
2750
2845
|
rb_define_module_function(rjb, "load", rjb_s_load, -1);
|
@@ -2763,7 +2858,7 @@ void Init_rjbcore()
|
|
2763
2858
|
rb_gc_register_address(&rjbc);
|
2764
2859
|
rb_define_method(rjbc, "method_missing", rjb_missing, -1);
|
2765
2860
|
rb_define_method(rjbc, "_invoke", rjb_invoke, -1);
|
2766
|
-
rb_define_method(rjbc, "_classname", rjb_i_class, 0);
|
2861
|
+
rb_define_method(rjbc, "_classname", rjb_i_class, 0);
|
2767
2862
|
|
2768
2863
|
/* Java instance object */
|
2769
2864
|
rjbi = rb_class_new(rb_cObject);
|
@@ -2771,6 +2866,8 @@ void Init_rjbcore()
|
|
2771
2866
|
rb_define_method(rjbi, "method_missing", rjb_i_missing, -1);
|
2772
2867
|
rb_define_method(rjbi, "_invoke", rjb_i_invoke, -1);
|
2773
2868
|
rb_define_method(rjbi, "_classname", rjb_i_class, 0);
|
2869
|
+
rb_define_method(rjbi, "_prepare_proxy", rjb_i_prepare_proxy, 0);
|
2870
|
+
rb_define_alias(rjbi, "include", "extend");
|
2774
2871
|
|
2775
2872
|
/* Ruby-Java Bridge object */
|
2776
2873
|
rjbb = rb_class_new(rb_cObject);
|
data/lib/rjb.rb
CHANGED
data/lib/rjbcore.so
CHANGED
Binary file
|
data/test/Base.class
ADDED
Binary file
|
data/test/ExtBase.class
ADDED
Binary file
|
data/test/IBase.class
ADDED
Binary file
|
data/test/JTest.class
ADDED
Binary file
|
Binary file
|
data/test/Test.class
ADDED
Binary file
|
data/test/test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/local/env ruby -Ku
|
2
2
|
# encoding: utf-8
|
3
|
-
# $Id: test.rb
|
3
|
+
# $Id: test.rb 109 2010-05-11 13:04:25Z arton $
|
4
4
|
|
5
5
|
begin
|
6
6
|
require 'rjb'
|
@@ -18,14 +18,14 @@ class TestRjb < Test::Unit::TestCase
|
|
18
18
|
Rjb::primitive_conversion = false
|
19
19
|
|
20
20
|
@jString = import('java.lang.String')
|
21
|
-
@jInteger =
|
22
|
-
@jShort =
|
23
|
-
@jDouble =
|
24
|
-
@jFloat =
|
25
|
-
@jBoolean =
|
26
|
-
@jByte =
|
27
|
-
@jLong =
|
28
|
-
@jChar =
|
21
|
+
@jInteger = import('java.lang.Integer')
|
22
|
+
@jShort = import('java.lang.Short')
|
23
|
+
@jDouble = import('java.lang.Double')
|
24
|
+
@jFloat = import('java.lang.Float')
|
25
|
+
@jBoolean = import('java.lang.Boolean')
|
26
|
+
@jByte = import('java.lang.Byte')
|
27
|
+
@jLong = import('java.lang.Long')
|
28
|
+
@jChar = import('java.lang.Character')
|
29
29
|
end
|
30
30
|
|
31
31
|
def teardown
|
@@ -650,5 +650,48 @@ class TestRjb < Test::Unit::TestCase
|
|
650
650
|
assert_equal "can't create Java VM", $!.message
|
651
651
|
end
|
652
652
|
end
|
653
|
+
|
654
|
+
module TestMixin
|
655
|
+
def test_hello(s)
|
656
|
+
'hello ' + s
|
657
|
+
end
|
658
|
+
end
|
659
|
+
def test_extend
|
660
|
+
@jString.class_eval do
|
661
|
+
include TestMixin
|
662
|
+
end
|
663
|
+
s = @jString.new
|
664
|
+
assert_equal('hello world', s.test_hello('world'))
|
665
|
+
end
|
666
|
+
def test_extend_with_factory
|
667
|
+
point = import('java.awt.Point')
|
668
|
+
point.class_eval do
|
669
|
+
include TestMixin
|
670
|
+
end
|
671
|
+
p = point.new(11, 12)
|
672
|
+
assert_equal(11, p.x)
|
673
|
+
assert_equal(12, p.y)
|
674
|
+
assert_equal('hello world', p.test_hello('world'))
|
675
|
+
p = p.location
|
676
|
+
assert_equal(11, p.x)
|
677
|
+
assert_equal(12, p.y)
|
678
|
+
assert_equal('hello world', p.test_hello('world'))
|
679
|
+
end
|
680
|
+
def test_fetch_method_signature
|
681
|
+
expected = ['I', 'II', 'Ljava.lang.String;', 'Ljava.lang.String;I']
|
682
|
+
sig = @jString.sigs('indexOf').sort
|
683
|
+
assert_equal(expected, sig)
|
684
|
+
end
|
685
|
+
def test_fetch_static_method_signature
|
686
|
+
expected = ['Ljava.lang.String;[Ljava.lang.Object;',
|
687
|
+
'Ljava.util.Locale;Ljava.lang.String;[Ljava.lang.Object;']
|
688
|
+
sig = @jString.static_sigs('format').sort
|
689
|
+
assert_equal(expected, sig)
|
690
|
+
end
|
691
|
+
def test_fetch_ctor_signature
|
692
|
+
expected = ['I', 'Ljava.lang.String;']
|
693
|
+
sig = @jInteger.ctor_sigs.sort
|
694
|
+
assert_equal(expected, sig)
|
695
|
+
end
|
653
696
|
end
|
654
697
|
|
data/test/tx.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/local/env ruby -Ku
|
2
|
+
# encoding: utf-8
|
3
|
+
# $Id: test.rb 87 2009-02-15 12:25:36Z arton $
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'rjb'
|
7
|
+
rescue LoadError
|
8
|
+
require 'rubygems'
|
9
|
+
require 'rjb'
|
10
|
+
end
|
11
|
+
require 'test/unit'
|
12
|
+
|
13
|
+
puts "start RJB(#{Rjb::VERSION}) test"
|
14
|
+
class TestRjb < Test::Unit::TestCase
|
15
|
+
include Rjb
|
16
|
+
def setup
|
17
|
+
Rjb::load('.')
|
18
|
+
@jString = import('java.lang.String')
|
19
|
+
@jInteger = Rjb::import('java.lang.Integer')
|
20
|
+
@jShort = Rjb::import('java.lang.Short')
|
21
|
+
@jDouble = Rjb::import('java.lang.Double')
|
22
|
+
@jFloat = Rjb::import('java.lang.Float')
|
23
|
+
@jBoolean = Rjb::import('java.lang.Boolean')
|
24
|
+
@jByte = Rjb::import('java.lang.Byte')
|
25
|
+
@jLong = Rjb::import('java.lang.Long')
|
26
|
+
@jChar = Rjb::import('java.lang.Character')
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_scalar
|
33
|
+
str = @jString.new_with_sig('Ljava.lang.String;', "abcde")
|
34
|
+
p str
|
35
|
+
p str.class
|
36
|
+
# rjb object (String)
|
37
|
+
str2 = @jString.new_with_sig('Ljava.lang.String;', 'fghijk')
|
38
|
+
p str2
|
39
|
+
p str2.class
|
40
|
+
a = str.concat(str2)
|
41
|
+
p a
|
42
|
+
p a.class
|
43
|
+
p str2
|
44
|
+
p str2.class
|
45
|
+
a = str.concat(str2)
|
46
|
+
p a
|
47
|
+
p a.class
|
48
|
+
assert_equal('abcdefghijk', str.concat(str2))
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
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.2.
|
4
|
+
version: 1.2.1
|
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:
|
12
|
+
date: 2010-05-11 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -26,25 +26,32 @@ extra_rdoc_files: []
|
|
26
26
|
files:
|
27
27
|
- ext/RBridge.java
|
28
28
|
- ext/load.c
|
29
|
-
- ext/rjbexception.c
|
30
29
|
- ext/riconv.c
|
31
30
|
- ext/rjb.c
|
32
|
-
- ext/
|
33
|
-
- ext/riconv.h
|
31
|
+
- ext/rjbexception.c
|
34
32
|
- ext/extconf.h
|
35
33
|
- ext/jniwrap.h
|
34
|
+
- ext/jp_co_infoseek_hp_arton_rjb_RBridge.h
|
35
|
+
- ext/riconv.h
|
36
36
|
- ext/rjb.h
|
37
37
|
- ext/depend
|
38
38
|
- data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class
|
39
39
|
- lib/rjb.rb
|
40
40
|
- samples/filechooser.rb
|
41
|
-
- test/test.rb
|
42
41
|
- test/gctest.rb
|
42
|
+
- test/test.rb
|
43
|
+
- test/tx.rb
|
44
|
+
- test/Base.class
|
45
|
+
- test/ExtBase.class
|
46
|
+
- test/IBase.class
|
43
47
|
- test/jp/co/infoseek/hp/arton/rjb/Base.class
|
48
|
+
- test/jp/co/infoseek/hp/arton/rjb/ExtBase.class
|
44
49
|
- test/jp/co/infoseek/hp/arton/rjb/IBase.class
|
45
|
-
- test/jp/co/infoseek/hp/arton/rjb/Test.class
|
46
50
|
- test/jp/co/infoseek/hp/arton/rjb/Test$TestTypes.class
|
47
|
-
- test/jp/co/infoseek/hp/arton/rjb/
|
51
|
+
- test/jp/co/infoseek/hp/arton/rjb/Test.class
|
52
|
+
- test/JTest.class
|
53
|
+
- test/Test$TestTypes.class
|
54
|
+
- test/Test.class
|
48
55
|
- COPYING
|
49
56
|
- ChangeLog
|
50
57
|
- readme.sj
|
@@ -76,7 +83,7 @@ requirements:
|
|
76
83
|
- JDK 5.0
|
77
84
|
- " VC6 version of Ruby"
|
78
85
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.3.
|
86
|
+
rubygems_version: 1.3.5
|
80
87
|
signing_key:
|
81
88
|
specification_version: 3
|
82
89
|
summary: Ruby Java bridge
|