rjb 1.5.7 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a44bbac6e23b95fd5b2297053622034f4cc8027d656f546bce3d3d2e20646b4
4
- data.tar.gz: 83ff490b4dd8fe79954832e355e4981e5dea72cf3dfbd8350698f869a7ca5eae
3
+ metadata.gz: bb67ad89857525ce2a6443cb151d5f48dc05a5338ad09e28714b1706cecaa5d6
4
+ data.tar.gz: 42ab7af0fab4e999d025bc4c7957771a9372699dcd0e15664a741eb0b008aea5
5
5
  SHA512:
6
- metadata.gz: 9e63eb18a2302be1b83db2e10486104dd5380cbcb7d623c2a2eb6a6203de21f750c03a26c7e6bbd6002adca588ca6d475a12368d72d5790fd6052738770c3ce8
7
- data.tar.gz: 426214a2feae8412362efaabb2cf0c4a49882e5701d0dceb80cb91ea24dc686eebc6c9fdee81a216e692735a86d33c99bc72bf9efaae6b0d631e43f4fa9a4b27
6
+ metadata.gz: ce14080ae984eaa12dafd0433fd5a902fa9dcb5d731f34e674a78d20ae9e04634512c7f40086283fcad7db1064f3a750c1b8c35802c8f1fd75add365cbcf3c0a
7
+ data.tar.gz: ea0a88e9752dfd8407bd9130b1548589b0fdca90d7a962bef175e504183775817e2818abcb833bae7ab65cfb88e4dcda04c666388b3f2c40235f4b93db396a56
data/ChangeLog CHANGED
@@ -1,3 +1,42 @@
1
+ Sat Aug 1 2020 arton
2
+ * ext/rjb.c
3
+ RJB_VERSION -> 1.6.2
4
+ * ext/load.c
5
+ support OpenJDK directory structure (without jre)
6
+ * lib/rjb.rb
7
+ change copyright notice
8
+ Wed Jul 17 2019 arton
9
+ * ext/rjb.c
10
+ RJB_VERSION -> 1.6.1
11
+ * lib/rjb.rb
12
+ java_methods and methods return symbol
13
+ implements respond_to? for Java methods
14
+ * ext/rbjexception.c
15
+ delegate to JavaProxy for respond_to? (except for to_str and exception)
16
+ * test/test.rb
17
+ change java_methods test to adjust above change
18
+ add respond_to? test
19
+ Thu Jul 11 2019 arton
20
+ * ext/rjb.c
21
+ RJB_VERSION -> 1.6.0
22
+ * ext/riconv.c
23
+ encode/decode between utf-8 and cesu-8 if char was greater than \uffff
24
+ Sun Feb 17 2019 lamby / arton
25
+ * ext/rjb.c
26
+ RJB_VERSION -> 1.5.9
27
+ * ext/depend.erb
28
+ it set javah line by ERB
29
+ * ext/extconf.rb
30
+ change javah to javac -h if it does not exist
31
+ * ext/depend
32
+ replaced by depend.erb
33
+ Thu Jan 17 2019 arton
34
+ * ext/rjbexception.c
35
+ restore method_missing for the exception class
36
+ * ext/rjb.c
37
+ RJB_VERSION -> 1.5.8
38
+ * test/test.rb
39
+ add #60 test
1
40
  Fri Dec 28 2018 arton
2
41
  * ext/rjbexception.c
3
42
  fix #60; stable java derived exception class for raise
@@ -3,7 +3,7 @@ rjb.o : rjb.c jp_co_infoseek_hp_arton_rjb_RBridge.h riconv.h rjb.h
3
3
  rjbexception.o : rjbexception.c jp_co_infoseek_hp_arton_rjb_RBridge.h riconv.h rjb.h
4
4
  load.o : load.c jp_co_infoseek_hp_arton_rjb_RBridge.h
5
5
  jp_co_infoseek_hp_arton_rjb_RBridge.h : jniwrap.h ../data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class
6
- javah -classpath ../data/rjb jp.co.infoseek.hp.arton.rjb.RBridge
6
+ <%= javah %>
7
7
  ../data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class : RBridge.java
8
8
  mkdir -p ../data/rjb/jp/co/infoseek/hp/arton/rjb
9
9
  javac -d ../data/rjb RBridge.java
@@ -4,5 +4,5 @@
4
4
  #define HAVE_NL_LANGINFO 1
5
5
  #define HAVE_SETLOCALE 1
6
6
  #define HAVE_GETENV 1
7
- #define RJB_RUBY_VERSION_CODE 260
7
+ #define RJB_RUBY_VERSION_CODE 271
8
8
  #endif
@@ -4,6 +4,7 @@
4
4
  # $Date: $
5
5
  #----------------------------------
6
6
  require 'mkmf'
7
+ require 'erb'
7
8
 
8
9
  class Path
9
10
 
@@ -74,4 +75,13 @@ when /mswin32/
74
75
  when /cygwin/, /mingw/
75
76
  $defs << '-DNONAMELESSUNION'
76
77
  end
78
+
79
+ if find_executable('javah')
80
+ javah = 'javah -classpath ../data/rjb jp.co.infoseek.hp.arton.rjb.RBridge'
81
+ else
82
+ javah = 'javac -h . -classpath ../data/rjb RBridge.java'
83
+ end
84
+ File.open('depend', 'w') do |fout|
85
+ fout.write ERB.new(IO::read('depend.erb')).result
86
+ end
77
87
  create_rjb_makefile
data/ext/load.c CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * Rjb - Ruby <-> Java Bridge
3
- * Copyright(c) 2004,2005,2006,2009,2010,2011 arton
3
+ * Copyright(c) 2004,2005,2006,2009,2010,2011,2020 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
@@ -38,9 +38,11 @@
38
38
  #if defined(_WIN32) || defined(__CYGWIN__)
39
39
  #if defined(__CYGWIN__)
40
40
  #define JVMDLL "%s/jre/bin/%s/jvm.dll"
41
+ #define OPENJDK_JVMDLL "%s/bin/%s/jvm.dll"
41
42
  #define DIRSEPARATOR '/'
42
43
  #else
43
44
  #define JVMDLL "%s\\jre\\bin\\%s\\jvm.dll"
45
+ #define OPENJDK_JVMDLL "%s\\bin\\%s\\jvm.dll"
44
46
  #define DIRSEPARATOR '\\'
45
47
  #if defined(_WIN64)
46
48
  #undef JVM_TYPE
@@ -61,6 +63,7 @@
61
63
  #define JVM_TYPE "j9vm"
62
64
  #elif defined(__hpux)
63
65
  #define JVMDLL "%s/jre/lib/%s/%s/libjvm.sl"
66
+ #define OPENJDK_JVMDLL "%s/lib/%s/libjvm.sl"
64
67
  #define ARCH "PA_RISC"
65
68
  #undef JVM_TYPE
66
69
  #define JVM_TYPE "server"
@@ -88,6 +91,7 @@
88
91
  #include <sys/systeminfo.h>
89
92
  #endif
90
93
  #define JVMDLL "%s/jre/lib/%s/%s/libjvm.so"
94
+ #define OPENJDK_JVMDLL "%s/lib/%s/libjvm.so"
91
95
  #define DIRSEPARATOR '/'
92
96
  #define CLASSPATH_SEP ':'
93
97
  #endif
@@ -123,12 +127,20 @@ static int open_jvm(char* libpath)
123
127
  size_t i;
124
128
  int state;
125
129
 
130
+ if (rb_funcall(rb_cFile, rb_intern("exist?"), 1, rb_str_new2(libpath)) == RUBY_Qfalse)
131
+ {
132
+ if (RTEST(ruby_verbose))
133
+ {
134
+ fprintf(stderr, "Rjb::load try to find but not exist %s\n", libpath);
135
+ }
136
+ return 0;
137
+ }
126
138
  #if defined(RUBINIUS)
127
139
  i = 1;
128
140
  #else
129
141
  i = 0;
130
142
  #endif
131
- for (; i < COUNTOF(DLLibs); i++)
143
+ for (; i < COUNTOF(DLLibs); i++)
132
144
  {
133
145
  state = 0;
134
146
  rb_protect(safe_require, rb_str_new2(DLLibs[i]), &state);
@@ -137,7 +149,7 @@ static int open_jvm(char* libpath)
137
149
  {
138
150
  if (i > 0)
139
151
  {
140
- rb_raise(rb_eRuntimeError, "Constants DL and Fiddle is not defined.");
152
+ rb_raise(rb_eRuntimeError, "Constants DL or Fiddle is not defined.");
141
153
  return 0;
142
154
  }
143
155
  }
@@ -163,8 +175,8 @@ static int open_jvm(char* libpath)
163
175
  }
164
176
  /* get function pointers of JNI */
165
177
  #if RJB_RUBY_VERSION_CODE < 190
166
- getdefaultjavavminitargsfunc = rb_funcall(rb_funcall(rb_funcall(jvmdll, rb_intern("[]"), 2, rb_str_new2(GETDEFAULTJVMINITARGS), rb_str_new2("IP")), rb_intern("to_ptr"), 0), rb_intern("to_i"), 0);
167
- createjavavmfunc = rb_funcall(rb_funcall(rb_funcall(jvmdll, rb_intern("[]"), 2, rb_str_new2(CREATEJVM), rb_str_new2("IPPP")), rb_intern("to_ptr"), 0), rb_intern("to_i"), 0);
178
+ getdefaultjavavminitargsfunc = rb_funcall(rb_funcall(rb_funcall(jvmdll, rb_intern("[]"), 2, rb_str_new2(GETDEFAULTJVMINITARGS), rb_str_new2("IP")), rb_intern("to_ptr"), 0), rb_intern("to_i"), 0);
179
+ createjavavmfunc = rb_funcall(rb_funcall(rb_funcall(jvmdll, rb_intern("[]"), 2, rb_str_new2(CREATEJVM), rb_str_new2("IPPP")), rb_intern("to_ptr"), 0), rb_intern("to_i"), 0);
168
180
  #else
169
181
  getdefaultjavavminitargsfunc = rb_funcall(jvmdll, rb_intern("[]"), 1, rb_str_new2(GETDEFAULTJVMINITARGS));
170
182
  createjavavmfunc = rb_funcall(jvmdll, rb_intern("[]"), 1, rb_str_new2(CREATEJVM));
@@ -184,6 +196,7 @@ static int file_exist(const char* dir, const char* file)
184
196
 
185
197
  /*
186
198
  * not completed, only valid under some circumstances.
199
+ * load priority: OpenJDK -> SunJDK
187
200
  */
188
201
  static int load_jvm(const char* jvmtype)
189
202
  {
@@ -236,26 +249,37 @@ static int load_jvm(const char* jvmtype)
236
249
  *(p + strlen(p) - 1) = '\0';
237
250
  jh = p;
238
251
  }
239
- #endif
252
+ #endif
240
253
  java_home = ALLOCA_N(char, strlen(jh) + 1);
241
254
  strcpy(java_home, jh);
242
255
  if (*(java_home + strlen(jh) - 1) == DIRSEPARATOR)
243
256
  {
244
257
  *(java_home + strlen(jh) - 1) = '\0';
245
258
  }
259
+ #if defined(__APPLE__) && defined(__MACH__)
260
+ libpath = ALLOCA_N(char, sizeof(JVMDLL) + strlen(java_home) + 1);
261
+ sprintf(libpath, JVMDLL, java_home);
262
+ return open_jvm(libpath);
263
+ #else
246
264
  #if defined(_WIN32) || defined(__CYGWIN__)
247
265
  libpath = ALLOCA_N(char, sizeof(JVMDLL) + strlen(java_home)
248
266
  + strlen(jvmtype) + 1);
249
- sprintf(libpath, JVMDLL, java_home, jvmtype);
250
- #elif defined(__APPLE__) && defined(__MACH__)
251
- libpath = ALLOCA_N(char, sizeof(JVMDLL) + strlen(java_home) + 1);
252
- sprintf(libpath, JVMDLL, java_home);
253
267
  #else /* not Windows / MAC OS-X */
254
268
  libpath = ALLOCA_N(char, sizeof(JVMDLL) + strlen(java_home)
255
- + strlen(ARCH) + strlen(jvmtype) + 1);
269
+ + strlen(ARCH) + strlen(jvmtype) + 1);
270
+ #endif
271
+ sprintf(libpath, OPENJDK_JVMDLL, java_home, jvmtype);
272
+ if (open_jvm(libpath))
273
+ {
274
+ return 1;
275
+ }
276
+ #if defined(_WIN32) || defined(__CYGWIN__)
277
+ return 0;
278
+ #else /* not Windows / MAC OS-X */
256
279
  sprintf(libpath, JVMDLL, java_home, ARCH, jvmtype);
257
280
  #endif
258
281
  return open_jvm(libpath);
282
+ #endif /* __APPLE__ and __MACH */
259
283
  }
260
284
 
261
285
  static int load_bridge(JNIEnv* jenv)
@@ -269,7 +293,7 @@ static int load_bridge(JNIEnv* jenv)
269
293
  VALUE v = rb_const_get(rb_cObject, rb_intern("RjbConf"));
270
294
  v = rb_const_get(v, rb_intern("BRIDGE_FILE"));
271
295
  #else
272
- VALUE v = rb_const_get_at(rb_const_get(rb_cObject, rb_intern("RjbConf")),
296
+ VALUE v = rb_const_get_at(rb_const_get(rb_cObject, rb_intern("RjbConf")),
273
297
  rb_intern("BRIDGE_FILE"));
274
298
  #endif
275
299
  bridge = StringValuePtr(v);
@@ -352,7 +376,7 @@ int rjb_create_jvm(JNIEnv** pjenv, JavaVMInitArgs* vm_args, char* userpath, VALU
352
376
  *(p + strlen(p) - 1) = '\0';
353
377
  libjvm = p;
354
378
  }
355
- #endif
379
+ #endif
356
380
  if (libjvm == NULL || !open_jvm(libjvm))
357
381
  {
358
382
  #if defined(__APPLE__) && defined(__MACH__)
@@ -370,7 +394,7 @@ int rjb_create_jvm(JNIEnv** pjenv, JavaVMInitArgs* vm_args, char* userpath, VALU
370
394
  }
371
395
  #endif
372
396
  }
373
-
397
+
374
398
  #if RJB_RUBY_VERSION_CODE < 190 && !defined(RUBINIUS)
375
399
  ruby_errinfo = Qnil;
376
400
  #else
@@ -167,6 +167,126 @@ static void check_kcode()
167
167
  objIconvR2J = objIconvJ2R = Qnil;
168
168
  }
169
169
  }
170
+ #else
171
+ VALUE cEncoding = Qnil;
172
+ VALUE encoding_utf8 = Qnil;
173
+ static void init_encoding_vars()
174
+ {
175
+ cEncoding = rb_const_get(rb_cObject, rb_intern("Encoding"));
176
+ encoding_utf8 = rb_const_get(cEncoding, rb_intern("UTF_8"));
177
+ }
178
+ static int contains_surrogate_pair(const unsigned char* p)
179
+ {
180
+ while (*p)
181
+ {
182
+ switch (*p & 0xf0)
183
+ {
184
+ case 0xf0:
185
+ return 1;
186
+ case 0xe0:
187
+ p += 3;
188
+ break;
189
+ default:
190
+ p += (*p & 0x80) ? 2 : 1;
191
+ }
192
+ }
193
+ return 0;
194
+ }
195
+ static int contains_auxchar(const unsigned char* p)
196
+ {
197
+ while (*p)
198
+ {
199
+ if (*p == 0xed)
200
+ {
201
+ #if defined(DEBUG)
202
+ printf("find %02x %02x %02x %02x %02x %02x\n", *p, *(p + 1), *(p + 2), *(p + 3), *(p + 4), *(p + 5));
203
+ #endif
204
+ return 1;
205
+ }
206
+ switch (*p & 0xe0)
207
+ {
208
+ case 0xe0:
209
+ p++;
210
+ case 0xc0:
211
+ p++;
212
+ default:
213
+ p++;
214
+ }
215
+ }
216
+ return 0;
217
+ }
218
+
219
+ static VALUE encode_to_cesu8(const unsigned char* p)
220
+ {
221
+ size_t len = strlen(p);
222
+ char* newstr = ALLOCA_N(char, len + (len + 1) / 2);
223
+ char* dest = newstr;
224
+ int sval, i;
225
+ while (*p)
226
+ {
227
+ switch (*p & 0xf0)
228
+ {
229
+ case 0xf0:
230
+ sval = *p++ & 7;
231
+ for (i = 0; i < 3; i++)
232
+ {
233
+ sval <<= 6;
234
+ sval |= (*p++ & 0x3f);
235
+ }
236
+ *dest++ = '\xed';
237
+ *dest++ = 0xa0 | (((sval >> 16) - 1) & 0x0f);
238
+ *dest++ = 0x80 | ((sval >> 10) & 0x3f);
239
+ *dest++ = '\xed';
240
+ *dest++ = 0xb0 | ((sval >> 6) & 0x0f);
241
+ *dest++ = 0x80 | (sval & 0x3f);
242
+ break;
243
+ case 0xe0:
244
+ *dest++ = *p++;
245
+ case 0xc0:
246
+ case 0xc1:
247
+ *dest++ = *p++;
248
+ default:
249
+ *dest++ = *p++;
250
+ }
251
+ }
252
+ return rb_str_new(newstr, dest - newstr);
253
+ }
254
+ static VALUE encode_to_utf8(const unsigned char* p)
255
+ {
256
+ size_t len = strlen(p);
257
+ char* newstr = ALLOCA_N(char, len);
258
+ char* dest = newstr;
259
+ int sval, i;
260
+ while (*p)
261
+ {
262
+ if (*p == 0xed)
263
+ {
264
+ char v = *(p + 1);
265
+ char w = *(p + 2);
266
+ char y = *(p + 4);
267
+ char z = *(p + 5);
268
+ p += 6;
269
+ sval = 0x10000 + ((v & 0x0f) << 16) + ((w & 0x3f) << 10) + ((y & 0x0f) << 6) + (z & 0x3f);
270
+ sval = (((v + 1) & 0x0f) << 16) + ((w & 0x3f) << 10) + ((y & 0x0f) << 6) + (z & 0x3f);
271
+ *dest++ = 0xf0 | ((sval >> 18));
272
+ *dest++ = 0x80 | ((sval >> 12) & 0x3f);
273
+ *dest++ = 0x80 | ((sval >> 6) & 0x3f);
274
+ *dest++ = 0x80 | (sval & 0x3f);
275
+ continue;
276
+ }
277
+ switch (*p & 0xe0)
278
+ {
279
+ case 0xe0:
280
+ *dest++ = *p++;
281
+ case 0xc0:
282
+ case 0xc1:
283
+ *dest++ = *p++;
284
+ default:
285
+ *dest++ = *p++;
286
+ }
287
+ }
288
+ return rb_str_new(newstr, dest - newstr);
289
+ }
170
290
  #endif
171
291
 
172
292
  #if defined(DEBUG)
@@ -177,6 +297,8 @@ static void debug_out(VALUE v)
177
297
  strlen(p), p);
178
298
  fflush(stdout);
179
299
  }
300
+ #else
301
+ #define debug_out(n)
180
302
  #endif
181
303
 
182
304
  VALUE exticonv_local_to_utf8(VALUE local_string)
@@ -192,23 +314,24 @@ VALUE exticonv_local_to_utf8(VALUE local_string)
192
314
  return local_string;
193
315
  }
194
316
  #else
195
- VALUE cEncoding, encoding, utf8;
196
- cEncoding = rb_const_get(rb_cObject, rb_intern("Encoding"));
317
+ VALUE encoding;
318
+ if (NIL_P(cEncoding))
319
+ {
320
+ init_encoding_vars();
321
+ }
197
322
  encoding = rb_funcall(local_string, rb_intern("encoding"), 0);
198
- utf8 = rb_const_get(cEncoding, rb_intern("UTF_8"));
199
- if (encoding != utf8)
323
+ if (encoding != encoding_utf8)
200
324
  {
201
- VALUE ret = rb_funcall(local_string, rb_intern("encode"), 2, utf8, encoding);
202
- #if defined(DEBUG)
325
+ VALUE ret = rb_funcall(local_string, rb_intern("encode"), 2, encoding_utf8, encoding);
203
326
  debug_out(local_string);
204
327
  debug_out(ret);
205
- #endif
206
- return ret;
328
+ local_string = ret;
207
329
  }
208
- else
330
+ if (contains_surrogate_pair(StringValuePtr(local_string)))
209
331
  {
210
- return local_string;
332
+ local_string = encode_to_cesu8(StringValuePtr(local_string));
211
333
  }
334
+ return local_string;
212
335
  #endif
213
336
  }
214
337
 
@@ -225,6 +348,14 @@ VALUE exticonv_utf8_to_local(VALUE utf8_string)
225
348
  return utf8_string;
226
349
  }
227
350
  #else
228
- return rb_funcall(utf8_string, rb_intern("force_encoding"), 1, rb_const_get(rb_cEncoding, rb_intern("UTF_8")));
351
+ if (NIL_P(cEncoding))
352
+ {
353
+ init_encoding_vars();
354
+ }
355
+ if (contains_auxchar(StringValuePtr(utf8_string)))
356
+ {
357
+ utf8_string = encode_to_utf8(StringValuePtr(utf8_string));
358
+ }
359
+ return rb_funcall(utf8_string, rb_intern("force_encoding"), 1, encoding_utf8);
229
360
  #endif
230
361
  }
data/ext/rjb.c CHANGED
@@ -14,7 +14,7 @@
14
14
  *
15
15
  */
16
16
 
17
- #define RJB_VERSION "1.5.7"
17
+ #define RJB_VERSION "1.6.2"
18
18
 
19
19
  #include "ruby.h"
20
20
  #include "extconf.h"
@@ -102,7 +102,7 @@ static VALUE primitive_conversion = Qfalse;
102
102
  /*
103
103
  * Object cache, never destroyed
104
104
  */
105
- /* method */
105
+ /* method */
106
106
  static jmethodID method_getModifiers;
107
107
  static jmethodID method_getName;
108
108
  static jmethodID getParameterTypes;
@@ -229,7 +229,7 @@ static VALUE jstring2val(JNIEnv* jenv, jstring s)
229
229
  const char* p;
230
230
  VALUE v;
231
231
 
232
- if (s == NULL)
232
+ if (s == NULL)
233
233
  {
234
234
  return Qnil;
235
235
  }
@@ -317,7 +317,7 @@ static VALUE jv2rv_r(JNIEnv* jenv, jvalue val)
317
317
  Data_Get_Struct(v, struct jv_data, ptr);
318
318
  v = register_instance(jenv, v, (struct jv_data*)ptr, val.l);
319
319
  (*jenv)->DeleteLocalRef(jenv, klass);
320
- (*jenv)->DeleteLocalRef(jenv, val.l);
320
+ (*jenv)->DeleteLocalRef(jenv, val.l);
321
321
  return v;
322
322
  }
323
323
 
@@ -357,7 +357,7 @@ static VALUE jfloat2rv(JNIEnv* jenv, jvalue val)
357
357
 
358
358
  static VALUE jint2rv(JNIEnv* jenv, jvalue val)
359
359
  {
360
- return INT2NUM(val.i);
360
+ return INT2NUM(val.i);
361
361
  }
362
362
 
363
363
  static VALUE jlong2rv(JNIEnv* jenv, jvalue val)
@@ -393,13 +393,13 @@ static VALUE ja2r(J2R conv, JNIEnv* jenv, jvalue val, int depth)
393
393
  VALUE v;
394
394
  int i;
395
395
  if (!val.l) return Qnil;
396
- if (depth == 1)
396
+ if (depth == 1)
397
397
  {
398
398
  return conv(jenv, val);
399
399
  }
400
400
  len = (*jenv)->GetArrayLength(jenv, val.l);
401
401
  v = rb_ary_new2(len);
402
- for (i = 0; i < len; i++)
402
+ for (i = 0; i < len; i++)
403
403
  {
404
404
  jvalue wrap;
405
405
  wrap.l = (*jenv)->GetObjectArrayElement(jenv, val.l, i);
@@ -454,7 +454,7 @@ static VALUE la2rv(JNIEnv* jenv, void* p)
454
454
  return LL2NUM(*(jlong*)p);
455
455
  #else
456
456
  return LONG2NUM(*(jlong*)p);
457
- #endif
457
+ #endif
458
458
  }
459
459
 
460
460
  static VALUE sa2rv(JNIEnv* jenv, void* p)
@@ -498,7 +498,7 @@ static VALUE jbytearray2rv(JNIEnv* jenv, jvalue val)
498
498
  static VALUE jchararray2rv(JNIEnv* jenv, jvalue val)
499
499
  {
500
500
  jchar* p = (*jenv)->GetCharArrayElements(jenv, val.l, NULL);
501
- return call_conv(jenv, val, sizeof(jchar), p, ca2rv,
501
+ return call_conv(jenv, val, sizeof(jchar), p, ca2rv,
502
502
  offsetof(struct JNINativeInterface_, ReleaseCharArrayElements));
503
503
  }
504
504
  static VALUE jdoublearray2rv(JNIEnv* jenv, jvalue val)
@@ -557,14 +557,14 @@ static VALUE jbooleanarray2rv(JNIEnv* jenv, jvalue val)
557
557
  */
558
558
  static jprimitive_table jpcvt[] = {
559
559
  { "java/lang/Integer", "intValue", "()I", "(I)V", NULL, 0, 0, jint2rv, },
560
- { "java/lang/Long", "longValue", "()J", "(J)V", NULL, 0, 0, jlong2rv, },
560
+ { "java/lang/Long", "longValue", "()J", "(J)V", NULL, 0, 0, jlong2rv, },
561
561
  { "java/lang/Double", "doubleValue", "()D", "(D)V", NULL, 0, 0, jdouble2rv, },
562
562
  { "java/lang/Boolean", "booleanValue", "()Z", "(Z)Ljava/lang/Boolean;",
563
563
  NULL, 0, 0, jboolean2rv, },
564
564
  { "java/lang/Character", "charValue", "()C", NULL, NULL, 0, 0, jchar2rv, },
565
565
  { "java/lang/Short", "intValue", "()I", NULL, NULL, 0, 0, jint2rv, },
566
566
  { "java/lang/Byte", "intValue", "()I", NULL, NULL, 0, 0, jint2rv, },
567
- { "java/lang/Float", "doubleValue", "()D", NULL, NULL, 0, 0, jdouble2rv, },
567
+ { "java/lang/Float", "doubleValue", "()D", NULL, NULL, 0, 0, jdouble2rv, },
568
568
  };
569
569
 
570
570
  /*
@@ -669,7 +669,7 @@ static void rv2jfloat(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int
669
669
  static void rv2jint(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int release)
670
670
  {
671
671
  if (!release)
672
- jv->i = NUM2INT(val);
672
+ jv->i = NUM2INT(val);
673
673
  }
674
674
  static void rv2jlong(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int release)
675
675
  {
@@ -693,7 +693,7 @@ static void rv2jshort(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, int
693
693
  if (release) return;
694
694
  if (TYPE(val) == T_FIXNUM)
695
695
  {
696
- int n = FIX2INT(val);
696
+ int n = FIX2INT(val);
697
697
  if (abs(n) < 0x7fff)
698
698
  {
699
699
  jv->s = (short)n;
@@ -814,7 +814,7 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
814
814
  Data_Get_Struct(val, struct rj_bridge, ptr);
815
815
  jv->l = ptr->proxy;
816
816
  }
817
- else if (CLASS_INHERITED(rjbc, rb_obj_class(val)))
817
+ else if (CLASS_INHERITED(rjbc, rb_obj_class(val)))
818
818
  {
819
819
  struct jv_data* ptr;
820
820
  Data_Get_Struct(val, struct jv_data, ptr);
@@ -836,13 +836,13 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
836
836
  case T_ARRAY:
837
837
  jv->l = r2objarray(jenv, val, "Ljava/lang/Object;");
838
838
  break;
839
- #if HAVE_LONG_LONG
839
+ #if HAVE_LONG_LONG
840
840
  case T_BIGNUM:
841
841
  arg.j = rb_big2ll(val);
842
842
  jv->l = (*jenv)->NewObject(jenv, jpcvt[PRM_LONG].klass,
843
843
  jpcvt[PRM_LONG].ctr_id, arg);
844
844
  break;
845
- #endif
845
+ #endif
846
846
  case T_OBJECT:
847
847
  default:
848
848
  #if defined(DEBUG)
@@ -860,7 +860,7 @@ static void rv2jobject(JNIEnv* jenv, VALUE val, jvalue* jv, const char* psig, in
860
860
  }
861
861
  else
862
862
  {
863
- switch (TYPE(val))
863
+ switch (TYPE(val))
864
864
  {
865
865
  case T_STRING:
866
866
  case T_FLOAT:
@@ -1287,7 +1287,7 @@ static J2R get_j2r(JNIEnv* jenv, jobject cls, char* psig, char* pdepth, char* pp
1287
1287
  const char* cname;
1288
1288
  const char* jname = NULL;
1289
1289
  jstring nm = (*jenv)->CallObjectMethod(jenv, cls, rjb_class_getName);
1290
- rjb_check_exception(jenv, 0);
1290
+ rjb_check_exception(jenv, 0);
1291
1291
  cname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
1292
1292
 
1293
1293
  if (*cname == '[')
@@ -1391,7 +1391,7 @@ static void setup_methodbase(JNIEnv* jenv, struct cls_constructor* pm,
1391
1391
  static void register_methodinfo(struct cls_method* newpm, st_table* tbl)
1392
1392
  {
1393
1393
  struct cls_method* pm;
1394
-
1394
+
1395
1395
  if (st_lookup(tbl, newpm->name, (st_data_t*)&pm))
1396
1396
  {
1397
1397
  newpm->next = pm->next;
@@ -1434,7 +1434,7 @@ static int make_alias(const char* jname, char* rname)
1434
1434
  static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static_method)
1435
1435
  {
1436
1436
  struct cls_method* result;
1437
- struct cls_method* pm;
1437
+ struct cls_method* pm;
1438
1438
  const char* jname;
1439
1439
  int alias;
1440
1440
  jstring nm;
@@ -1450,12 +1450,12 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
1450
1450
  rjb_check_exception(jenv, 0);
1451
1451
  setup_methodbase(jenv, &result->basic, parama, param_count);
1452
1452
  nm = (*jenv)->CallObjectMethod(jenv, m, method_getName);
1453
- rjb_check_exception(jenv, 0);
1453
+ rjb_check_exception(jenv, 0);
1454
1454
  jname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
1455
1455
  rname = ALLOCA_N(char, strlen(jname) * 2 + 8);
1456
1456
  alias = make_alias(jname, rname);
1457
1457
  result->name = rb_intern(jname);
1458
- rjb_release_string(jenv, nm, jname);
1458
+ rjb_release_string(jenv, nm, jname);
1459
1459
  result->basic.id = (*jenv)->FromReflectedMethod(jenv, m);
1460
1460
  rjb_check_exception(jenv, 0);
1461
1461
  cls = (*jenv)->CallObjectMethod(jenv, m, getReturnType);
@@ -1470,7 +1470,7 @@ static void create_methodinfo(JNIEnv* jenv, st_table* tbl, jobject m, int static
1470
1470
  && (*rname == 'g' || *rname == 's') && *(rname + 1) == 'e' && *(rname + 2) == 't')
1471
1471
  {
1472
1472
  pm = clone_methodinfo(result);
1473
- if (*rname == 's')
1473
+ if (*rname == 's')
1474
1474
  {
1475
1475
  if (result->basic.arg_count == 1)
1476
1476
  {
@@ -1515,7 +1515,7 @@ static void create_fieldinfo(JNIEnv* jenv, st_table* tbl, jobject f, int readonl
1515
1515
  result = ALLOC(struct cls_field);
1516
1516
  memset(result, 0, sizeof(struct cls_field));
1517
1517
  nm = (*jenv)->CallObjectMethod(jenv, f, field_getName);
1518
- rjb_check_exception(jenv, 0);
1518
+ rjb_check_exception(jenv, 0);
1519
1519
  jname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
1520
1520
  result->name = rb_intern(jname);
1521
1521
  rjb_release_string(jenv, nm, jname);
@@ -1537,7 +1537,7 @@ static void create_fieldinfo(JNIEnv* jenv, st_table* tbl, jobject f, int readonl
1537
1537
  static void setup_constructors(JNIEnv* jenv, struct cls_constructor*** pptr, jobjectArray methods)
1538
1538
  {
1539
1539
  int i;
1540
- struct cls_constructor* pc;
1540
+ struct cls_constructor* pc;
1541
1541
  jsize mcount = (*jenv)->GetArrayLength(jenv, methods);
1542
1542
  struct cls_constructor** tbl = ALLOC_N(struct cls_constructor*, mcount + 1);
1543
1543
  *pptr = tbl;
@@ -1557,21 +1557,21 @@ static void setup_constructors(JNIEnv* jenv, struct cls_constructor*** pptr, job
1557
1557
  pc->id = (*jenv)->FromReflectedMethod(jenv, c);
1558
1558
  (*jenv)->DeleteLocalRef(jenv, c);
1559
1559
  }
1560
- tbl[mcount] = NULL;
1560
+ tbl[mcount] = NULL;
1561
1561
  }
1562
-
1562
+
1563
1563
  static void setup_methods(JNIEnv* jenv, st_table** tbl, st_table** static_tbl,
1564
1564
  jobjectArray methods)
1565
1565
  {
1566
1566
  int i;
1567
- jint modifier;
1567
+ jint modifier;
1568
1568
  jsize mcount = (*jenv)->GetArrayLength(jenv, methods);
1569
1569
  *tbl = st_init_numtable_with_size(mcount);
1570
1570
  *static_tbl = st_init_numtable();
1571
1571
  for (i = 0; i < mcount; i++)
1572
1572
  {
1573
1573
  jobject m = (*jenv)->GetObjectArrayElement(jenv, methods, i);
1574
- rjb_check_exception(jenv, 0);
1574
+ rjb_check_exception(jenv, 0);
1575
1575
  modifier = (*jenv)->CallIntMethod(jenv, m, method_getModifiers);
1576
1576
  if (!(modifier & ACC_STATIC))
1577
1577
  {
@@ -1588,13 +1588,13 @@ static void setup_methods(JNIEnv* jenv, st_table** tbl, st_table** static_tbl,
1588
1588
  static void setup_fields(JNIEnv* jenv, st_table** tbl, jobjectArray flds)
1589
1589
  {
1590
1590
  int i;
1591
- jint modifier;
1591
+ jint modifier;
1592
1592
  jsize fcount = (*jenv)->GetArrayLength(jenv, flds);
1593
1593
  *tbl = st_init_numtable_with_size(fcount);
1594
1594
  for (i = 0; i < fcount; i++)
1595
1595
  {
1596
1596
  jobject f = (*jenv)->GetObjectArrayElement(jenv, flds, i);
1597
- rjb_check_exception(jenv, 0);
1597
+ rjb_check_exception(jenv, 0);
1598
1598
  modifier = (*jenv)->CallIntMethod(jenv, f, field_getModifiers);
1599
1599
  create_fieldinfo(jenv, *tbl, f, modifier & ACC_FINAL, modifier & ACC_STATIC);
1600
1600
  (*jenv)->DeleteLocalRef(jenv, f);
@@ -1640,7 +1640,7 @@ static void load_constants(JNIEnv* jenv, jclass klass, VALUE self, jobjectArray
1640
1640
  rjb_check_exception(jenv, 0);
1641
1641
  jfid = (*jenv)->GetStaticFieldID(jenv, klass, cname, sigs);
1642
1642
  rjb_check_exception(jenv, 0);
1643
- switch (sig)
1643
+ switch (sig)
1644
1644
  {
1645
1645
  case 'D':
1646
1646
  jv.d = (*jenv)->GetStaticDoubleField(jenv, klass, jfid);
@@ -1670,14 +1670,14 @@ static void load_constants(JNIEnv* jenv, jclass klass, VALUE self, jobjectArray
1670
1670
  jv.l = (*jenv)->GetStaticObjectField(jenv, klass, jfid);
1671
1671
  break;
1672
1672
  }
1673
- pname = (char*)cname;
1673
+ pname = (char*)cname;
1674
1674
  if (!isupper(*cname))
1675
1675
  {
1676
1676
  pname = ALLOCA_N(char, strlen(cname) + 1);
1677
1677
  strcpy(pname, cname);
1678
1678
  *pname = toupper(*pname);
1679
- if (!isupper(*pname)
1680
- || rb_const_defined(rb_obj_class(self), rb_intern(pname)))
1679
+ if (!isupper(*pname)
1680
+ || rb_const_defined(rb_obj_class(self), rb_intern(pname)))
1681
1681
  {
1682
1682
  pname = NULL;
1683
1683
  }
@@ -1697,7 +1697,7 @@ static void setup_metadata(JNIEnv* jenv, VALUE self, struct jv_data* ptr, VALUE
1697
1697
  jmethodID mid;
1698
1698
  jobjectArray methods;
1699
1699
  jobjectArray flds;
1700
-
1700
+
1701
1701
  jclass klass = (*jenv)->GetObjectClass(jenv, ptr->idata.obj);
1702
1702
  ptr->idata.klass = (*jenv)->NewGlobalRef(jenv, klass);
1703
1703
  rjb_check_exception(jenv, 0);
@@ -1726,7 +1726,7 @@ static void setup_metadata(JNIEnv* jenv, VALUE self, struct jv_data* ptr, VALUE
1726
1726
  * def load(class_path = '', vmargs = [])
1727
1727
  * class_path: passes for the class dir and jar name
1728
1728
  * vmargs: strng array of vmarg (such as -Xrs)
1729
- *
1729
+ *
1730
1730
  * change in rjb 0.1.7, omit first argument for JNI version.
1731
1731
  * because I misunderstood the number means (JVM but JNI).
1732
1732
  */
@@ -1769,7 +1769,7 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
1769
1769
  rb_funcall(user_path, stradd, 1, rb_ary_entry(classpath, 0));
1770
1770
  }
1771
1771
  userpath = StringValueCStr(user_path);
1772
-
1772
+
1773
1773
  if (!NIL_P(vm_argv))
1774
1774
  {
1775
1775
  Check_Type(vm_argv, T_ARRAY);
@@ -1792,31 +1792,31 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
1792
1792
  RJB_LOAD_METHOD(getParameterTypes, jmethod, "getParameterTypes", "()[Ljava/lang/Class;");
1793
1793
  RJB_LOAD_METHOD(getReturnType, jmethod, "getReturnType", "()Ljava/lang/Class;");
1794
1794
  rjb_check_exception(jenv, 1);
1795
-
1795
+
1796
1796
  RJB_FIND_CLASS(jfield, "java/lang/reflect/Field");
1797
1797
  RJB_LOAD_METHOD(field_getModifiers, jfield, "getModifiers", "()I");
1798
1798
  RJB_LOAD_METHOD(field_getName, jfield, "getName", "()Ljava/lang/String;");
1799
1799
  RJB_LOAD_METHOD(field_getType, jfield, "getType", "()Ljava/lang/Class;");
1800
1800
  rjb_check_exception(jenv, 1);
1801
-
1801
+
1802
1802
  RJB_HOLD_CLASS(j_class, "java/lang/Class");
1803
1803
  RJB_LOAD_METHOD(rjb_class_getName, j_class, "getName", "()Ljava/lang/String;");
1804
1804
  rjb_check_exception(jenv, 1);
1805
-
1805
+
1806
1806
  RJB_HOLD_CLASS(rjb_j_throwable, "java/lang/Throwable");
1807
1807
  RJB_LOAD_METHOD(rjb_throwable_getMessage, rjb_j_throwable, "getMessage", "()Ljava/lang/String;");
1808
- rjb_check_exception(jenv, 1);
1808
+ rjb_check_exception(jenv, 1);
1809
1809
 
1810
1810
  RJB_HOLD_CLASS(j_string, "java/lang/String");
1811
1811
  RJB_LOAD_METHOD(str_tostring, j_string, "toString", "()Ljava/lang/String;");
1812
- rjb_check_exception(jenv, 1);
1812
+ rjb_check_exception(jenv, 1);
1813
1813
 
1814
1814
  RJB_HOLD_CLASS(j_object, "java/lang/Object");
1815
- rjb_check_exception(jenv, 1);
1815
+ rjb_check_exception(jenv, 1);
1816
1816
 
1817
1817
  RJB_HOLD_CLASS(j_url, "java/net/URL");
1818
1818
  RJB_LOAD_METHOD(url_new, j_url, "<init>", "(Ljava/lang/String;)V");
1819
- rjb_check_exception(jenv, 1);
1819
+ rjb_check_exception(jenv, 1);
1820
1820
 
1821
1821
  for (i = PRM_INT; i < PRM_LAST; i++)
1822
1822
  {
@@ -1840,7 +1840,7 @@ static VALUE rjb_s_load(int argc, VALUE* argv, VALUE self)
1840
1840
  rb_define_method(rb_singleton_class(jklass), "forName", rjb_class_forname, -1);
1841
1841
  rb_define_alias(rb_singleton_class(jklass), "for_name", "forName");
1842
1842
  rb_gc_register_address(&jklass);
1843
-
1843
+
1844
1844
  return Qnil;
1845
1845
  }
1846
1846
 
@@ -1874,7 +1874,7 @@ jobject get_systemloader(JNIEnv* jenv)
1874
1874
  RJB_HOLD_CLASS(j_classloader, "java/lang/ClassLoader");
1875
1875
  RJB_LOAD_STATIC_METHOD(get_system_classloader, j_classloader,
1876
1876
  "getSystemClassLoader", "()Ljava/lang/ClassLoader;");
1877
- rjb_check_exception(jenv, 1);
1877
+ rjb_check_exception(jenv, 1);
1878
1878
  }
1879
1879
  return (*jenv)->CallStaticObjectMethod(jenv, j_classloader, get_system_classloader);
1880
1880
  }
@@ -1908,7 +1908,7 @@ static VALUE rjb_s_unload(int argc, VALUE* argv, VALUE self)
1908
1908
  st_foreach(RHASH(rjb_loaded_classes)->tbl, clear_classes, 0);
1909
1909
  #endif
1910
1910
  #endif
1911
-
1911
+
1912
1912
  if (rjb_jvm)
1913
1913
  {
1914
1914
  JNIEnv* jenv = rjb_attach_current_thread();
@@ -1990,10 +1990,10 @@ static VALUE rjb_delete_ref(struct jvi_data* ptr)
1990
1990
  */
1991
1991
  static VALUE rj_bridge_free(struct rj_bridge* ptr)
1992
1992
  {
1993
- JNIEnv* jenv = rjb_attach_current_thread();
1993
+ JNIEnv* jenv = rjb_attach_current_thread();
1994
1994
  if (jenv)
1995
1995
  {
1996
- (*jenv)->DeleteLocalRef(jenv, ptr->proxy);
1996
+ (*jenv)->DeleteLocalRef(jenv, ptr->proxy);
1997
1997
  (*jenv)->DeleteLocalRef(jenv, ptr->bridge);
1998
1998
  }
1999
1999
  return Qnil;
@@ -2015,7 +2015,7 @@ static VALUE rjb_s_free(struct jv_data* ptr)
2015
2015
  /* class never delete
2016
2016
  JNIEnv* jenv = rjb_attach_current_thread();
2017
2017
  struct cls_constructor** c;
2018
-
2018
+
2019
2019
  rjb_delete_ref(&ptr->idata);
2020
2020
  if (ptr->constructors)
2021
2021
  {
@@ -2030,7 +2030,7 @@ static VALUE rjb_s_free(struct jv_data* ptr)
2030
2030
  st_foreach(ptr->idata.methods, (int(*)())free_method_item, 0);
2031
2031
  st_free_table(ptr->idata.methods);
2032
2032
  }
2033
- (*jenv)->DeleteGlobalRef(jenv, ptr->idata.klass);
2033
+ (*jenv)->DeleteGlobalRef(jenv, ptr->idata.klass);
2034
2034
  st_delete(RHASH(rjb_loaded_classes)->tbl, clsname, NULL);
2035
2035
  */
2036
2036
  return Qnil;
@@ -2049,7 +2049,7 @@ static VALUE createinstance(JNIEnv* jenv, int argc, VALUE* argv,
2049
2049
  struct jv_data* jklass;
2050
2050
  struct jvi_data* org;
2051
2051
  jvalue* args = (argc) ? ALLOCA_N(jvalue, argc) : NULL;
2052
-
2052
+
2053
2053
  Data_Get_Struct(self, struct jv_data, jklass);
2054
2054
  org = &jklass->idata;
2055
2055
 
@@ -2087,7 +2087,7 @@ static VALUE import_class(JNIEnv* jenv, jclass jcls, VALUE clsname)
2087
2087
  char* nm = ALLOCA_N(char, strlen(pclsname) + 1);
2088
2088
  strcpy(nm, pclsname);
2089
2089
  *nm = toupper(*nm);
2090
- for (pclsname = nm; *pclsname; pclsname++)
2090
+ for (pclsname = nm; *pclsname; pclsname++)
2091
2091
  {
2092
2092
  if (*pclsname == '.')
2093
2093
  {
@@ -2116,7 +2116,7 @@ static VALUE rjb_a_missing(int argc, VALUE* argv, VALUE self)
2116
2116
 
2117
2117
  static VALUE rjb_i_prepare_proxy(VALUE self)
2118
2118
  {
2119
- return rb_funcall(self, rb_intern("instance_eval"), 1,
2119
+ return rb_funcall(self, rb_intern("instance_eval"), 1,
2120
2120
  rb_str_new2("instance_eval(&" USER_INITIALIZE ")"));
2121
2121
  }
2122
2122
 
@@ -2175,7 +2175,7 @@ static int check_rtype(JNIEnv* jenv, VALUE* pv, char* p)
2175
2175
  if (strchr("IJ", *p)) return SOSO;
2176
2176
  return strchr("BCDFS", *p) != NULL;
2177
2177
  case T_BIGNUM:
2178
- return strchr("BCDFIJS", *p) != NULL;
2178
+ return strchr("BCDFIJS", *p) != NULL;
2179
2179
  case T_FLOAT:
2180
2180
  if (*p == 'D') return SOSO;
2181
2181
  if (*p == 'F') return SATISFIED;
@@ -2298,7 +2298,7 @@ static VALUE rjb_newinstance(int argc, VALUE* argv, VALUE self)
2298
2298
  int weight = 0;
2299
2299
  int cweight;
2300
2300
  JNIEnv* jenv = rjb_prelude();
2301
-
2301
+
2302
2302
  Data_Get_Struct(self, struct jv_data, ptr);
2303
2303
 
2304
2304
  if (ptr->constructors)
@@ -2378,7 +2378,7 @@ jclass rjb_find_class(JNIEnv* jenv, VALUE name)
2378
2378
  {
2379
2379
  char* cname;
2380
2380
  char* jnicls;
2381
-
2381
+
2382
2382
  Check_Type(name, T_STRING);
2383
2383
  cname = StringValueCStr(name);
2384
2384
  jnicls = ALLOCA_N(char, strlen(cname) + 1);
@@ -2455,8 +2455,8 @@ static VALUE rjb_s_bind(VALUE self, VALUE rbobj, VALUE itfname)
2455
2455
  VALUE result = Qnil;
2456
2456
  jclass itf;
2457
2457
  JNIEnv* jenv = rjb_prelude();
2458
-
2459
- itf = rjb_find_class(jenv, itfname);
2458
+
2459
+ itf = rjb_find_class(jenv, itfname);
2460
2460
  rjb_check_exception(jenv, 1);
2461
2461
  if (itf)
2462
2462
  {
@@ -2582,7 +2582,7 @@ static jobject conv_jarname_to_url(JNIEnv* jenv, VALUE jarname)
2582
2582
  #if defined(DOSISH)
2583
2583
  if (strlen(jarp) > 1 && jarp[1] == ':')
2584
2584
  {
2585
- sprintf(urlp, "file:///%s", jarp);
2585
+ sprintf(urlp, "file:///%s", jarp);
2586
2586
  }
2587
2587
  else
2588
2588
  #endif
@@ -2604,7 +2604,7 @@ static jobject conv_jarname_to_url(JNIEnv* jenv, VALUE jarname)
2604
2604
  }
2605
2605
  #endif
2606
2606
  arg.l = (*jenv)->NewStringUTF(jenv, urlp);
2607
- rjb_check_exception(jenv, 0);
2607
+ rjb_check_exception(jenv, 0);
2608
2608
  url = (*jenv)->NewObject(jenv, j_url, url_new, arg);
2609
2609
  rjb_check_exception(jenv, 0);
2610
2610
  return url;
@@ -2657,7 +2657,7 @@ static VALUE rjb_s_add_jar(VALUE self, VALUE jarname)
2657
2657
  if (!url_loader)
2658
2658
  {
2659
2659
  args[0].l = (*jenv)->NewObjectArray(jenv, (jsize)((count == 0) ? 1 : count), j_url, NULL);
2660
- rjb_check_exception(jenv, 0);
2660
+ rjb_check_exception(jenv, 0);
2661
2661
  if (!count)
2662
2662
  {
2663
2663
  (*jenv)->SetObjectArrayElement(jenv, args[0].l, 0,
@@ -2732,7 +2732,7 @@ static VALUE rjb_i_class(VALUE self)
2732
2732
  static VALUE getter(JNIEnv* jenv, struct cls_field* pf, struct jvi_data* ptr)
2733
2733
  {
2734
2734
  jvalue jv;
2735
- switch (pf->result_signature)
2735
+ switch (pf->result_signature)
2736
2736
  {
2737
2737
  case 'D':
2738
2738
  if (pf->static_field)
@@ -2839,7 +2839,7 @@ static void setter(JNIEnv* jenv, struct cls_field* pf, struct jvi_data* ptr, VA
2839
2839
  {
2840
2840
  jvalue jv;
2841
2841
  pf->arg_convert(jenv, val, &jv, pf->field_signature, 0);
2842
- switch (*pf->field_signature)
2842
+ switch (*pf->field_signature)
2843
2843
  {
2844
2844
  case 'D':
2845
2845
  if (pf->static_field)
@@ -2960,7 +2960,7 @@ static VALUE invoke(JNIEnv* jenv, struct cls_method* pm, struct jvi_data* ptr,
2960
2960
  found = 0;
2961
2961
  if (argc == pm->basic.arg_count)
2962
2962
  {
2963
- if (sig && pm->basic.method_signature)
2963
+ if (sig && pm->basic.method_signature)
2964
2964
  {
2965
2965
  if (!strcmp(sig, pm->basic.method_signature))
2966
2966
  {
@@ -2999,7 +2999,7 @@ static VALUE invoke(JNIEnv* jenv, struct cls_method* pm, struct jvi_data* ptr,
2999
2999
  if (!prefer_pm)
3000
3000
  {
3001
3001
  const char* tname = rb_id2name(orgpm->name);
3002
- if (sig)
3002
+ if (sig)
3003
3003
  {
3004
3004
  rb_raise(rb_eRuntimeError, "Fail: unknown method name `%s(\'%s\')'", tname, sig);
3005
3005
  }
@@ -3092,7 +3092,7 @@ static VALUE invoke_by_instance(ID rmid, int argc, VALUE* argv,
3092
3092
  {
3093
3093
  ret = getter(jenv, pf, ptr);
3094
3094
  }
3095
- else
3095
+ else
3096
3096
  {
3097
3097
  if (argc == 1 && *(tname + strlen(tname) - 1) == '=')
3098
3098
  {
@@ -3154,7 +3154,7 @@ static VALUE rjb_i_missing(int argc, VALUE* argv, VALUE self)
3154
3154
  ID rmid = rb_to_id(argv[0]);
3155
3155
 
3156
3156
  Data_Get_Struct(self, struct jvi_data, ptr);
3157
-
3157
+
3158
3158
  return invoke_by_instance(rmid, argc -1, argv + 1, ptr, NULL);
3159
3159
  }
3160
3160
 
@@ -3217,7 +3217,7 @@ static VALUE invoke_by_class(ID rmid, int argc, VALUE* argv,
3217
3217
  rb_raise(rb_eRuntimeError, "Fail: unknown method name `%s'", tname);
3218
3218
  }
3219
3219
  }
3220
-
3220
+
3221
3221
  return ret;
3222
3222
  }
3223
3223
 
@@ -3259,7 +3259,7 @@ static VALUE rjb_missing(int argc, VALUE* argv, VALUE self)
3259
3259
  return r;
3260
3260
  }
3261
3261
  }
3262
-
3262
+
3263
3263
  Data_Get_Struct(self, struct jv_data, ptr);
3264
3264
  return invoke_by_class(rmid, argc - 1, argv + 1, ptr, NULL);
3265
3265
  }
@@ -3293,7 +3293,7 @@ void Init_rjbcore()
3293
3293
  #else
3294
3294
  rb_protect((VALUE(*)(VALUE))rb_require, (VALUE)"iconv", NULL);
3295
3295
  #endif
3296
- #endif
3296
+ #endif
3297
3297
  rjb_loaded_classes = rb_hash_new();
3298
3298
  #ifndef RUBINIUS
3299
3299
  OBJ_FREEZE(rjb_loaded_classes);
@@ -3323,7 +3323,7 @@ void Init_rjbcore()
3323
3323
  rb_define_class_variable(rjb, "@@classpath", rb_ary_new());
3324
3324
  cvar_classpath = rb_intern("@@classpath");
3325
3325
 
3326
- /* Java class object */
3326
+ /* Java class object */
3327
3327
  rjbc = CLASS_NEW(rb_cObject, "Rjb_JavaClass");
3328
3328
  rb_gc_register_address(&rjbc);
3329
3329
  rb_define_method(rjbc, "method_missing", rjb_missing, -1);
@@ -3334,7 +3334,7 @@ void Init_rjbcore()
3334
3334
  /* Java instance object */
3335
3335
  rjbi = CLASS_NEW(rb_cObject, "Rjb_JavaProxy");
3336
3336
  rb_gc_register_address(&rjbi);
3337
- rb_define_method(rjbi, "method_missing", rjb_i_missing, -1);
3337
+ rb_define_method(rjbi, "method_missing", rjb_i_missing, -1);
3338
3338
  rb_define_method(rjbi, "_invoke", rjb_i_invoke, -1);
3339
3339
  rb_define_method(rjbi, "_classname", rjb_i_class, 0);
3340
3340
  rb_define_method(rjbi, "_prepare_proxy", rjb_i_prepare_proxy, 0);
@@ -26,11 +26,37 @@
26
26
  #include "riconv.h"
27
27
  #include "rjb.h"
28
28
 
29
+ static VALUE missing_delegate(int argc, VALUE* argv, VALUE self)
30
+ {
31
+ ID rmid = rb_to_id(argv[0]);
32
+ return rb_funcallv(rb_ivar_get(self, rb_intern("@cause")), rmid, argc - 1, argv + 1);
33
+ }
34
+
29
35
  static VALUE get_cause(VALUE self)
30
36
  {
31
37
  return rb_funcall(rb_ivar_get(self, rb_intern("@cause")), rb_intern("cause"), 0);
32
38
  }
33
39
 
40
+ static VALUE ex_respond_to(int argc, VALUE* argv, VALUE self)
41
+ {
42
+ if (argc < 1 || argc > 2)
43
+ {
44
+ rb_raise(rb_eArgError, "respond_to? require 1 or 2 arguments");
45
+ }
46
+ if (rb_to_id(argv[0]) == rb_intern("to_str"))
47
+ {
48
+ return Qfalse;
49
+ }
50
+ else if (rb_to_id(argv[0]) == rb_intern("exception"))
51
+ {
52
+ return Qtrue;
53
+ }
54
+ else
55
+ {
56
+ return rb_funcallv(rb_ivar_get(self, rb_intern("@cause")), rb_intern("respond_to?"), argc, argv);
57
+ }
58
+ }
59
+
34
60
  /*
35
61
  * handle Java exception
36
62
  * At this time, the Java exception is defined without the package name.
@@ -60,6 +86,8 @@ VALUE rjb_get_exception_class(JNIEnv* jenv, jstring str)
60
86
  {
61
87
  rexp = rb_define_class(pcls, rb_eStandardError);
62
88
  rb_define_method(rexp, "cause", get_cause, 0);
89
+ rb_define_method(rexp, "method_missing", missing_delegate, -1);
90
+ rb_define_method(rexp, "respond_to?", ex_respond_to, -1);
63
91
  #if defined(HAVE_RB_HASH_ASET) || defined(RUBINIUS)
64
92
  rb_hash_aset(rjb_loaded_classes, cname, rexp);
65
93
  #else
@@ -69,7 +97,7 @@ VALUE rjb_get_exception_class(JNIEnv* jenv, jstring str)
69
97
  st_insert(RHASH(rjb_loaded_classes)->tbl, cname, rexp);
70
98
  #endif
71
99
  #endif
72
-
100
+
73
101
  }
74
102
  return rexp;
75
103
  }
@@ -81,7 +109,7 @@ VALUE rjb_s_throw(int argc, VALUE* argv, VALUE self)
81
109
  {
82
110
  VALUE klass;
83
111
  VALUE message;
84
- JNIEnv* jenv = NULL;
112
+ JNIEnv* jenv = NULL;
85
113
 
86
114
  rjb_load_vm_default();
87
115
 
data/lib/rjb.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  =begin
2
- Copyright(c) 2006-2010,2012 arton
2
+ Copyright(c) 2006-2010,2012,2020 arton
3
3
  =end
4
4
 
5
5
  require 'rbconfig'
@@ -86,7 +86,7 @@ module Rjb
86
86
  (org + klass.getMethods.select do |m|
87
87
  blk.call(m)
88
88
  end.map do |m|
89
- m.name
89
+ m.name.to_sym
90
90
  end).uniq
91
91
  end
92
92
  def format_sigs(s)
@@ -98,6 +98,19 @@ module Rjb
98
98
  "[#{s.map{|m|m.nil? ? 'void' : m}.join(', ')}]"
99
99
  end
100
100
  end
101
+ def make_snake(nm)
102
+ nm.gsub(/(.)([A-Z])/) { "#{$1}_#{$2.downcase}" }
103
+ end
104
+ alias :rjb_org_respond_to? :respond_to?
105
+ def rjb_respond_to?(sym, klass, priv)
106
+ return true if (klass ? self : getClass).getMethods.select do |m|
107
+ (klass && !instance_method?(m) && (priv || public_method?(m))) ||
108
+ (!klass && instance_method?(m) && (priv || public_method?(m)))
109
+ end.map do |m|
110
+ [m.name.to_sym, make_snake(m.name).to_sym]
111
+ end.flatten.include?(sym.to_sym)
112
+ rjb_org_respond_to?(sym, priv)
113
+ end
101
114
  end
102
115
 
103
116
  class Rjb_JavaClass
@@ -119,6 +132,9 @@ module Rjb
119
132
  "#{m}(#{format_sigs(self.static_sigs(m))})"
120
133
  end
121
134
  end
135
+ def respond_to?(sym, priv = false)
136
+ rjb_respond_to?(sym, true, priv)
137
+ end
122
138
  end
123
139
  class Rjb_JavaProxy
124
140
  include JMethod
@@ -141,6 +157,9 @@ module Rjb
141
157
  "#{m}(#{format_sigs(getClass.sigs(m))})"
142
158
  end
143
159
  end
160
+ def respond_to?(sym, priv = false)
161
+ rjb_respond_to?(sym, false, priv)
162
+ end
144
163
  end
145
164
  class Rjb_JavaBridge
146
165
  def method_missing(name, *args)
@@ -216,17 +216,28 @@ class TestRjb < Test::Unit::TestCase
216
216
  end
217
217
 
218
218
  def test_combination_charcters
219
- teststr = "\xc7\x96\xc3\xbc\xcc\x84\x75\xcc\x88\xcc\x84\xed\xa1\xa9\xed\xba\xb2\xe3\x81\x8b\xe3\x82\x9a"
219
+ teststr = "\xc7\x96\xc3\xbc\xcc\x84\x75\xcc\x88\xcc\x84𪚲\xe3\x81\x8b\xe3\x82\x9a"
220
220
  test = import('jp.co.infoseek.hp.arton.rjb.Test').new
221
221
  s = test.getUmlaut()
222
222
  if Object::const_defined?(:Encoding) #>=1.9
223
- teststr = teststr.force_encoding(Encoding::UTF_8)
224
- assert_equal(s, teststr)
223
+ =begin
224
+ n = [teststr.bytes.length, s.bytes.length].max
225
+ puts "org:#{teststr.bytes.length}, ret:#{s.bytes.length}"
226
+ 0.upto(n - 1) do |i|
227
+ b0 = teststr.getbyte(i)
228
+ b0 = 0 unless b0
229
+ b1 = s.getbyte(i)
230
+ b1 = 0 unless b1
231
+ puts sprintf("%02X - %02X\n", b0, b1)
232
+ end
233
+ =end
234
+ assert_equal(teststr.bytes.length, s.bytes.length)
235
+ assert_equal(teststr, s)
225
236
  else
226
237
  default_kcode = $KCODE
227
238
  begin
228
239
  $KCODE = "utf8"
229
- assert_equal(s, teststr)
240
+ assert_equal(teststr, s)
230
241
  ensure
231
242
  $KCODE = default_kcode
232
243
  end
@@ -715,19 +726,19 @@ class TestRjb < Test::Unit::TestCase
715
726
  end
716
727
  def test_methods_extension
717
728
  m = @jString.new('').methods
718
- assert m.include?('indexOf')
729
+ assert m.include?(:indexOf)
719
730
  end
720
731
  def test_class_methods_extension
721
732
  m = @jString.methods
722
- assert m.include?('format')
733
+ assert m.include?(:format)
723
734
  end
724
735
  def test_pmethods_extension
725
736
  m = @jString.new('').public_methods
726
- assert m.include?('indexOf')
737
+ assert m.include?(:indexOf)
727
738
  end
728
739
  def test_class_pmethods_extension
729
740
  m = @jString.public_methods
730
- assert m.include?('format')
741
+ assert m.include?(:format)
731
742
  end
732
743
  def test_java_methods
733
744
  indexof = @jString.new('').java_methods.find do |m|
@@ -933,5 +944,36 @@ class TestRjb < Test::Unit::TestCase
933
944
  assert_equal org.size, len
934
945
  assert_equal org, buffer[0...len]
935
946
  end
936
- end
937
947
 
948
+ def test_re_raise
949
+ begin
950
+ @jInteger.parseInt('blabla')
951
+ flunk('no exception')
952
+ rescue NumberFormatException => e
953
+ begin
954
+ raise
955
+ rescue => e
956
+ assert_equal(NumberFormatException, e.class)
957
+ # OK
958
+ end
959
+ end
960
+ end
961
+
962
+ def test_java_utf8
963
+ y = @jString.new('𠮷野家')
964
+ assert_equal '𠮷野家', y.toString
965
+ end
966
+
967
+ def test_respond_to
968
+ str = @jString.new('blabla')
969
+ assert str.respond_to? :substring
970
+ assert_false str.respond_to? :unknown_method
971
+ begin
972
+ @jInteger.parseInt('blabla')
973
+ rescue => e
974
+ assert e.respond_to? :print_stack_trace
975
+ assert e.respond_to? :printStackTrace
976
+ assert_false e.respond_to? :unknown_method
977
+ end
978
+ end
979
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.7
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - arton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-27 00:00:00.000000000 Z
11
+ date: 2020-08-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'RJB is a bridge program that connect between Ruby and Java with Java
14
14
  Native Interface.
@@ -24,7 +24,7 @@ files:
24
24
  - ChangeLog
25
25
  - data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class
26
26
  - ext/RBridge.java
27
- - ext/depend
27
+ - ext/depend.erb
28
28
  - ext/extconf.h
29
29
  - ext/extconf.rb
30
30
  - ext/jniwrap.h
@@ -74,7 +74,7 @@ files:
74
74
  - test/x.rb
75
75
  homepage: https://www.artonx.org/collabo/backyard/?RubyJavaBridge
76
76
  licenses:
77
- - LGPL
77
+ - LGPL-2.1-or-later
78
78
  metadata: {}
79
79
  post_install_message:
80
80
  rdoc_options: []
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - none
95
95
  - JDK 5.0
96
- rubygems_version: 3.0.1
96
+ rubygems_version: 3.1.2
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: Ruby Java bridge