oj 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of oj might be problematic. Click here for more details.

Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -4
  3. data/ext/oj/compat.c +3 -4
  4. data/ext/oj/encode.h +51 -0
  5. data/ext/oj/fast.c +4 -9
  6. data/ext/oj/object.c +7 -19
  7. data/ext/oj/oj.c +32 -12
  8. data/ext/oj/oj.h +3 -0
  9. data/ext/oj/parse.c +2 -3
  10. data/ext/oj/saj.c +4 -9
  11. data/ext/oj/scp.c +5 -12
  12. data/ext/oj/strict.c +5 -12
  13. data/lib/oj/version.rb +1 -1
  14. data/test/a.rb +38 -0
  15. data/test/bug.rb +15 -0
  16. data/test/e.rb +12 -0
  17. data/test/files.rb +29 -0
  18. data/test/foo.rb +24 -0
  19. data/test/mj.rb +48 -0
  20. data/test/perf.rb +107 -0
  21. data/test/perf_compat.rb +128 -0
  22. data/test/perf_fast.rb +164 -0
  23. data/test/perf_object.rb +136 -0
  24. data/test/perf_saj.rb +109 -0
  25. data/test/perf_scp.rb +151 -0
  26. data/test/perf_simple.rb +287 -0
  27. data/test/perf_strict.rb +127 -0
  28. data/test/sample.rb +55 -0
  29. data/test/sample/change.rb +14 -0
  30. data/test/sample/dir.rb +19 -0
  31. data/test/sample/doc.rb +36 -0
  32. data/test/sample/file.rb +48 -0
  33. data/test/sample/group.rb +16 -0
  34. data/test/sample/hasprops.rb +16 -0
  35. data/test/sample/layer.rb +12 -0
  36. data/test/sample/line.rb +20 -0
  37. data/test/sample/oval.rb +10 -0
  38. data/test/sample/rect.rb +10 -0
  39. data/test/sample/shape.rb +35 -0
  40. data/test/sample/text.rb +20 -0
  41. data/test/sample_json.rb +37 -0
  42. data/test/test_compat.rb +342 -0
  43. data/test/test_fast.rb +416 -0
  44. data/test/test_mimic.rb +208 -0
  45. data/test/test_mimic_after.rb +35 -0
  46. data/test/test_object.rb +390 -0
  47. data/test/test_saj.rb +184 -0
  48. data/test/test_scp.rb +224 -0
  49. data/test/test_strict.rb +259 -0
  50. data/test/tests.rb +1017 -0
  51. data/test/x.rb +59 -0
  52. metadata +41 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f2645663d6b76de56402dc004a41b2299c3eb09
4
- data.tar.gz: 2df5a5fdca36bb28f69130f249500cbe7ea9a148
3
+ metadata.gz: e9c84fb3930bef0021b22138c0e4ee9b42785b1a
4
+ data.tar.gz: cba9e1d4cd91413a80b7ff6521ccb6b4c41927d9
5
5
  SHA512:
6
- metadata.gz: b8b3d8d7a4437b06cb2b7c509042bcd83f5ad6af6dba92e05b40af29b49d89b98608ffcb0668807201ce152b13ca702276bcf8492afe04adb2a8594bafcfecc0
7
- data.tar.gz: 3daeb161d0402dcdbffd7aad76551ae39203e9b797fcff261d32c8b38a63d175c270e1f0ad7f9e2db6fbd86af5de81f564cac5e9415a74a7f84e2f2f29a6c01c
6
+ metadata.gz: 8a6741639d1ba3a7bd3292980ac7819aa6497c8c14621beefc4a1b151c7b8735f787460a02fd0edc8d4fd8c884cf66a453ac5439be7ecb58bf73f85bea21fe7b
7
+ data.tar.gz: 7e822754689d760c7e35b648d601f641e33edc1922e747051046abf2f9785f69a6fd0643b24951de6f2fc0e1352689780d64aeb595375c6181d143080bf18075
data/README.md CHANGED
@@ -20,11 +20,9 @@ Follow [@peterohler on Twitter](http://twitter.com/#!/peterohler) for announceme
20
20
 
21
21
  [![Build Status](https://secure.travis-ci.org/ohler55/oj.png?branch=master)](http://travis-ci.org/ohler55/oj)
22
22
 
23
- ### Current Release 2.1.3
23
+ ### Current Release 2.1.4
24
24
 
25
- - Fixed bug that did not deserialize all attributes in an Exception subclass.
26
-
27
- - Added a sample to demonstrate how to write Exception subclasses that will automatically serialize and deserialize.
25
+ - Fixed Linux 32 bit rounding bug.
28
26
 
29
27
  [Older release notes](http://www.ohler.com/dev/oj_misc/release_notes.html).
30
28
 
@@ -35,6 +35,7 @@
35
35
  #include "parse.h"
36
36
  #include "resolve.h"
37
37
  #include "hash.h"
38
+ #include "encode.h"
38
39
 
39
40
  static void
40
41
  hash_set_cstr(ParseInfo pi, const char *key, size_t klen, const char *str, size_t len, const char *orig) {
@@ -54,10 +55,8 @@ hash_set_cstr(ParseInfo pi, const char *key, size_t klen, const char *str, size_
54
55
  VALUE rstr = rb_str_new(str, len);
55
56
  VALUE rkey = rb_str_new(key, klen);
56
57
 
57
- #if HAS_ENCODING_SUPPORT
58
- rb_enc_associate(rstr, oj_utf8_encoding);
59
- rb_enc_associate(rkey, oj_utf8_encoding);
60
- #endif
58
+ rstr = oj_encode(rstr);
59
+ rkey = oj_encode(rkey);
61
60
  if (Yes == pi->options.sym_key) {
62
61
  rkey = rb_str_intern(rkey);
63
62
  }
@@ -0,0 +1,51 @@
1
+ /* encode.h
2
+ * Copyright (c) 2011, Peter Ohler
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * - Redistributions of source code must retain the above copyright notice, this
9
+ * list of conditions and the following disclaimer.
10
+ *
11
+ * - Redistributions in binary form must reproduce the above copyright notice,
12
+ * this list of conditions and the following disclaimer in the documentation
13
+ * and/or other materials provided with the distribution.
14
+ *
15
+ * - Neither the name of Peter Ohler nor the names of its contributors may be
16
+ * used to endorse or promote products derived from this software without
17
+ * specific prior written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ */
30
+
31
+ #ifndef __OJ_ENCODE_H__
32
+ #define __OJ_ENCODE_H__
33
+
34
+ #include "ruby.h"
35
+ #if HAS_ENCODING_SUPPORT
36
+ #include "ruby/encoding.h"
37
+ #endif
38
+
39
+ static inline VALUE
40
+ oj_encode(VALUE rstr) {
41
+ #if HAS_ENCODING_SUPPORT
42
+ rb_enc_associate(rstr, oj_utf8_encoding);
43
+ #else
44
+ if (Qnil != oj_utf8_encoding) {
45
+ rstr = rb_funcall(oj_utf8_encoding, oj_iconv_id, 1, rstr);
46
+ }
47
+ #endif
48
+ return rstr;
49
+ }
50
+
51
+ #endif /* __OJ_ENCODE_H__ */
@@ -38,6 +38,7 @@
38
38
  #include <errno.h>
39
39
 
40
40
  #include "oj.h"
41
+ #include "encode.h"
41
42
 
42
43
  // maximum to allocate on the stack, arbitrary limit
43
44
  #define SMALL_XML 65536
@@ -266,9 +267,7 @@ leaf_value(Doc doc, Leaf leaf) {
266
267
  break;
267
268
  case T_STRING:
268
269
  leaf->value = rb_str_new2(leaf->str);
269
- #if HAS_ENCODING_SUPPORT
270
- rb_enc_associate(leaf->value, oj_utf8_encoding);
271
- #endif
270
+ leaf->value = oj_encode(leaf->value);
272
271
  leaf->value_type = RUBY_VAL;
273
272
  break;
274
273
  case T_ARRAY:
@@ -467,9 +466,7 @@ leaf_hash_value(Doc doc, Leaf leaf) {
467
466
 
468
467
  do {
469
468
  key = rb_str_new2(e->key);
470
- #if HAS_ENCODING_SUPPORT
471
- rb_enc_associate(key, oj_utf8_encoding);
472
- #endif
469
+ key = oj_encode(key);
473
470
  rb_hash_aset(h, key, leaf_value(doc, e));
474
471
  e = e->next;
475
472
  } while (e != first);
@@ -1275,9 +1272,7 @@ doc_local_key(VALUE self) {
1275
1272
 
1276
1273
  if (T_HASH == leaf->parent_type) {
1277
1274
  key = rb_str_new2(leaf->key);
1278
- #if HAS_ENCODING_SUPPORT
1279
- rb_enc_associate(key, oj_utf8_encoding);
1280
- #endif
1275
+ key = oj_encode(key);
1281
1276
  } else if (T_ARRAY == leaf->parent_type) {
1282
1277
  key = LONG2NUM(leaf->index);
1283
1278
  }
@@ -36,6 +36,7 @@
36
36
  #include "resolve.h"
37
37
  #include "hash.h"
38
38
  #include "odd.h"
39
+ #include "encode.h"
39
40
 
40
41
  inline static long
41
42
  read_long(const char *str, size_t len) {
@@ -57,16 +58,11 @@ hash_key(ParseInfo pi, const char *key, size_t klen, char k1) {
57
58
 
58
59
  if (':' == k1) {
59
60
  rkey = rb_str_new(key + 1, klen - 1);
60
- #if HAS_ENCODING_SUPPORT
61
- rb_enc_associate(rkey, oj_utf8_encoding);
62
- #endif
61
+ rkey = oj_encode(rkey);
63
62
  rkey = rb_funcall(rkey, oj_to_sym_id, 0);
64
63
  } else {
65
64
  rkey = rb_str_new(key, klen);
66
-
67
- #if HAS_ENCODING_SUPPORT
68
- rb_enc_associate(rkey, oj_utf8_encoding);
69
- #endif
65
+ rkey = oj_encode(rkey);
70
66
  if (Yes == pi->options.sym_key) {
71
67
  rkey = rb_str_intern(rkey);
72
68
  }
@@ -80,9 +76,7 @@ str_to_value(ParseInfo pi, const char *str, size_t len, const char *orig) {
80
76
 
81
77
  if (':' == *orig && 0 < len) {
82
78
  rstr = rb_str_new(str + 1, len - 1);
83
- #if HAS_ENCODING_SUPPORT
84
- rb_enc_associate(rstr, oj_utf8_encoding);
85
- #endif
79
+ rstr = oj_encode(rstr);
86
80
  rstr = rb_funcall(rstr, oj_to_sym_id, 0);
87
81
  } else if (pi->circ_array && 3 <= len && '^' == *orig && 'r' == orig[1]) {
88
82
  long i = read_long(str + 2, len - 2);
@@ -94,9 +88,7 @@ str_to_value(ParseInfo pi, const char *str, size_t len, const char *orig) {
94
88
  rstr = oj_circ_array_get(pi->circ_array, i);
95
89
  } else {
96
90
  rstr = rb_str_new(str, len);
97
- #if HAS_ENCODING_SUPPORT
98
- rb_enc_associate(rstr, oj_utf8_encoding);
99
- #endif
91
+ rstr = oj_encode(rstr);
100
92
  }
101
93
  return rstr;
102
94
  }
@@ -127,16 +119,12 @@ hat_cstr(ParseInfo pi, Val parent, const char *key, size_t klen, const char *str
127
119
  break;
128
120
  case 'm':
129
121
  parent->val = rb_str_new(str + 1, len - 1);
130
- #if HAS_ENCODING_SUPPORT
131
- rb_enc_associate(parent->val, oj_utf8_encoding);
132
- #endif
122
+ parent->val = oj_encode(parent->val);
133
123
  parent->val = rb_funcall(parent->val, oj_to_sym_id, 0);
134
124
  break;
135
125
  case 's':
136
126
  parent->val = rb_str_new(str, len);
137
- #if HAS_ENCODING_SUPPORT
138
- rb_enc_associate(parent->val, oj_utf8_encoding);
139
- #endif
127
+ parent->val = oj_encode(parent->val);
140
128
  break;
141
129
  case 'c': // class
142
130
  parent->val = oj_name2class(pi, str, len, Yes == pi->options.auto_define);
@@ -40,6 +40,7 @@
40
40
  #include "parse.h"
41
41
  #include "hash.h"
42
42
  #include "odd.h"
43
+ #include "encode.h"
43
44
 
44
45
  typedef struct _YesNoOpt {
45
46
  VALUE sym;
@@ -60,6 +61,7 @@ ID oj_fileno_id;
60
61
  ID oj_hash_end_id;
61
62
  ID oj_hash_set_id;
62
63
  ID oj_hash_start_id;
64
+ ID oj_iconv_id;
63
65
  ID oj_instance_variables_id;
64
66
  ID oj_json_create_id;
65
67
  ID oj_new_id;
@@ -118,6 +120,8 @@ static VALUE mimic = Qnil;
118
120
 
119
121
  #if HAS_ENCODING_SUPPORT
120
122
  rb_encoding *oj_utf8_encoding = 0;
123
+ #else
124
+ VALUE oj_utf8_encoding = Qnil;
121
125
  #endif
122
126
 
123
127
  #if SAFE_CACHE
@@ -678,9 +682,7 @@ dump(int argc, VALUE *argv, VALUE self) {
678
682
  rb_raise(rb_eNoMemError, "Not enough memory.");
679
683
  }
680
684
  rstr = rb_str_new2(out.buf);
681
- #if HAS_ENCODING_SUPPORT
682
- rb_enc_associate(rstr, oj_utf8_encoding);
683
- #endif
685
+ rstr = oj_encode(rstr);
684
686
  if (out.allocated) {
685
687
  xfree(out.buf);
686
688
  }
@@ -727,9 +729,7 @@ mimic_dump(int argc, VALUE *argv, VALUE self) {
727
729
  rb_raise(rb_eNoMemError, "Not enough memory.");
728
730
  }
729
731
  rstr = rb_str_new2(out.buf);
730
- #if HAS_ENCODING_SUPPORT
731
- rb_enc_associate(rstr, oj_utf8_encoding);
732
- #endif
732
+ rstr = oj_encode(rstr);
733
733
  if (2 <= argc && Qnil != argv[1]) {
734
734
  VALUE io = argv[1];
735
735
  VALUE args[1];
@@ -872,9 +872,7 @@ mimic_generate_core(int argc, VALUE *argv, Options copts) {
872
872
  rb_raise(rb_eNoMemError, "Not enough memory.");
873
873
  }
874
874
  rstr = rb_str_new2(out.buf);
875
- #if HAS_ENCODING_SUPPORT
876
- rb_enc_associate(rstr, oj_utf8_encoding);
877
- #endif
875
+ rstr = oj_encode(rstr);
878
876
  if (out.allocated) {
879
877
  xfree(out.buf);
880
878
  }
@@ -1072,6 +1070,23 @@ hash_test(VALUE self) {
1072
1070
  }
1073
1071
  */
1074
1072
 
1073
+ #if !HAS_ENCODING_SUPPORT
1074
+ static VALUE
1075
+ iconv_encoder(VALUE x) {
1076
+ VALUE iconv;
1077
+
1078
+ rb_require("iconv");
1079
+ iconv = rb_const_get(rb_cObject, rb_intern("Iconv"));
1080
+
1081
+ return rb_funcall(iconv, rb_intern("new"), 2, rb_str_new2("ASCII//TRANSLIT"), rb_str_new2("UTF-8"));
1082
+ }
1083
+
1084
+ static VALUE
1085
+ iconv_rescue(VALUE x) {
1086
+ return Qnil;
1087
+ }
1088
+ #endif
1089
+
1075
1090
  void Init_oj() {
1076
1091
  Oj = rb_define_module("Oj");
1077
1092
 
@@ -1079,6 +1094,13 @@ void Init_oj() {
1079
1094
  rb_require("date");
1080
1095
  rb_require("bigdecimal");
1081
1096
  rb_require("stringio");
1097
+ #if HAS_ENCODING_SUPPORT
1098
+ oj_utf8_encoding = rb_enc_find("UTF-8");
1099
+ #else
1100
+ // need an option to turn this on
1101
+ oj_utf8_encoding = rb_rescue(iconv_encoder, Qnil, iconv_rescue, Qnil);
1102
+ oj_utf8_encoding = Qnil;
1103
+ #endif
1082
1104
 
1083
1105
  //rb_define_module_function(Oj, "hash_test", hash_test, 0);
1084
1106
 
@@ -1109,6 +1131,7 @@ void Init_oj() {
1109
1131
  oj_hash_end_id = rb_intern("hash_end");
1110
1132
  oj_hash_set_id = rb_intern("hash_set");
1111
1133
  oj_hash_start_id = rb_intern("hash_start");
1134
+ oj_iconv_id = rb_intern("iconv");
1112
1135
  oj_instance_variables_id = rb_intern("instance_variables");
1113
1136
  oj_json_create_id = rb_intern("json_create");
1114
1137
  oj_new_id = rb_intern("new");
@@ -1157,9 +1180,6 @@ void Init_oj() {
1157
1180
  oj_slash_string = rb_str_new2("/"); rb_gc_register_address(&oj_slash_string);
1158
1181
 
1159
1182
  oj_default_options.mode = ObjectMode;
1160
- #if HAS_ENCODING_SUPPORT
1161
- oj_utf8_encoding = rb_enc_find("UTF-8");
1162
- #endif
1163
1183
 
1164
1184
  oj_hash_init();
1165
1185
  oj_odd_init();
@@ -174,6 +174,8 @@ extern VALUE Oj;
174
174
  extern struct _Options oj_default_options;
175
175
  #if HAS_ENCODING_SUPPORT
176
176
  extern rb_encoding *oj_utf8_encoding;
177
+ #else
178
+ extern VALUE oj_utf8_encoding;
177
179
  #endif
178
180
 
179
181
  extern VALUE oj_bag_class;
@@ -197,6 +199,7 @@ extern ID oj_fileno_id;
197
199
  extern ID oj_hash_end_id;
198
200
  extern ID oj_hash_set_id;
199
201
  extern ID oj_hash_start_id;
202
+ extern ID oj_iconv_id;
200
203
  extern ID oj_instance_variables_id;
201
204
  extern ID oj_json_create_id;
202
205
  extern ID oj_new_id;
@@ -48,7 +48,6 @@
48
48
  #define NUM_MAX (FIXNUM_MAX >> 8)
49
49
  #endif
50
50
  #define EXP_MAX 1023
51
- #define I64_MAX 0x7FFFFFFFFFFFFFFFLL
52
51
  #define DEC_MAX 14
53
52
 
54
53
  static void
@@ -418,7 +417,7 @@ read_num(ParseInfo pi) {
418
417
  zero_cnt = 0;
419
418
  }
420
419
  ni.i = ni.i * 10 + d;
421
- if (I64_MAX <= ni.i || DEC_MAX < ni.dec_cnt - zero_cnt) {
420
+ if (LONG_MAX <= ni.i || DEC_MAX < ni.dec_cnt - zero_cnt) {
422
421
  ni.big = 1;
423
422
  }
424
423
  }
@@ -436,7 +435,7 @@ read_num(ParseInfo pi) {
436
435
  ni.dec_cnt++;
437
436
  ni.num = ni.num * 10 + d;
438
437
  ni.div *= 10;
439
- if (I64_MAX <= ni.div || DEC_MAX < ni.dec_cnt - zero_cnt) {
438
+ if (LONG_MAX <= ni.div || DEC_MAX < ni.dec_cnt - zero_cnt) {
440
439
  ni.big = 1;
441
440
  }
442
441
  }
@@ -42,6 +42,7 @@
42
42
  #define OJ_INFINITY (1.0/0.0)
43
43
 
44
44
  #include "oj.h"
45
+ #include "encode.h"
45
46
 
46
47
  typedef struct _CX {
47
48
  VALUE *cur;
@@ -150,9 +151,7 @@ call_add_value(VALUE handler, VALUE value, const char *key) {
150
151
  k = Qnil;
151
152
  } else {
152
153
  k = rb_str_new2(key);
153
- #if HAS_ENCODING_SUPPORT
154
- rb_enc_associate(k, oj_utf8_encoding);
155
- #endif
154
+ k = oj_encode(k);
156
155
  }
157
156
  rb_funcall(handler, oj_add_value_id, 2, value, k);
158
157
  }
@@ -165,9 +164,7 @@ call_no_value(VALUE handler, ID method, const char *key) {
165
164
  k = Qnil;
166
165
  } else {
167
166
  k = rb_str_new2(key);
168
- #if HAS_ENCODING_SUPPORT
169
- rb_enc_associate(k, oj_utf8_encoding);
170
- #endif
167
+ k = oj_encode(k);
171
168
  }
172
169
  rb_funcall(handler, method, 1, k);
173
170
  }
@@ -344,9 +341,7 @@ read_str(ParseInfo pi, const char *key) {
344
341
  if (pi->has_add_value) {
345
342
  VALUE s = rb_str_new2(text);
346
343
 
347
- #if HAS_ENCODING_SUPPORT
348
- rb_enc_associate(s, oj_utf8_encoding);
349
- #endif
344
+ s = oj_encode(s);
350
345
  call_add_value(pi->handler, s, key);
351
346
  }
352
347
  }
@@ -37,6 +37,7 @@
37
37
 
38
38
  #include "oj.h"
39
39
  #include "parse.h"
40
+ #include "encode.h"
40
41
 
41
42
  inline static int
42
43
  respond_to(VALUE obj, ID method) {
@@ -108,9 +109,7 @@ static void
108
109
  add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
109
110
  VALUE rstr = rb_str_new(str, len);
110
111
 
111
- #if HAS_ENCODING_SUPPORT
112
- rb_enc_associate(rstr, oj_utf8_encoding);
113
- #endif
112
+ rstr = oj_encode(rstr);
114
113
  rb_funcall((VALUE)pi->cbc, oj_add_value_id, 1, rstr);
115
114
  }
116
115
 
@@ -143,9 +142,7 @@ static VALUE
143
142
  hash_key(ParseInfo pi, const char *key, size_t klen) {
144
143
  VALUE rkey = rb_str_new(key, klen);
145
144
 
146
- #if HAS_ENCODING_SUPPORT
147
- rb_enc_associate(rkey, oj_utf8_encoding);
148
- #endif
145
+ rkey = oj_encode(rkey);
149
146
  if (Yes == pi->options.sym_key) {
150
147
  rkey = rb_str_intern(rkey);
151
148
  }
@@ -156,9 +153,7 @@ static void
156
153
  hash_set_cstr(ParseInfo pi, const char *key, size_t klen, const char *str, size_t len, const char *orig) {
157
154
  VALUE rstr = rb_str_new(str, len);
158
155
 
159
- #if HAS_ENCODING_SUPPORT
160
- rb_enc_associate(rstr, oj_utf8_encoding);
161
- #endif
156
+ rstr = oj_encode(rstr);
162
157
  rb_funcall((VALUE)pi->cbc, oj_hash_set_id, 3, stack_peek(&pi->stack)->val, hash_key(pi, key, klen), rstr);
163
158
  }
164
159
 
@@ -176,9 +171,7 @@ static void
176
171
  array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
177
172
  VALUE rstr = rb_str_new(str, len);
178
173
 
179
- #if HAS_ENCODING_SUPPORT
180
- rb_enc_associate(rstr, oj_utf8_encoding);
181
- #endif
174
+ rstr = oj_encode(rstr);
182
175
  rb_funcall((VALUE)pi->cbc, oj_array_append_id, 2, stack_peek(&pi->stack)->val, rstr);
183
176
  }
184
177