rjb 1.0.9-mswin32 → 1.0.11-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,21 @@
1
+ Fri Nov 9 arton
2
+ *test.rb
3
+ *Test.java
4
+ add test for reproducing rjb-bugs-15430
5
+ *rjb.c
6
+ fix rjb-bugs-15430 that caused by bad array conversion.
7
+ (generics method result signature is an object, but the real result is typed array)
8
+ *riconv.c
9
+ correct to get the number of array element.
10
+ Tue Oct 23 Kuwashima
11
+ *riconv.c
12
+ Change string encoding conversion rule.
13
+ Mon Oct 22 Kuwashima
14
+ *riconv.c
15
+ *riconv.h
16
+ recycle iconv instance.
17
+ *test/test.rb
18
+ add cases for test_kjconv
1
19
  Sun Sep 23 arton
2
20
  *rjb.c
3
21
  version 1.0.9
data/ext/extconf.h ADDED
@@ -0,0 +1,6 @@
1
+ #ifndef EXTCONF_H
2
+ #define EXTCONF_H
3
+ #define HAVE_JNI_H 1
4
+ #define HAVE_SETLOCALE 1
5
+ #define HAVE_GETENV 1
6
+ #endif
data/ext/riconv.c CHANGED
@@ -12,144 +12,179 @@
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 4 2006-09-11 15:21:38Z arton $
15
+ * $Id: riconv.c 37 2007-11-08 17:25:36Z arton $
16
16
  */
17
17
 
18
18
  #include "ruby.h"
19
+ #include "extconf.h"
20
+
21
+ #if defined _WIN32 || defined __CYGWIN__
22
+ #include <windows.h>
23
+ #endif
24
+
25
+ #if defined HAVE_NL_LANGINFO
26
+ #include <langinfo.h>
27
+ static const char* const NL_EUC_TABLE[] = { "EUC-JISX0213", "EUC-JP", "EUC-JP-MS" };
28
+ static const char* const NL_SJIS_TABLE[] = { "SHIFT_JIS", "SHIFT_JISX0213", "WINDOWS-31J" };
29
+ #endif
30
+
31
+ #if defined HAVE_SETLOCALE
32
+ #include <locale.h>
33
+ static const char* const LOCALE_EUC_TABLE[] = { "japanese", "ja_JP.eucJP", "japanese.euc", "ja_JP", "ja_JP.ujis" };
34
+ static const char* const LOCALE_SJIS_TABLE[] = { "japanese.sjis", "ja_JP.SJIS" };
35
+ static const char* const LOCALE_UTF8_TABLE[] = { "ja_JP.UTF-8", "ja_JP.utf8" };
36
+ #endif
37
+
19
38
  #include "riconv.h"
20
39
 
21
- static const char* cs_eucjp = "EUC-JP";
22
- static const char* cs_sjis = "Shift_JIS";
23
- static const char* cs_cp932 = "CP932";
24
- static const char* cs_ms932 = "MS932";
25
- static const char* cs_utf8 = "UTF-8";
40
+ static const char* const CS_EUCJP = "EUC-JP";
41
+ static const char* const CS_CP932 = "CP932";
42
+ static const char* const CS_SJIS = "SHIFT_JIS";
43
+ static const char* const CS_UTF8 = "UTF-8";
44
+
45
+
46
+ static VALUE objIconvJ2R;
47
+ static VALUE objIconvR2J;
48
+ static const char* charcode; //is this necessary?
49
+ static char Kcode = '\0';
26
50
 
27
- /* Regexp::match�̃��b�p�[ */
28
- static int regxp_is_match(VALUE str, VALUE regxp)
51
+ static int find_table(const char* const str, const char* const table[])
29
52
  {
30
- return rb_funcall(str, rb_intern("match"), 1, RREGEXP(regxp)) != Qnil ? 1 : 0 ;
53
+ int i;
54
+ int size = sizeof(table) / sizeof(table[0]);
55
+ for (i = 0; i < size; ++i)
56
+ {
57
+ if (strstr(str, table[i])) return 1;
58
+ }
59
+ return 0;
31
60
  }
32
61
 
33
- /* RUBY_PLATFORM����ސ�����Windows�Ȃ�1���A�����łȂ����0��Ԃ� */
34
- static int platform_is_windows()
62
+ static const char* get_charcode_name_by_locale(const char* const name)
35
63
  {
36
- VALUE platform = rb_const_get(rb_cObject, rb_intern("RUBY_PLATFORM"));
37
- return regxp_is_match(platform, rb_str_new2("msvcrt|mswin|bccwin|mingw|cygwin"))
38
- ? 1
39
- : 0;
64
+ if (find_table(name, LOCALE_UTF8_TABLE))
65
+ return NULL;
66
+ else if (find_table(name, LOCALE_EUC_TABLE))
67
+ return CS_EUCJP;
68
+ else if (find_table(name, LOCALE_SJIS_TABLE))
69
+ return CS_SJIS;
70
+ else
71
+ return NULL;
40
72
  }
41
-
42
73
  /*
43
- * RUBY_PLATFORM��$KCODE������Iconv�ŗL���ȓK���ȕ����R�[�h����Ԃ�
44
- * TODO: ���s�‹���LOCALE,LANG,LC_ALL�����Q�l�ɂ���
74
+ * Get better charcode name.
45
75
  */
46
- static char* get_charset_name()
76
+ static const char* get_charcode_name()
47
77
  {
48
- char* result = NULL;
49
- ID id_Iconv = rb_intern("Iconv");
50
-
51
- if (rb_const_defined(rb_cObject, id_Iconv))
52
- {
53
- VALUE kcode = rb_gv_get("$KCODE");
54
- VALUE platform = rb_const_get(rb_cObject, rb_intern("RUBY_PLATFORM"));
55
- char* kcodep = (TYPE(kcode) == T_STRING) ? StringValuePtr(kcode) : "";
56
-
57
- switch(toupper(*kcodep))
58
- {
59
- case 'E':
60
- result = (char*)cs_eucjp;
61
- break;
62
- case 'S':
63
- if (platform_is_windows())
64
- {
65
- result = (char*)cs_cp932;
66
- }
67
- else
68
- {
69
- result = (char*)cs_sjis;
70
- }
71
- break;
72
- case 'N':
73
- if (platform_is_windows())
74
- {
75
- result = (char*)cs_cp932;
76
- }
77
- else
78
- {
79
- result = NULL;
80
- }
81
- break;
82
- case 'U':
83
- default:
84
- result = NULL;
85
- break;
86
- }
87
- }else{
88
- result = NULL;
89
- }
78
+ const char* result = NULL;
79
+ const char* lang = NULL;
80
+
81
+ switch(Kcode)
82
+ {
83
+ case 'E':
84
+ result = CS_EUCJP;
85
+ break;
86
+ case 'S':
87
+ #if defined _WIN32 || defined __CYGWIN__
88
+ result = CS_CP932;
89
+ #else
90
+ result = CS_SJIS;
91
+ #endif
92
+ break;
93
+ case 'U':
94
+ //as is.
95
+ break;
96
+ case 'N':
97
+ default:
98
+ #if defined _WIN32 || defined __CYGWIN__
99
+ if (932 == GetACP()) result = CS_CP932;
100
+ #elif defined HAVE_NL_LANGINFO
101
+ setlocale(LC_ALL, ""); //initialize
102
+ lang = nl_langinfo(CODESET);
103
+ if (find_table(lang, NL_EUC_TABLE))
104
+ result = CS_EUCJP;
105
+ else if (find_table(lang, NL_SJIS_TABLE))
106
+ result = CS_SJIS;
107
+ #elif defined HAVE_SETLOCALE
108
+ setlocale(LC_ALL, ""); //initialize
109
+ result = get_charcode_name_by_locale(setlocale(LC_ALL, NULL));
110
+ #elif defined HAVE_GETENV
111
+ printf("HAVE_GETENV\n");
112
+ if (result = get_charcode_name_by_locale(getenv("LC_ALL")))
113
+ ;
114
+ else if (result = get_charcode_name_by_locale(getenv("LC_CTYPE")))
115
+ ;
116
+ else if (result = get_charcode_name_by_locale(getenv("LANG")))
117
+ ;
118
+ #endif
119
+ break;
120
+ }
90
121
  return result;
91
122
  }
92
123
 
93
- /*
94
- * �g�����C�u������Iconv������ꍇ��1,�Ȃ��ꍇ��0��Ԃ�
95
- */
96
- static int has_exticonv()
97
- {
98
- ID id_Iconv = rb_intern("Iconv");
99
- VALUE Iconv = rb_const_get(rb_cObject, id_Iconv);
100
- if(Iconv == Qnil)
101
- {
102
- return 0;
103
- }
104
- else
105
- {
106
- return 1;
107
- }
108
- }
109
124
 
110
- VALUE exticonv_local_to_utf8(VALUE local_string)
125
+ static void reinit()
111
126
  {
112
- char* cs = get_charset_name();
113
- if(cs)
114
- {
115
- return exticonv_cc(local_string, cs, cs_utf8);
116
- }
117
- else
118
- {
119
- return local_string;
120
- }
127
+ charcode = get_charcode_name();
128
+ if (charcode)
129
+ {
130
+ VALUE rb_iconv_klass = rb_const_get(rb_cObject, rb_intern("Iconv"));
131
+ if (RTEST(rb_iconv_klass)) {
132
+ ID sym_new = rb_intern("new");
133
+ rb_gc_unregister_address(&objIconvR2J);
134
+ objIconvR2J = rb_funcall(rb_iconv_klass, sym_new, 2, rb_str_new2(CS_UTF8), rb_str_new2(charcode));
135
+ rb_gc_register_address(&objIconvR2J);
136
+ rb_gc_unregister_address(&objIconvJ2R);
137
+ objIconvJ2R = rb_funcall(rb_iconv_klass, sym_new, 2, rb_str_new2(charcode), rb_str_new2(CS_UTF8));
138
+ rb_gc_register_address(&objIconvJ2R);
139
+ }
140
+ }
141
+ else
142
+ {
143
+ objIconvR2J = objIconvJ2R = Qnil;
144
+ }
121
145
  }
122
146
 
123
- VALUE exticonv_utf8_to_local(VALUE utf8_string)
147
+ static void check_kcode()
124
148
  {
125
- char* cs = get_charset_name();
126
- if(cs)
127
- {
128
- return exticonv_cc(utf8_string, cs_utf8, cs);
129
- }
130
- else
131
- {
132
- return utf8_string;
133
- }
149
+ VALUE rb_iconv_klass = rb_const_get(rb_cObject, rb_intern("Iconv"));
150
+ VALUE kcode = rb_gv_get("$KCODE");
151
+ if (RTEST(rb_iconv_klass) && TYPE(kcode) == T_STRING) {
152
+ char* kcodep = StringValuePtr(kcode);
153
+ char upper_kcode = toupper(*kcodep);
154
+ if (Kcode != upper_kcode)
155
+ {
156
+ Kcode = upper_kcode;
157
+ reinit();
158
+ }
159
+ }
160
+ else
161
+ {
162
+ objIconvR2J = objIconvJ2R = Qnil;
163
+ }
134
164
  }
135
165
 
136
- VALUE exticonv_cc(VALUE original_string, const char* from, const char* to)
166
+ VALUE exticonv_local_to_utf8(VALUE local_string)
137
167
  {
138
- return exticonv_vv(original_string, rb_str_new2(from), rb_str_new2(to));
168
+ check_kcode();
169
+ if(RTEST(objIconvR2J))
170
+ {
171
+ return rb_funcall(objIconvR2J, rb_intern("iconv"), 1, local_string);
172
+ }
173
+ else
174
+ {
175
+ return local_string;
176
+ }
139
177
  }
140
178
 
141
- VALUE exticonv_vv(VALUE original_string, VALUE from, VALUE to)
179
+ VALUE exticonv_utf8_to_local(VALUE utf8_string)
142
180
  {
143
- if(has_exticonv())
144
- {
145
- ID id_Iconv = rb_intern("Iconv");
146
- ID id_iconv = rb_intern("iconv");
147
- VALUE Iconv = rb_const_get(rb_cObject, id_Iconv);
148
- return rb_ary_entry(rb_funcall(Iconv, id_iconv, 3, to, from, original_string), 0);
149
- }
150
- else
151
- {
152
- //iconv���Ȃ���΂��̂܂ܕԂ�
153
- return original_string;
154
- }
181
+ check_kcode();
182
+ if(RTEST(objIconvR2J))
183
+ {
184
+ return rb_funcall(objIconvJ2R, rb_intern("iconv"), 1, utf8_string);
185
+ }
186
+ else
187
+ {
188
+ return utf8_string;
189
+ }
155
190
  }
data/ext/riconv.h CHANGED
@@ -12,14 +12,12 @@
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.h 4 2006-09-11 15:21:38Z arton $
15
+ * $Id: riconv.h 29 2007-10-22 08:29:05Z kuwa1 $
16
16
  */
17
17
  #ifndef _RICONV_H
18
18
  #define _RICONV_H
19
19
 
20
20
  extern VALUE exticonv_local_to_utf8(VALUE);
21
21
  extern VALUE exticonv_utf8_to_local(VALUE);
22
- extern VALUE exticonv_cc(VALUE, const char*, const char*);
23
- extern VALUE exticonv_vv(VALUE, VALUE, VALUE);
24
22
 
25
23
  #endif /* _RICONV_H */
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 25 2007-09-23 00:30:23Z arton $
15
+ * $Id: rjb.c 39 2007-11-08 17:33:57Z arton $
16
16
  */
17
17
 
18
- #define RJB_VERSION "1.0.9"
18
+ #define RJB_VERSION "1.0.11"
19
19
 
20
20
  #include "ruby.h"
21
21
  #include "st.h"
@@ -45,6 +45,7 @@ static void setup_metadata(JNIEnv* jenv, VALUE self, struct jv_data*, VALUE clas
45
45
  static VALUE jarray2rv(JNIEnv* jenv, jvalue val);
46
46
  static jarray r2objarray(JNIEnv* jenv, VALUE v, const char* cls);
47
47
  static VALUE jv2rv_withprim(JNIEnv* jenv, jobject o);
48
+ static J2R get_arrayconv(const char* cname, char* depth);
48
49
 
49
50
  static VALUE rjb;
50
51
  static VALUE jklass;
@@ -237,6 +238,7 @@ static VALUE jv2rv_r(JNIEnv* jenv, jvalue val)
237
238
  // object to ruby
238
239
  if (!val.l) return Qnil;
239
240
  klass = (*jenv)->GetObjectClass(jenv, val.l);
241
+
240
242
  if ((*jenv)->IsSameObject(jenv, klass, j_class))
241
243
  {
242
244
  (*jenv)->DeleteLocalRef(jenv, klass);
@@ -247,8 +249,13 @@ static VALUE jv2rv_r(JNIEnv* jenv, jvalue val)
247
249
  cname = (*jenv)->GetStringUTFChars(jenv, nm, NULL);
248
250
  if (*cname == '[')
249
251
  {
252
+ char depth = 0;
253
+ J2R j2r = get_arrayconv(cname, &depth);
250
254
  rjb_release_string(jenv, nm, cname);
251
- return jarray2rv(jenv, val);
255
+ v = j2r(jenv, val);
256
+ (*jenv)->DeleteLocalRef(jenv, klass);
257
+ (*jenv)->DeleteLocalRef(jenv, val.l);
258
+ return v;
252
259
  }
253
260
  clsname = rb_str_new2(cname);
254
261
  rjb_release_string(jenv, nm, cname);
@@ -1146,6 +1153,27 @@ static R2J get_r2j(JNIEnv* jenv, jobject o, int* siglen, char* sigp)
1146
1153
  return result;
1147
1154
  }
1148
1155
 
1156
+ static J2R get_arrayconv(const char* cname, char* pdepth)
1157
+ {
1158
+ int i;
1159
+ int start;
1160
+ for (start = 1; *(cname + start) == '['; start++);
1161
+ *pdepth = (char)start;
1162
+ for (i = 0; i < COUNTOF(jcvt); i++)
1163
+ {
1164
+ if (*(cname + start) == jcvt[i].jntype[0])
1165
+ {
1166
+ if (jcvt[i].jntype[0] == 'L'
1167
+ && strncmp(cname + start, jcvt[i].jntype, strlen(jcvt[i].jntype)))
1168
+ {
1169
+ break;
1170
+ }
1171
+ return jcvt[i].ja2r;
1172
+ }
1173
+ }
1174
+ return &jarray2rv;
1175
+ }
1176
+
1149
1177
  static J2R get_j2r(JNIEnv* jenv, jobject cls, char* psig, char* pdepth, char* ppsig, off_t* piv, int static_method)
1150
1178
  {
1151
1179
  int i;
@@ -1158,26 +1186,7 @@ static J2R get_j2r(JNIEnv* jenv, jobject cls, char* psig, char* pdepth, char* pp
1158
1186
 
1159
1187
  if (*cname == '[')
1160
1188
  {
1161
- int start;
1162
- for (start = 1; *(cname + start) == '['; start++);
1163
- *pdepth = (char)start;
1164
- for (i = 0; i < COUNTOF(jcvt); i++)
1165
- {
1166
- if (*(cname + start) == jcvt[i].jntype[0])
1167
- {
1168
- if (jcvt[i].jntype[0] == 'L'
1169
- && strncmp(cname + start, jcvt[i].jntype, strlen(jcvt[i].jntype)))
1170
- {
1171
- break;
1172
- }
1173
- result = jcvt[i].ja2r;
1174
- break;
1175
- }
1176
- }
1177
- if (!result)
1178
- {
1179
- result = jarray2rv;
1180
- }
1189
+ result = get_arrayconv(cname, pdepth);
1181
1190
  jname = cname;
1182
1191
  }
1183
1192
  else
data/lib/rjbcore.so CHANGED
Binary file
data/test/test.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/local/env ruby
2
- # $Id: test.rb 23 2007-09-22 23:07:05Z arton $
2
+ # $Id: test.rb 34 2007-11-08 16:52:07Z arton $
3
3
 
4
4
  require 'test/unit'
5
5
  require 'rjb'
@@ -142,6 +142,32 @@ class TestRjb < Test::Unit::TestCase
142
142
  sjis_kj = "\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67"
143
143
  s = @jString.new(sjis_kj)
144
144
  assert_equal(s.toString(), sjis_kj)
145
+ $KCODE = 'utf8'
146
+ utf8_kj = "\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88"
147
+ s = @jString.new(utf8_kj)
148
+ assert_equal(s.toString(), utf8_kj)
149
+ $KCODE = 'none'
150
+ if /mswin(?!ce)|mingw|cygwin|bccwin/ =~ RUBY_PLATFORM
151
+ #expecting shift_jis on windows
152
+ none_kj = "\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67"
153
+ else
154
+ #expecting utf-8 unless windows
155
+ none_kj = "\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88"
156
+ end
157
+ s = @jString.new(none_kj)
158
+ assert_equal(s.toString(), none_kj)
159
+ $KCODE = 'utf8'
160
+ utf8_kj = "\xE6\xBC\xA2\xE5\xAD\x97\xE3\x83\x86\xE3\x82\xAD\xE3\x82\xB9\xE3\x83\x88"
161
+ s = @jString.new(utf8_kj)
162
+ assert_equal(s.toString(), utf8_kj)
163
+ $KCODE = 'sjis'
164
+ sjis_kj = "\x8a\xbf\x8e\x9a\x83\x65\x83\x4c\x83\x58\x83\x67"
165
+ s = @jString.new(sjis_kj)
166
+ assert_equal(s.toString(), sjis_kj)
167
+ $KCODE = 'euc'
168
+ euc_kj = "\xb4\xc1\xbb\xfa\xa5\xc6\xa5\xad\xa5\xb9\xa5\xc8"
169
+ s = @jString.new(euc_kj)
170
+ assert_equal(s.toString(), euc_kj)
145
171
  end
146
172
 
147
173
  def test_constants()
@@ -499,5 +525,22 @@ class TestRjb < Test::Unit::TestCase
499
525
  assert_equal 8070450532247928832, a.get(7)
500
526
  assert_equal ?A, a.get(8)
501
527
  end
528
+
529
+ def test_enum
530
+ t = Rjb::import('jp.co.infoseek.hp.arton.rjb.Test$TestTypes')
531
+ assert t.ONE.equals(t.values()[0])
532
+ assert_equal 3, t.values().size
533
+ assert_equal 2, t.THREE.ordinal
534
+ assert_equal "TWO", t.TWO.name
535
+ assert_equal "THREE", t.THREE.toString
536
+ end
537
+
538
+ #rjb-bugs-15430 rebported by Bryan Duxbury
539
+ def test_generics_map
540
+ test = import('jp.co.infoseek.hp.arton.rjb.Test').new
541
+ map = test.sorted_map
542
+ assert_equal "\0\x1\x2\x3\x4", map.get('abc')
543
+ assert_equal "\x5\x6\x7\x8\x9", map.get('def')
544
+ end
502
545
  end
503
546
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: rjb
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.9
7
- date: 2007-09-23 00:00:00 +09:00
6
+ version: 1.0.11
7
+ date: 2007-11-09 00:00:00 +09:00
8
8
  summary: Ruby Java bridge
9
9
  require_paths:
10
10
  - lib
@@ -34,6 +34,7 @@ files:
34
34
  - ext/riconv.c
35
35
  - ext/rjb.c
36
36
  - ext/rjbexception.c
37
+ - ext/extconf.h
37
38
  - ext/jniwrap.h
38
39
  - ext/jp_co_infoseek_hp_arton_rjb_RBridge.h
39
40
  - ext/riconv.h
@@ -47,6 +48,7 @@ files:
47
48
  - test/jp/co/infoseek/hp/arton/rjb/Base.class
48
49
  - test/jp/co/infoseek/hp/arton/rjb/ExtBase.class
49
50
  - test/jp/co/infoseek/hp/arton/rjb/IBase.class
51
+ - test/jp/co/infoseek/hp/arton/rjb/Test$TestTypes.class
50
52
  - test/jp/co/infoseek/hp/arton/rjb/Test.class
51
53
  - COPYING
52
54
  - ChangeLog