json 1.8.2 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/.travis.yml +11 -9
  4. data/{CHANGES → CHANGES.md} +220 -89
  5. data/Gemfile +10 -6
  6. data/{README-json-jruby.markdown → README-json-jruby.md} +0 -0
  7. data/{README.rdoc → README.md} +204 -137
  8. data/Rakefile +35 -113
  9. data/VERSION +1 -1
  10. data/ext/json/ext/fbuffer/fbuffer.h +0 -3
  11. data/ext/json/ext/generator/generator.c +215 -110
  12. data/ext/json/ext/generator/generator.h +18 -5
  13. data/ext/json/ext/parser/extconf.rb +3 -0
  14. data/ext/json/ext/parser/parser.c +422 -508
  15. data/ext/json/ext/parser/parser.h +15 -8
  16. data/ext/json/ext/parser/parser.rl +151 -200
  17. data/ext/json/extconf.rb +0 -1
  18. data/java/src/json/ext/ByteListTranscoder.java +1 -2
  19. data/java/src/json/ext/Generator.java +44 -22
  20. data/java/src/json/ext/GeneratorMethods.java +1 -2
  21. data/java/src/json/ext/GeneratorService.java +1 -2
  22. data/java/src/json/ext/GeneratorState.java +3 -56
  23. data/java/src/json/ext/OptionsReader.java +2 -3
  24. data/java/src/json/ext/Parser.java +132 -415
  25. data/java/src/json/ext/Parser.rl +48 -124
  26. data/java/src/json/ext/ParserService.java +1 -2
  27. data/java/src/json/ext/RuntimeInfo.java +1 -6
  28. data/java/src/json/ext/StringDecoder.java +1 -2
  29. data/java/src/json/ext/StringEncoder.java +5 -0
  30. data/java/src/json/ext/Utils.java +1 -2
  31. data/json-java.gemspec +16 -2
  32. data/json.gemspec +0 -0
  33. data/json_pure.gemspec +22 -29
  34. data/lib/json.rb +379 -29
  35. data/lib/json/add/bigdecimal.rb +3 -2
  36. data/lib/json/add/complex.rb +4 -3
  37. data/lib/json/add/core.rb +1 -0
  38. data/lib/json/add/date.rb +1 -1
  39. data/lib/json/add/date_time.rb +1 -1
  40. data/lib/json/add/exception.rb +1 -1
  41. data/lib/json/add/ostruct.rb +3 -3
  42. data/lib/json/add/range.rb +1 -1
  43. data/lib/json/add/rational.rb +3 -2
  44. data/lib/json/add/regexp.rb +3 -3
  45. data/lib/json/add/set.rb +29 -0
  46. data/lib/json/add/struct.rb +1 -1
  47. data/lib/json/add/symbol.rb +1 -1
  48. data/lib/json/add/time.rb +1 -1
  49. data/lib/json/common.rb +335 -128
  50. data/lib/json/ext.rb +0 -6
  51. data/lib/json/generic_object.rb +5 -4
  52. data/lib/json/pure.rb +2 -8
  53. data/lib/json/pure/generator.rb +64 -127
  54. data/lib/json/pure/parser.rb +42 -82
  55. data/lib/json/version.rb +2 -1
  56. data/references/rfc7159.txt +899 -0
  57. data/tests/fixtures/obsolete_fail1.json +1 -0
  58. data/tests/{test_json_addition.rb → json_addition_test.rb} +32 -25
  59. data/tests/json_common_interface_test.rb +126 -0
  60. data/tests/json_encoding_test.rb +107 -0
  61. data/tests/json_ext_parser_test.rb +15 -0
  62. data/tests/{test_json_fixtures.rb → json_fixtures_test.rb} +10 -8
  63. data/tests/{test_json_generate.rb → json_generator_test.rb} +123 -39
  64. data/tests/{test_json_generic_object.rb → json_generic_object_test.rb} +15 -8
  65. data/tests/json_parser_test.rb +472 -0
  66. data/tests/json_string_matching_test.rb +38 -0
  67. data/tests/{setup_variant.rb → test_helper.rb} +6 -0
  68. data/tools/diff.sh +18 -0
  69. data/tools/fuzz.rb +1 -9
  70. metadata +46 -53
  71. data/COPYING +0 -58
  72. data/COPYING-json-jruby +0 -57
  73. data/GPL +0 -340
  74. data/TODO +0 -1
  75. data/data/example.json +0 -1
  76. data/data/index.html +0 -38
  77. data/data/prototype.js +0 -4184
  78. data/tests/fixtures/fail1.json +0 -1
  79. data/tests/test_json.rb +0 -553
  80. data/tests/test_json_encoding.rb +0 -65
  81. data/tests/test_json_string_matching.rb +0 -39
  82. data/tests/test_json_unicode.rb +0 -72
@@ -1,7 +1,6 @@
1
1
  #ifndef _GENERATOR_H_
2
2
  #define _GENERATOR_H_
3
3
 
4
- #include <string.h>
5
4
  #include <math.h>
6
5
  #include <ctype.h>
7
6
 
@@ -73,7 +72,6 @@ typedef struct JSON_Generator_StateStruct {
73
72
  long max_nesting;
74
73
  char allow_nan;
75
74
  char ascii_only;
76
- char quirks_mode;
77
75
  long depth;
78
76
  long buffer_initial_length;
79
77
  } JSON_Generator_State;
@@ -99,8 +97,12 @@ typedef struct JSON_Generator_StateStruct {
99
97
 
100
98
  static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self);
101
99
  static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self);
100
+ #ifdef RUBY_INTEGER_UNIFICATION
101
+ static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self);
102
+ #else
102
103
  static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self);
103
104
  static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self);
105
+ #endif
104
106
  static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self);
105
107
  static VALUE mString_included_s(VALUE self, VALUE modul);
106
108
  static VALUE mString_to_json(int argc, VALUE *argv, VALUE self);
@@ -112,7 +114,6 @@ static VALUE mFalseClass_to_json(int argc, VALUE *argv, VALUE self);
112
114
  static VALUE mNilClass_to_json(int argc, VALUE *argv, VALUE self);
113
115
  static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self);
114
116
  static void State_free(void *state);
115
- static JSON_Generator_State *State_allocate(void);
116
117
  static VALUE cState_s_allocate(VALUE klass);
117
118
  static VALUE cState_configure(VALUE self, VALUE opts);
118
119
  static VALUE cState_to_h(VALUE self);
@@ -123,6 +124,9 @@ static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
123
124
  static void generate_json_null(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
124
125
  static void generate_json_false(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
125
126
  static void generate_json_true(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
127
+ #ifdef RUBY_INTEGER_UNIFICATION
128
+ static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
129
+ #endif
126
130
  static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
127
131
  static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
128
132
  static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
@@ -147,11 +151,20 @@ static VALUE cState_ascii_only_p(VALUE self);
147
151
  static VALUE cState_depth(VALUE self);
148
152
  static VALUE cState_depth_set(VALUE self, VALUE depth);
149
153
  static FBuffer *cState_prepare_buffer(VALUE self);
150
- #ifdef TypedData_Wrap_Struct
154
+ #ifndef ZALLOC
155
+ #define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
156
+ static inline void *ruby_zalloc(size_t n)
157
+ {
158
+ void *p = ruby_xmalloc(n);
159
+ memset(p, 0, n);
160
+ return p;
161
+ }
162
+ #endif
163
+ #ifdef TypedData_Make_Struct
151
164
  static const rb_data_type_t JSON_Generator_State_type;
152
165
  #define NEW_TYPEDDATA_WRAPPER 1
153
166
  #else
154
- #define TypedData_Wrap_Struct(klass, ignore, json) Data_Wrap_Struct(klass, NULL, State_free, json)
167
+ #define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, State_free, json)
155
168
  #define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json)
156
169
  #endif
157
170
 
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: false
1
2
  require 'mkmf'
2
3
 
4
+ have_func("rb_enc_raise", "ruby.h")
5
+
3
6
  create_makefile 'json/ext/parser'
@@ -1,11 +1,33 @@
1
-
1
+ /* This file is automatically generated from parser.rl by using ragel */
2
2
  #line 1 "parser.rl"
3
3
  #include "../fbuffer/fbuffer.h"
4
4
  #include "parser.h"
5
5
 
6
+ #if defined HAVE_RUBY_ENCODING_H
7
+ # define EXC_ENCODING rb_utf8_encoding(),
8
+ # ifndef HAVE_RB_ENC_RAISE
9
+ static void
10
+ enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
11
+ {
12
+ va_list args;
13
+ VALUE mesg;
14
+
15
+ va_start(args, fmt);
16
+ mesg = rb_enc_vsprintf(enc, fmt, args);
17
+ va_end(args);
18
+
19
+ rb_exc_raise(rb_exc_new3(exc, mesg));
20
+ }
21
+ # define rb_enc_raise enc_raise
22
+ # endif
23
+ #else
24
+ # define EXC_ENCODING /* nothing */
25
+ # define rb_enc_raise rb_raise
26
+ #endif
27
+
6
28
  /* unicode */
7
29
 
8
- static const char digit_values[256] = {
30
+ static const signed char digit_values[256] = {
9
31
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
10
32
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
11
33
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
@@ -24,20 +46,20 @@ static const char digit_values[256] = {
24
46
 
25
47
  static UTF32 unescape_unicode(const unsigned char *p)
26
48
  {
27
- char b;
49
+ signed char b;
28
50
  UTF32 result = 0;
29
51
  b = digit_values[p[0]];
30
52
  if (b < 0) return UNI_REPLACEMENT_CHAR;
31
- result = (result << 4) | b;
53
+ result = (result << 4) | (unsigned char)b;
32
54
  b = digit_values[p[1]];
33
- result = (result << 4) | b;
34
55
  if (b < 0) return UNI_REPLACEMENT_CHAR;
56
+ result = (result << 4) | (unsigned char)b;
35
57
  b = digit_values[p[2]];
36
- result = (result << 4) | b;
37
58
  if (b < 0) return UNI_REPLACEMENT_CHAR;
59
+ result = (result << 4) | (unsigned char)b;
38
60
  b = digit_values[p[3]];
39
- result = (result << 4) | b;
40
61
  if (b < 0) return UNI_REPLACEMENT_CHAR;
62
+ result = (result << 4) | (unsigned char)b;
41
63
  return result;
42
64
  }
43
65
 
@@ -67,59 +89,53 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
67
89
  return len;
68
90
  }
69
91
 
70
- #ifdef HAVE_RUBY_ENCODING_H
71
- static VALUE CEncoding_ASCII_8BIT, CEncoding_UTF_8, CEncoding_UTF_16BE,
72
- CEncoding_UTF_16LE, CEncoding_UTF_32BE, CEncoding_UTF_32LE;
73
- static ID i_encoding, i_encode;
74
- #else
75
- static ID i_iconv;
76
- #endif
77
-
78
92
  static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
79
93
  static VALUE CNaN, CInfinity, CMinusInfinity;
94
+ static VALUE cBigDecimal = Qundef;
80
95
 
81
96
  static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
82
- i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, i_quirks_mode,
83
- i_object_class, i_array_class, i_key_p, i_deep_const_get, i_match,
84
- i_match_string, i_aset, i_aref, i_leftshift;
97
+ i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
98
+ i_object_class, i_array_class, i_decimal_class, i_key_p,
99
+ i_deep_const_get, i_match, i_match_string, i_aset, i_aref,
100
+ i_leftshift, i_new, i_BigDecimal;
85
101
 
86
102
 
87
- #line 110 "parser.rl"
103
+ #line 126 "parser.rl"
88
104
 
89
105
 
90
106
 
91
- #line 92 "parser.c"
92
- static const int JSON_object_start = 1;
93
- static const int JSON_object_first_final = 27;
94
- static const int JSON_object_error = 0;
107
+ #line 108 "parser.c"
108
+ enum {JSON_object_start = 1};
109
+ enum {JSON_object_first_final = 27};
110
+ enum {JSON_object_error = 0};
95
111
 
96
- static const int JSON_object_en_main = 1;
112
+ enum {JSON_object_en_main = 1};
97
113
 
98
114
 
99
- #line 151 "parser.rl"
115
+ #line 168 "parser.rl"
100
116
 
101
117
 
102
- static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
118
+ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
103
119
  {
104
120
  int cs = EVIL;
105
121
  VALUE last_name = Qnil;
106
122
  VALUE object_class = json->object_class;
107
123
 
108
- if (json->max_nesting && json->current_nesting > json->max_nesting) {
109
- rb_raise(eNestingError, "nesting of %d is too deep", json->current_nesting);
124
+ if (json->max_nesting && current_nesting > json->max_nesting) {
125
+ rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
110
126
  }
111
127
 
112
128
  *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
113
129
 
114
130
 
115
- #line 116 "parser.c"
131
+ #line 132 "parser.c"
116
132
  {
117
133
  cs = JSON_object_start;
118
134
  }
119
135
 
120
- #line 166 "parser.rl"
136
+ #line 183 "parser.rl"
121
137
 
122
- #line 123 "parser.c"
138
+ #line 139 "parser.c"
123
139
  {
124
140
  if ( p == pe )
125
141
  goto _test_eof;
@@ -147,7 +163,7 @@ case 2:
147
163
  goto st2;
148
164
  goto st0;
149
165
  tr2:
150
- #line 133 "parser.rl"
166
+ #line 150 "parser.rl"
151
167
  {
152
168
  char *np;
153
169
  json->parsing_name = 1;
@@ -160,7 +176,7 @@ st3:
160
176
  if ( ++p == pe )
161
177
  goto _test_eof3;
162
178
  case 3:
163
- #line 164 "parser.c"
179
+ #line 180 "parser.c"
164
180
  switch( (*p) ) {
165
181
  case 13: goto st3;
166
182
  case 32: goto st3;
@@ -227,14 +243,15 @@ case 8:
227
243
  goto st8;
228
244
  goto st0;
229
245
  tr11:
230
- #line 118 "parser.rl"
246
+ #line 134 "parser.rl"
231
247
  {
232
248
  VALUE v = Qnil;
233
- char *np = JSON_parse_value(json, p, pe, &v);
249
+ char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
234
250
  if (np == NULL) {
235
251
  p--; {p++; cs = 9; goto _out;}
236
252
  } else {
237
253
  if (NIL_P(json->object_class)) {
254
+ OBJ_FREEZE(last_name);
238
255
  rb_hash_aset(*result, last_name, v);
239
256
  } else {
240
257
  rb_funcall(*result, i_aset, 2, last_name, v);
@@ -247,7 +264,7 @@ st9:
247
264
  if ( ++p == pe )
248
265
  goto _test_eof9;
249
266
  case 9:
250
- #line 251 "parser.c"
267
+ #line 268 "parser.c"
251
268
  switch( (*p) ) {
252
269
  case 13: goto st9;
253
270
  case 32: goto st9;
@@ -336,14 +353,14 @@ case 18:
336
353
  goto st9;
337
354
  goto st18;
338
355
  tr4:
339
- #line 141 "parser.rl"
356
+ #line 158 "parser.rl"
340
357
  { p--; {p++; cs = 27; goto _out;} }
341
358
  goto st27;
342
359
  st27:
343
360
  if ( ++p == pe )
344
361
  goto _test_eof27;
345
362
  case 27:
346
- #line 347 "parser.c"
363
+ #line 364 "parser.c"
347
364
  goto st0;
348
365
  st19:
349
366
  if ( ++p == pe )
@@ -441,7 +458,7 @@ case 26:
441
458
  _out: {}
442
459
  }
443
460
 
444
- #line 167 "parser.rl"
461
+ #line 184 "parser.rl"
445
462
 
446
463
  if (cs >= JSON_object_first_final) {
447
464
  if (json->create_additions) {
@@ -466,281 +483,358 @@ case 26:
466
483
 
467
484
 
468
485
 
469
- #line 470 "parser.c"
470
- static const int JSON_value_start = 1;
471
- static const int JSON_value_first_final = 21;
472
- static const int JSON_value_error = 0;
486
+ #line 487 "parser.c"
487
+ enum {JSON_value_start = 1};
488
+ enum {JSON_value_first_final = 29};
489
+ enum {JSON_value_error = 0};
473
490
 
474
- static const int JSON_value_en_main = 1;
491
+ enum {JSON_value_en_main = 1};
475
492
 
476
493
 
477
- #line 271 "parser.rl"
494
+ #line 284 "parser.rl"
478
495
 
479
496
 
480
- static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
497
+ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
481
498
  {
482
499
  int cs = EVIL;
483
500
 
484
501
 
485
- #line 486 "parser.c"
502
+ #line 503 "parser.c"
486
503
  {
487
504
  cs = JSON_value_start;
488
505
  }
489
506
 
490
- #line 278 "parser.rl"
507
+ #line 291 "parser.rl"
491
508
 
492
- #line 493 "parser.c"
509
+ #line 510 "parser.c"
493
510
  {
494
511
  if ( p == pe )
495
512
  goto _test_eof;
496
513
  switch ( cs )
497
514
  {
515
+ st1:
516
+ if ( ++p == pe )
517
+ goto _test_eof1;
498
518
  case 1:
499
519
  switch( (*p) ) {
500
- case 34: goto tr0;
501
- case 45: goto tr2;
502
- case 73: goto st2;
503
- case 78: goto st9;
504
- case 91: goto tr5;
505
- case 102: goto st11;
506
- case 110: goto st15;
507
- case 116: goto st18;
508
- case 123: goto tr9;
520
+ case 13: goto st1;
521
+ case 32: goto st1;
522
+ case 34: goto tr2;
523
+ case 45: goto tr3;
524
+ case 47: goto st6;
525
+ case 73: goto st10;
526
+ case 78: goto st17;
527
+ case 91: goto tr7;
528
+ case 102: goto st19;
529
+ case 110: goto st23;
530
+ case 116: goto st26;
531
+ case 123: goto tr11;
509
532
  }
510
- if ( 48 <= (*p) && (*p) <= 57 )
511
- goto tr2;
533
+ if ( (*p) > 10 ) {
534
+ if ( 48 <= (*p) && (*p) <= 57 )
535
+ goto tr3;
536
+ } else if ( (*p) >= 9 )
537
+ goto st1;
512
538
  goto st0;
513
539
  st0:
514
540
  cs = 0;
515
541
  goto _out;
516
- tr0:
517
- #line 219 "parser.rl"
542
+ tr2:
543
+ #line 236 "parser.rl"
518
544
  {
519
545
  char *np = JSON_parse_string(json, p, pe, result);
520
- if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
546
+ if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
521
547
  }
522
- goto st21;
523
- tr2:
524
- #line 224 "parser.rl"
548
+ goto st29;
549
+ tr3:
550
+ #line 241 "parser.rl"
525
551
  {
526
552
  char *np;
527
- if(pe > p + 9 - json->quirks_mode && !strncmp(MinusInfinity, p, 9)) {
553
+ if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) {
528
554
  if (json->allow_nan) {
529
555
  *result = CMinusInfinity;
530
556
  {p = (( p + 10))-1;}
531
- p--; {p++; cs = 21; goto _out;}
557
+ p--; {p++; cs = 29; goto _out;}
532
558
  } else {
533
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
559
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
534
560
  }
535
561
  }
536
562
  np = JSON_parse_float(json, p, pe, result);
537
563
  if (np != NULL) {p = (( np))-1;}
538
564
  np = JSON_parse_integer(json, p, pe, result);
539
565
  if (np != NULL) {p = (( np))-1;}
540
- p--; {p++; cs = 21; goto _out;}
566
+ p--; {p++; cs = 29; goto _out;}
541
567
  }
542
- goto st21;
543
- tr5:
544
- #line 242 "parser.rl"
568
+ goto st29;
569
+ tr7:
570
+ #line 259 "parser.rl"
545
571
  {
546
572
  char *np;
547
- json->current_nesting++;
548
- np = JSON_parse_array(json, p, pe, result);
549
- json->current_nesting--;
550
- if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
573
+ np = JSON_parse_array(json, p, pe, result, current_nesting + 1);
574
+ if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
551
575
  }
552
- goto st21;
553
- tr9:
554
- #line 250 "parser.rl"
576
+ goto st29;
577
+ tr11:
578
+ #line 265 "parser.rl"
555
579
  {
556
580
  char *np;
557
- json->current_nesting++;
558
- np = JSON_parse_object(json, p, pe, result);
559
- json->current_nesting--;
560
- if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
581
+ np = JSON_parse_object(json, p, pe, result, current_nesting + 1);
582
+ if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
561
583
  }
562
- goto st21;
563
- tr16:
564
- #line 212 "parser.rl"
584
+ goto st29;
585
+ tr25:
586
+ #line 229 "parser.rl"
565
587
  {
566
588
  if (json->allow_nan) {
567
589
  *result = CInfinity;
568
590
  } else {
569
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
591
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
570
592
  }
571
593
  }
572
- goto st21;
573
- tr18:
574
- #line 205 "parser.rl"
594
+ goto st29;
595
+ tr27:
596
+ #line 222 "parser.rl"
575
597
  {
576
598
  if (json->allow_nan) {
577
599
  *result = CNaN;
578
600
  } else {
579
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
601
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
580
602
  }
581
603
  }
582
- goto st21;
583
- tr22:
584
- #line 199 "parser.rl"
604
+ goto st29;
605
+ tr31:
606
+ #line 216 "parser.rl"
585
607
  {
586
608
  *result = Qfalse;
587
609
  }
588
- goto st21;
589
- tr25:
590
- #line 196 "parser.rl"
610
+ goto st29;
611
+ tr34:
612
+ #line 213 "parser.rl"
591
613
  {
592
614
  *result = Qnil;
593
615
  }
594
- goto st21;
595
- tr28:
596
- #line 202 "parser.rl"
616
+ goto st29;
617
+ tr37:
618
+ #line 219 "parser.rl"
597
619
  {
598
620
  *result = Qtrue;
599
621
  }
600
- goto st21;
601
- st21:
622
+ goto st29;
623
+ st29:
602
624
  if ( ++p == pe )
603
- goto _test_eof21;
604
- case 21:
605
- #line 258 "parser.rl"
606
- { p--; {p++; cs = 21; goto _out;} }
607
- #line 608 "parser.c"
625
+ goto _test_eof29;
626
+ case 29:
627
+ #line 271 "parser.rl"
628
+ { p--; {p++; cs = 29; goto _out;} }
629
+ #line 630 "parser.c"
630
+ switch( (*p) ) {
631
+ case 13: goto st29;
632
+ case 32: goto st29;
633
+ case 47: goto st2;
634
+ }
635
+ if ( 9 <= (*p) && (*p) <= 10 )
636
+ goto st29;
608
637
  goto st0;
609
638
  st2:
610
639
  if ( ++p == pe )
611
640
  goto _test_eof2;
612
641
  case 2:
613
- if ( (*p) == 110 )
614
- goto st3;
642
+ switch( (*p) ) {
643
+ case 42: goto st3;
644
+ case 47: goto st5;
645
+ }
615
646
  goto st0;
616
647
  st3:
617
648
  if ( ++p == pe )
618
649
  goto _test_eof3;
619
650
  case 3:
620
- if ( (*p) == 102 )
651
+ if ( (*p) == 42 )
621
652
  goto st4;
622
- goto st0;
653
+ goto st3;
623
654
  st4:
624
655
  if ( ++p == pe )
625
656
  goto _test_eof4;
626
657
  case 4:
627
- if ( (*p) == 105 )
628
- goto st5;
629
- goto st0;
658
+ switch( (*p) ) {
659
+ case 42: goto st4;
660
+ case 47: goto st29;
661
+ }
662
+ goto st3;
630
663
  st5:
631
664
  if ( ++p == pe )
632
665
  goto _test_eof5;
633
666
  case 5:
634
- if ( (*p) == 110 )
635
- goto st6;
636
- goto st0;
667
+ if ( (*p) == 10 )
668
+ goto st29;
669
+ goto st5;
637
670
  st6:
638
671
  if ( ++p == pe )
639
672
  goto _test_eof6;
640
673
  case 6:
641
- if ( (*p) == 105 )
642
- goto st7;
674
+ switch( (*p) ) {
675
+ case 42: goto st7;
676
+ case 47: goto st9;
677
+ }
643
678
  goto st0;
644
679
  st7:
645
680
  if ( ++p == pe )
646
681
  goto _test_eof7;
647
682
  case 7:
648
- if ( (*p) == 116 )
683
+ if ( (*p) == 42 )
649
684
  goto st8;
650
- goto st0;
685
+ goto st7;
651
686
  st8:
652
687
  if ( ++p == pe )
653
688
  goto _test_eof8;
654
689
  case 8:
655
- if ( (*p) == 121 )
656
- goto tr16;
657
- goto st0;
690
+ switch( (*p) ) {
691
+ case 42: goto st8;
692
+ case 47: goto st1;
693
+ }
694
+ goto st7;
658
695
  st9:
659
696
  if ( ++p == pe )
660
697
  goto _test_eof9;
661
698
  case 9:
662
- if ( (*p) == 97 )
663
- goto st10;
664
- goto st0;
699
+ if ( (*p) == 10 )
700
+ goto st1;
701
+ goto st9;
665
702
  st10:
666
703
  if ( ++p == pe )
667
704
  goto _test_eof10;
668
705
  case 10:
669
- if ( (*p) == 78 )
670
- goto tr18;
706
+ if ( (*p) == 110 )
707
+ goto st11;
671
708
  goto st0;
672
709
  st11:
673
710
  if ( ++p == pe )
674
711
  goto _test_eof11;
675
712
  case 11:
676
- if ( (*p) == 97 )
713
+ if ( (*p) == 102 )
677
714
  goto st12;
678
715
  goto st0;
679
716
  st12:
680
717
  if ( ++p == pe )
681
718
  goto _test_eof12;
682
719
  case 12:
683
- if ( (*p) == 108 )
720
+ if ( (*p) == 105 )
684
721
  goto st13;
685
722
  goto st0;
686
723
  st13:
687
724
  if ( ++p == pe )
688
725
  goto _test_eof13;
689
726
  case 13:
690
- if ( (*p) == 115 )
727
+ if ( (*p) == 110 )
691
728
  goto st14;
692
729
  goto st0;
693
730
  st14:
694
731
  if ( ++p == pe )
695
732
  goto _test_eof14;
696
733
  case 14:
697
- if ( (*p) == 101 )
698
- goto tr22;
734
+ if ( (*p) == 105 )
735
+ goto st15;
699
736
  goto st0;
700
737
  st15:
701
738
  if ( ++p == pe )
702
739
  goto _test_eof15;
703
740
  case 15:
704
- if ( (*p) == 117 )
741
+ if ( (*p) == 116 )
705
742
  goto st16;
706
743
  goto st0;
707
744
  st16:
708
745
  if ( ++p == pe )
709
746
  goto _test_eof16;
710
747
  case 16:
711
- if ( (*p) == 108 )
712
- goto st17;
748
+ if ( (*p) == 121 )
749
+ goto tr25;
713
750
  goto st0;
714
751
  st17:
715
752
  if ( ++p == pe )
716
753
  goto _test_eof17;
717
754
  case 17:
718
- if ( (*p) == 108 )
719
- goto tr25;
755
+ if ( (*p) == 97 )
756
+ goto st18;
720
757
  goto st0;
721
758
  st18:
722
759
  if ( ++p == pe )
723
760
  goto _test_eof18;
724
761
  case 18:
725
- if ( (*p) == 114 )
726
- goto st19;
762
+ if ( (*p) == 78 )
763
+ goto tr27;
727
764
  goto st0;
728
765
  st19:
729
766
  if ( ++p == pe )
730
767
  goto _test_eof19;
731
768
  case 19:
732
- if ( (*p) == 117 )
769
+ if ( (*p) == 97 )
733
770
  goto st20;
734
771
  goto st0;
735
772
  st20:
736
773
  if ( ++p == pe )
737
774
  goto _test_eof20;
738
775
  case 20:
776
+ if ( (*p) == 108 )
777
+ goto st21;
778
+ goto st0;
779
+ st21:
780
+ if ( ++p == pe )
781
+ goto _test_eof21;
782
+ case 21:
783
+ if ( (*p) == 115 )
784
+ goto st22;
785
+ goto st0;
786
+ st22:
787
+ if ( ++p == pe )
788
+ goto _test_eof22;
789
+ case 22:
739
790
  if ( (*p) == 101 )
740
- goto tr28;
791
+ goto tr31;
792
+ goto st0;
793
+ st23:
794
+ if ( ++p == pe )
795
+ goto _test_eof23;
796
+ case 23:
797
+ if ( (*p) == 117 )
798
+ goto st24;
799
+ goto st0;
800
+ st24:
801
+ if ( ++p == pe )
802
+ goto _test_eof24;
803
+ case 24:
804
+ if ( (*p) == 108 )
805
+ goto st25;
806
+ goto st0;
807
+ st25:
808
+ if ( ++p == pe )
809
+ goto _test_eof25;
810
+ case 25:
811
+ if ( (*p) == 108 )
812
+ goto tr34;
813
+ goto st0;
814
+ st26:
815
+ if ( ++p == pe )
816
+ goto _test_eof26;
817
+ case 26:
818
+ if ( (*p) == 114 )
819
+ goto st27;
820
+ goto st0;
821
+ st27:
822
+ if ( ++p == pe )
823
+ goto _test_eof27;
824
+ case 27:
825
+ if ( (*p) == 117 )
826
+ goto st28;
827
+ goto st0;
828
+ st28:
829
+ if ( ++p == pe )
830
+ goto _test_eof28;
831
+ case 28:
832
+ if ( (*p) == 101 )
833
+ goto tr37;
741
834
  goto st0;
742
835
  }
743
- _test_eof21: cs = 21; goto _test_eof;
836
+ _test_eof1: cs = 1; goto _test_eof;
837
+ _test_eof29: cs = 29; goto _test_eof;
744
838
  _test_eof2: cs = 2; goto _test_eof;
745
839
  _test_eof3: cs = 3; goto _test_eof;
746
840
  _test_eof4: cs = 4; goto _test_eof;
@@ -760,12 +854,20 @@ case 20:
760
854
  _test_eof18: cs = 18; goto _test_eof;
761
855
  _test_eof19: cs = 19; goto _test_eof;
762
856
  _test_eof20: cs = 20; goto _test_eof;
857
+ _test_eof21: cs = 21; goto _test_eof;
858
+ _test_eof22: cs = 22; goto _test_eof;
859
+ _test_eof23: cs = 23; goto _test_eof;
860
+ _test_eof24: cs = 24; goto _test_eof;
861
+ _test_eof25: cs = 25; goto _test_eof;
862
+ _test_eof26: cs = 26; goto _test_eof;
863
+ _test_eof27: cs = 27; goto _test_eof;
864
+ _test_eof28: cs = 28; goto _test_eof;
763
865
 
764
866
  _test_eof: {}
765
867
  _out: {}
766
868
  }
767
869
 
768
- #line 279 "parser.rl"
870
+ #line 292 "parser.rl"
769
871
 
770
872
  if (cs >= JSON_value_first_final) {
771
873
  return p;
@@ -775,15 +877,15 @@ case 20:
775
877
  }
776
878
 
777
879
 
778
- #line 779 "parser.c"
779
- static const int JSON_integer_start = 1;
780
- static const int JSON_integer_first_final = 3;
781
- static const int JSON_integer_error = 0;
880
+ #line 881 "parser.c"
881
+ enum {JSON_integer_start = 1};
882
+ enum {JSON_integer_first_final = 3};
883
+ enum {JSON_integer_error = 0};
782
884
 
783
- static const int JSON_integer_en_main = 1;
885
+ enum {JSON_integer_en_main = 1};
784
886
 
785
887
 
786
- #line 295 "parser.rl"
888
+ #line 308 "parser.rl"
787
889
 
788
890
 
789
891
  static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -791,15 +893,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
791
893
  int cs = EVIL;
792
894
 
793
895
 
794
- #line 795 "parser.c"
896
+ #line 897 "parser.c"
795
897
  {
796
898
  cs = JSON_integer_start;
797
899
  }
798
900
 
799
- #line 302 "parser.rl"
901
+ #line 315 "parser.rl"
800
902
  json->memo = p;
801
903
 
802
- #line 803 "parser.c"
904
+ #line 905 "parser.c"
803
905
  {
804
906
  if ( p == pe )
805
907
  goto _test_eof;
@@ -833,14 +935,14 @@ case 3:
833
935
  goto st0;
834
936
  goto tr4;
835
937
  tr4:
836
- #line 292 "parser.rl"
938
+ #line 305 "parser.rl"
837
939
  { p--; {p++; cs = 4; goto _out;} }
838
940
  goto st4;
839
941
  st4:
840
942
  if ( ++p == pe )
841
943
  goto _test_eof4;
842
944
  case 4:
843
- #line 844 "parser.c"
945
+ #line 946 "parser.c"
844
946
  goto st0;
845
947
  st5:
846
948
  if ( ++p == pe )
@@ -859,7 +961,7 @@ case 5:
859
961
  _out: {}
860
962
  }
861
963
 
862
- #line 304 "parser.rl"
964
+ #line 317 "parser.rl"
863
965
 
864
966
  if (cs >= JSON_integer_first_final) {
865
967
  long len = p - json->memo;
@@ -874,31 +976,44 @@ case 5:
874
976
  }
875
977
 
876
978
 
877
- #line 878 "parser.c"
878
- static const int JSON_float_start = 1;
879
- static const int JSON_float_first_final = 8;
880
- static const int JSON_float_error = 0;
979
+ #line 980 "parser.c"
980
+ enum {JSON_float_start = 1};
981
+ enum {JSON_float_first_final = 8};
982
+ enum {JSON_float_error = 0};
881
983
 
882
- static const int JSON_float_en_main = 1;
984
+ enum {JSON_float_en_main = 1};
883
985
 
884
986
 
885
- #line 329 "parser.rl"
987
+ #line 342 "parser.rl"
886
988
 
887
989
 
990
+ static int is_bigdecimal_class(VALUE obj)
991
+ {
992
+ if (cBigDecimal == Qundef) {
993
+ if (rb_const_defined(rb_cObject, i_BigDecimal)) {
994
+ cBigDecimal = rb_const_get_at(rb_cObject, i_BigDecimal);
995
+ }
996
+ else {
997
+ return 0;
998
+ }
999
+ }
1000
+ return obj == cBigDecimal;
1001
+ }
1002
+
888
1003
  static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
889
1004
  {
890
1005
  int cs = EVIL;
891
1006
 
892
1007
 
893
- #line 894 "parser.c"
1008
+ #line 1009 "parser.c"
894
1009
  {
895
1010
  cs = JSON_float_start;
896
1011
  }
897
1012
 
898
- #line 336 "parser.rl"
1013
+ #line 362 "parser.rl"
899
1014
  json->memo = p;
900
1015
 
901
- #line 902 "parser.c"
1016
+ #line 1017 "parser.c"
902
1017
  {
903
1018
  if ( p == pe )
904
1019
  goto _test_eof;
@@ -956,14 +1071,14 @@ case 8:
956
1071
  goto st0;
957
1072
  goto tr9;
958
1073
  tr9:
959
- #line 323 "parser.rl"
1074
+ #line 336 "parser.rl"
960
1075
  { p--; {p++; cs = 9; goto _out;} }
961
1076
  goto st9;
962
1077
  st9:
963
1078
  if ( ++p == pe )
964
1079
  goto _test_eof9;
965
1080
  case 9:
966
- #line 967 "parser.c"
1081
+ #line 1082 "parser.c"
967
1082
  goto st0;
968
1083
  st5:
969
1084
  if ( ++p == pe )
@@ -1024,14 +1139,24 @@ case 7:
1024
1139
  _out: {}
1025
1140
  }
1026
1141
 
1027
- #line 338 "parser.rl"
1142
+ #line 364 "parser.rl"
1028
1143
 
1029
1144
  if (cs >= JSON_float_first_final) {
1030
1145
  long len = p - json->memo;
1031
1146
  fbuffer_clear(json->fbuffer);
1032
1147
  fbuffer_append(json->fbuffer, json->memo, len);
1033
1148
  fbuffer_append_char(json->fbuffer, '\0');
1034
- *result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
1149
+ if (NIL_P(json->decimal_class)) {
1150
+ *result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
1151
+ } else {
1152
+ VALUE text;
1153
+ text = rb_str_new2(FBUFFER_PTR(json->fbuffer));
1154
+ if (is_bigdecimal_class(json->decimal_class)) {
1155
+ *result = rb_funcall(Qnil, i_BigDecimal, 1, text);
1156
+ } else {
1157
+ *result = rb_funcall(json->decimal_class, i_new, 1, text);
1158
+ }
1159
+ }
1035
1160
  return p + 1;
1036
1161
  } else {
1037
1162
  return NULL;
@@ -1040,36 +1165,36 @@ case 7:
1040
1165
 
1041
1166
 
1042
1167
 
1043
- #line 1044 "parser.c"
1044
- static const int JSON_array_start = 1;
1045
- static const int JSON_array_first_final = 17;
1046
- static const int JSON_array_error = 0;
1168
+ #line 1169 "parser.c"
1169
+ enum {JSON_array_start = 1};
1170
+ enum {JSON_array_first_final = 17};
1171
+ enum {JSON_array_error = 0};
1047
1172
 
1048
- static const int JSON_array_en_main = 1;
1173
+ enum {JSON_array_en_main = 1};
1049
1174
 
1050
1175
 
1051
- #line 381 "parser.rl"
1176
+ #line 417 "parser.rl"
1052
1177
 
1053
1178
 
1054
- static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
1179
+ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
1055
1180
  {
1056
1181
  int cs = EVIL;
1057
1182
  VALUE array_class = json->array_class;
1058
1183
 
1059
- if (json->max_nesting && json->current_nesting > json->max_nesting) {
1060
- rb_raise(eNestingError, "nesting of %d is too deep", json->current_nesting);
1184
+ if (json->max_nesting && current_nesting > json->max_nesting) {
1185
+ rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
1061
1186
  }
1062
1187
  *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
1063
1188
 
1064
1189
 
1065
- #line 1066 "parser.c"
1190
+ #line 1191 "parser.c"
1066
1191
  {
1067
1192
  cs = JSON_array_start;
1068
1193
  }
1069
1194
 
1070
- #line 394 "parser.rl"
1195
+ #line 430 "parser.rl"
1071
1196
 
1072
- #line 1073 "parser.c"
1197
+ #line 1198 "parser.c"
1073
1198
  {
1074
1199
  if ( p == pe )
1075
1200
  goto _test_eof;
@@ -1108,10 +1233,10 @@ case 2:
1108
1233
  goto st2;
1109
1234
  goto st0;
1110
1235
  tr2:
1111
- #line 358 "parser.rl"
1236
+ #line 394 "parser.rl"
1112
1237
  {
1113
1238
  VALUE v = Qnil;
1114
- char *np = JSON_parse_value(json, p, pe, &v);
1239
+ char *np = JSON_parse_value(json, p, pe, &v, current_nesting);
1115
1240
  if (np == NULL) {
1116
1241
  p--; {p++; cs = 3; goto _out;}
1117
1242
  } else {
@@ -1128,7 +1253,7 @@ st3:
1128
1253
  if ( ++p == pe )
1129
1254
  goto _test_eof3;
1130
1255
  case 3:
1131
- #line 1132 "parser.c"
1256
+ #line 1257 "parser.c"
1132
1257
  switch( (*p) ) {
1133
1258
  case 13: goto st3;
1134
1259
  case 32: goto st3;
@@ -1228,14 +1353,14 @@ case 12:
1228
1353
  goto st3;
1229
1354
  goto st12;
1230
1355
  tr4:
1231
- #line 373 "parser.rl"
1356
+ #line 409 "parser.rl"
1232
1357
  { p--; {p++; cs = 17; goto _out;} }
1233
1358
  goto st17;
1234
1359
  st17:
1235
1360
  if ( ++p == pe )
1236
1361
  goto _test_eof17;
1237
1362
  case 17:
1238
- #line 1239 "parser.c"
1363
+ #line 1364 "parser.c"
1239
1364
  goto st0;
1240
1365
  st13:
1241
1366
  if ( ++p == pe )
@@ -1291,12 +1416,12 @@ case 16:
1291
1416
  _out: {}
1292
1417
  }
1293
1418
 
1294
- #line 395 "parser.rl"
1419
+ #line 431 "parser.rl"
1295
1420
 
1296
1421
  if(cs >= JSON_array_first_final) {
1297
1422
  return p + 1;
1298
1423
  } else {
1299
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
1424
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
1300
1425
  return NULL;
1301
1426
  }
1302
1427
  }
@@ -1336,13 +1461,21 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
1336
1461
  break;
1337
1462
  case 'u':
1338
1463
  if (pe > stringEnd - 4) {
1339
- return Qnil;
1464
+ rb_enc_raise(
1465
+ EXC_ENCODING eParserError,
1466
+ "%u: incomplete unicode character escape sequence at '%s'", __LINE__, p
1467
+ );
1340
1468
  } else {
1341
1469
  UTF32 ch = unescape_unicode((unsigned char *) ++pe);
1342
1470
  pe += 3;
1343
1471
  if (UNI_SUR_HIGH_START == (ch & 0xFC00)) {
1344
1472
  pe++;
1345
- if (pe > stringEnd - 6) return Qnil;
1473
+ if (pe > stringEnd - 6) {
1474
+ rb_enc_raise(
1475
+ EXC_ENCODING eParserError,
1476
+ "%u: incomplete surrogate pair at '%s'", __LINE__, p
1477
+ );
1478
+ }
1346
1479
  if (pe[0] == '\\' && pe[1] == 'u') {
1347
1480
  UTF32 sur = unescape_unicode((unsigned char *) pe + 2);
1348
1481
  ch = (((ch & 0x3F) << 10) | ((((ch >> 6) & 0xF) + 1) << 16)
@@ -1372,15 +1505,15 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
1372
1505
  }
1373
1506
 
1374
1507
 
1375
- #line 1376 "parser.c"
1376
- static const int JSON_string_start = 1;
1377
- static const int JSON_string_first_final = 8;
1378
- static const int JSON_string_error = 0;
1508
+ #line 1509 "parser.c"
1509
+ enum {JSON_string_start = 1};
1510
+ enum {JSON_string_first_final = 8};
1511
+ enum {JSON_string_error = 0};
1379
1512
 
1380
- static const int JSON_string_en_main = 1;
1513
+ enum {JSON_string_en_main = 1};
1381
1514
 
1382
1515
 
1383
- #line 494 "parser.rl"
1516
+ #line 538 "parser.rl"
1384
1517
 
1385
1518
 
1386
1519
  static int
@@ -1402,15 +1535,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
1402
1535
 
1403
1536
  *result = rb_str_buf_new(0);
1404
1537
 
1405
- #line 1406 "parser.c"
1538
+ #line 1539 "parser.c"
1406
1539
  {
1407
1540
  cs = JSON_string_start;
1408
1541
  }
1409
1542
 
1410
- #line 515 "parser.rl"
1543
+ #line 559 "parser.rl"
1411
1544
  json->memo = p;
1412
1545
 
1413
- #line 1414 "parser.c"
1546
+ #line 1547 "parser.c"
1414
1547
  {
1415
1548
  if ( p == pe )
1416
1549
  goto _test_eof;
@@ -1431,11 +1564,11 @@ case 2:
1431
1564
  case 34: goto tr2;
1432
1565
  case 92: goto st3;
1433
1566
  }
1434
- if ( 0 <= (*p) && (*p) <= 31 )
1567
+ if ( 0 <= (signed char)(*p) && (*p) <= 31 )
1435
1568
  goto st0;
1436
1569
  goto st2;
1437
1570
  tr2:
1438
- #line 480 "parser.rl"
1571
+ #line 524 "parser.rl"
1439
1572
  {
1440
1573
  *result = json_string_unescape(*result, json->memo + 1, p);
1441
1574
  if (NIL_P(*result)) {
@@ -1446,14 +1579,14 @@ tr2:
1446
1579
  {p = (( p + 1))-1;}
1447
1580
  }
1448
1581
  }
1449
- #line 491 "parser.rl"
1582
+ #line 535 "parser.rl"
1450
1583
  { p--; {p++; cs = 8; goto _out;} }
1451
1584
  goto st8;
1452
1585
  st8:
1453
1586
  if ( ++p == pe )
1454
1587
  goto _test_eof8;
1455
1588
  case 8:
1456
- #line 1457 "parser.c"
1589
+ #line 1590 "parser.c"
1457
1590
  goto st0;
1458
1591
  st3:
1459
1592
  if ( ++p == pe )
@@ -1461,7 +1594,7 @@ st3:
1461
1594
  case 3:
1462
1595
  if ( (*p) == 117 )
1463
1596
  goto st4;
1464
- if ( 0 <= (*p) && (*p) <= 31 )
1597
+ if ( 0 <= (signed char)(*p) && (*p) <= 31 )
1465
1598
  goto st0;
1466
1599
  goto st2;
1467
1600
  st4:
@@ -1529,7 +1662,7 @@ case 7:
1529
1662
  _out: {}
1530
1663
  }
1531
1664
 
1532
- #line 517 "parser.rl"
1665
+ #line 561 "parser.rl"
1533
1666
 
1534
1667
  if (json->create_additions && RTEST(match_string = json->match_string)) {
1535
1668
  VALUE klass;
@@ -1544,6 +1677,8 @@ case 7:
1544
1677
 
1545
1678
  if (json->symbolize_names && json->parsing_name) {
1546
1679
  *result = rb_str_intern(*result);
1680
+ } else if (RB_TYPE_P(*result, T_STRING)) {
1681
+ rb_str_resize(*result, RSTRING_LEN(*result));
1547
1682
  }
1548
1683
  if (cs >= JSON_string_first_final) {
1549
1684
  return p + 1;
@@ -1566,41 +1701,16 @@ case 7:
1566
1701
 
1567
1702
  static VALUE convert_encoding(VALUE source)
1568
1703
  {
1569
- char *ptr = RSTRING_PTR(source);
1570
- long len = RSTRING_LEN(source);
1571
- if (len < 2) {
1572
- rb_raise(eParserError, "A JSON text must at least contain two octets!");
1573
- }
1574
1704
  #ifdef HAVE_RUBY_ENCODING_H
1575
- {
1576
- VALUE encoding = rb_funcall(source, i_encoding, 0);
1577
- if (encoding == CEncoding_ASCII_8BIT) {
1578
- if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
1579
- source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32BE);
1580
- } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
1581
- source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16BE);
1582
- } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
1583
- source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_32LE);
1584
- } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
1585
- source = rb_funcall(source, i_encode, 2, CEncoding_UTF_8, CEncoding_UTF_16LE);
1586
- } else {
1587
- source = rb_str_dup(source);
1588
- FORCE_UTF8(source);
1589
- }
1590
- } else {
1591
- source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8);
1592
- }
1593
- }
1594
- #else
1595
- if (len >= 4 && ptr[0] == 0 && ptr[1] == 0 && ptr[2] == 0) {
1596
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-32be"), source);
1597
- } else if (len >= 4 && ptr[0] == 0 && ptr[2] == 0) {
1598
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-16be"), source);
1599
- } else if (len >= 4 && ptr[1] == 0 && ptr[2] == 0 && ptr[3] == 0) {
1600
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-32le"), source);
1601
- } else if (len >= 4 && ptr[1] == 0 && ptr[3] == 0) {
1602
- source = rb_funcall(mJSON, i_iconv, 3, rb_str_new2("utf-8"), rb_str_new2("utf-16le"), source);
1705
+ rb_encoding *enc = rb_enc_get(source);
1706
+ if (enc == rb_ascii8bit_encoding()) {
1707
+ if (OBJ_FROZEN(source)) {
1708
+ source = rb_str_dup(source);
1603
1709
  }
1710
+ FORCE_UTF8(source);
1711
+ } else {
1712
+ source = rb_str_conv_enc(source, rb_enc_get(source), rb_utf8_encoding());
1713
+ }
1604
1714
  #endif
1605
1715
  return source;
1606
1716
  }
@@ -1623,8 +1733,9 @@ static VALUE convert_encoding(VALUE source)
1623
1733
  * defiance of RFC 4627 to be parsed by the Parser. This option defaults to
1624
1734
  * false.
1625
1735
  * * *symbolize_names*: If set to true, returns symbols for the names
1626
- * (keys) in a JSON object. Otherwise strings are returned, which is also
1627
- * the default.
1736
+ * (keys) in a JSON object. Otherwise strings are returned, which is
1737
+ * also the default. It's not possible to use this option in
1738
+ * conjunction with the *create_additions* option.
1628
1739
  * * *create_additions*: If set to false, the Parser doesn't create
1629
1740
  * additions even if a matching class and create_id was found. This option
1630
1741
  * defaults to false.
@@ -1639,12 +1750,18 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1639
1750
  if (json->Vsource) {
1640
1751
  rb_raise(rb_eTypeError, "already initialized instance");
1641
1752
  }
1753
+ #ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
1754
+ rb_scan_args(argc, argv, "1:", &source, &opts);
1755
+ #else
1642
1756
  rb_scan_args(argc, argv, "11", &source, &opts);
1757
+ #endif
1643
1758
  if (!NIL_P(opts)) {
1759
+ #ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
1644
1760
  opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
1645
1761
  if (NIL_P(opts)) {
1646
1762
  rb_raise(rb_eArgError, "opts needs to be like a hash");
1647
1763
  } else {
1764
+ #endif
1648
1765
  VALUE tmp = ID2SYM(i_max_nesting);
1649
1766
  if (option_given_p(opts, tmp)) {
1650
1767
  VALUE max_nesting = rb_hash_aref(opts, tmp);
@@ -1669,19 +1786,17 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1669
1786
  } else {
1670
1787
  json->symbolize_names = 0;
1671
1788
  }
1672
- tmp = ID2SYM(i_quirks_mode);
1673
- if (option_given_p(opts, tmp)) {
1674
- VALUE quirks_mode = rb_hash_aref(opts, tmp);
1675
- json->quirks_mode = RTEST(quirks_mode) ? 1 : 0;
1676
- } else {
1677
- json->quirks_mode = 0;
1678
- }
1679
1789
  tmp = ID2SYM(i_create_additions);
1680
1790
  if (option_given_p(opts, tmp)) {
1681
1791
  json->create_additions = RTEST(rb_hash_aref(opts, tmp));
1682
1792
  } else {
1683
1793
  json->create_additions = 0;
1684
1794
  }
1795
+ if (json->symbolize_names && json->create_additions) {
1796
+ rb_raise(rb_eArgError,
1797
+ "options :symbolize_names and :create_additions cannot be "
1798
+ " used in conjunction");
1799
+ }
1685
1800
  tmp = ID2SYM(i_create_id);
1686
1801
  if (option_given_p(opts, tmp)) {
1687
1802
  json->create_id = rb_hash_aref(opts, tmp);
@@ -1700,6 +1815,12 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1700
1815
  } else {
1701
1816
  json->array_class = Qnil;
1702
1817
  }
1818
+ tmp = ID2SYM(i_decimal_class);
1819
+ if (option_given_p(opts, tmp)) {
1820
+ json->decimal_class = rb_hash_aref(opts, tmp);
1821
+ } else {
1822
+ json->decimal_class = Qnil;
1823
+ }
1703
1824
  tmp = ID2SYM(i_match_string);
1704
1825
  if (option_given_p(opts, tmp)) {
1705
1826
  VALUE match_string = rb_hash_aref(opts, tmp);
@@ -1707,20 +1828,19 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1707
1828
  } else {
1708
1829
  json->match_string = Qnil;
1709
1830
  }
1831
+ #ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
1710
1832
  }
1833
+ #endif
1711
1834
  } else {
1712
1835
  json->max_nesting = 100;
1713
1836
  json->allow_nan = 0;
1714
- json->create_additions = 1;
1837
+ json->create_additions = 0;
1715
1838
  json->create_id = rb_funcall(mJSON, i_create_id, 0);
1716
1839
  json->object_class = Qnil;
1717
1840
  json->array_class = Qnil;
1841
+ json->decimal_class = Qnil;
1718
1842
  }
1719
- source = rb_convert_type(source, T_STRING, "String", "to_str");
1720
- if (!json->quirks_mode) {
1721
- source = convert_encoding(StringValue(source));
1722
- }
1723
- json->current_nesting = 0;
1843
+ source = convert_encoding(StringValue(source));
1724
1844
  StringValue(source);
1725
1845
  json->len = RSTRING_LEN(source);
1726
1846
  json->source = RSTRING_PTR(source);;
@@ -1729,209 +1849,41 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1729
1849
  }
1730
1850
 
1731
1851
 
1732
- #line 1733 "parser.c"
1733
- static const int JSON_start = 1;
1734
- static const int JSON_first_final = 10;
1735
- static const int JSON_error = 0;
1852
+ #line 1853 "parser.c"
1853
+ enum {JSON_start = 1};
1854
+ enum {JSON_first_final = 10};
1855
+ enum {JSON_error = 0};
1736
1856
 
1737
- static const int JSON_en_main = 1;
1857
+ enum {JSON_en_main = 1};
1738
1858
 
1739
1859
 
1740
- #line 740 "parser.rl"
1860
+ #line 761 "parser.rl"
1741
1861
 
1742
1862
 
1743
- static VALUE cParser_parse_strict(VALUE self)
1863
+ /*
1864
+ * call-seq: parse()
1865
+ *
1866
+ * Parses the current JSON text _source_ and returns the complete data
1867
+ * structure as a result.
1868
+ */
1869
+ static VALUE cParser_parse(VALUE self)
1744
1870
  {
1745
- char *p, *pe;
1746
- int cs = EVIL;
1747
- VALUE result = Qnil;
1748
- GET_PARSER;
1871
+ char *p, *pe;
1872
+ int cs = EVIL;
1873
+ VALUE result = Qnil;
1874
+ GET_PARSER;
1749
1875
 
1750
1876
 
1751
- #line 1752 "parser.c"
1877
+ #line 1878 "parser.c"
1752
1878
  {
1753
1879
  cs = JSON_start;
1754
1880
  }
1755
1881
 
1756
- #line 750 "parser.rl"
1757
- p = json->source;
1758
- pe = p + json->len;
1882
+ #line 777 "parser.rl"
1883
+ p = json->source;
1884
+ pe = p + json->len;
1759
1885
 
1760
- #line 1761 "parser.c"
1761
- {
1762
- if ( p == pe )
1763
- goto _test_eof;
1764
- switch ( cs )
1765
- {
1766
- st1:
1767
- if ( ++p == pe )
1768
- goto _test_eof1;
1769
- case 1:
1770
- switch( (*p) ) {
1771
- case 13: goto st1;
1772
- case 32: goto st1;
1773
- case 47: goto st2;
1774
- case 91: goto tr3;
1775
- case 123: goto tr4;
1776
- }
1777
- if ( 9 <= (*p) && (*p) <= 10 )
1778
- goto st1;
1779
- goto st0;
1780
- st0:
1781
- cs = 0;
1782
- goto _out;
1783
- st2:
1784
- if ( ++p == pe )
1785
- goto _test_eof2;
1786
- case 2:
1787
- switch( (*p) ) {
1788
- case 42: goto st3;
1789
- case 47: goto st5;
1790
- }
1791
- goto st0;
1792
- st3:
1793
- if ( ++p == pe )
1794
- goto _test_eof3;
1795
- case 3:
1796
- if ( (*p) == 42 )
1797
- goto st4;
1798
- goto st3;
1799
- st4:
1800
- if ( ++p == pe )
1801
- goto _test_eof4;
1802
- case 4:
1803
- switch( (*p) ) {
1804
- case 42: goto st4;
1805
- case 47: goto st1;
1806
- }
1807
- goto st3;
1808
- st5:
1809
- if ( ++p == pe )
1810
- goto _test_eof5;
1811
- case 5:
1812
- if ( (*p) == 10 )
1813
- goto st1;
1814
- goto st5;
1815
- tr3:
1816
- #line 729 "parser.rl"
1817
- {
1818
- char *np;
1819
- json->current_nesting = 1;
1820
- np = JSON_parse_array(json, p, pe, &result);
1821
- if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
1822
- }
1823
- goto st10;
1824
- tr4:
1825
- #line 722 "parser.rl"
1826
- {
1827
- char *np;
1828
- json->current_nesting = 1;
1829
- np = JSON_parse_object(json, p, pe, &result);
1830
- if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
1831
- }
1832
- goto st10;
1833
- st10:
1834
- if ( ++p == pe )
1835
- goto _test_eof10;
1836
- case 10:
1837
- #line 1838 "parser.c"
1838
- switch( (*p) ) {
1839
- case 13: goto st10;
1840
- case 32: goto st10;
1841
- case 47: goto st6;
1842
- }
1843
- if ( 9 <= (*p) && (*p) <= 10 )
1844
- goto st10;
1845
- goto st0;
1846
- st6:
1847
- if ( ++p == pe )
1848
- goto _test_eof6;
1849
- case 6:
1850
- switch( (*p) ) {
1851
- case 42: goto st7;
1852
- case 47: goto st9;
1853
- }
1854
- goto st0;
1855
- st7:
1856
- if ( ++p == pe )
1857
- goto _test_eof7;
1858
- case 7:
1859
- if ( (*p) == 42 )
1860
- goto st8;
1861
- goto st7;
1862
- st8:
1863
- if ( ++p == pe )
1864
- goto _test_eof8;
1865
- case 8:
1866
- switch( (*p) ) {
1867
- case 42: goto st8;
1868
- case 47: goto st10;
1869
- }
1870
- goto st7;
1871
- st9:
1872
- if ( ++p == pe )
1873
- goto _test_eof9;
1874
- case 9:
1875
- if ( (*p) == 10 )
1876
- goto st10;
1877
- goto st9;
1878
- }
1879
- _test_eof1: cs = 1; goto _test_eof;
1880
- _test_eof2: cs = 2; goto _test_eof;
1881
- _test_eof3: cs = 3; goto _test_eof;
1882
- _test_eof4: cs = 4; goto _test_eof;
1883
- _test_eof5: cs = 5; goto _test_eof;
1884
- _test_eof10: cs = 10; goto _test_eof;
1885
- _test_eof6: cs = 6; goto _test_eof;
1886
- _test_eof7: cs = 7; goto _test_eof;
1887
- _test_eof8: cs = 8; goto _test_eof;
1888
- _test_eof9: cs = 9; goto _test_eof;
1889
-
1890
- _test_eof: {}
1891
- _out: {}
1892
- }
1893
-
1894
- #line 753 "parser.rl"
1895
-
1896
- if (cs >= JSON_first_final && p == pe) {
1897
- return result;
1898
- } else {
1899
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
1900
- return Qnil;
1901
- }
1902
- }
1903
-
1904
-
1905
-
1906
- #line 1907 "parser.c"
1907
- static const int JSON_quirks_mode_start = 1;
1908
- static const int JSON_quirks_mode_first_final = 10;
1909
- static const int JSON_quirks_mode_error = 0;
1910
-
1911
- static const int JSON_quirks_mode_en_main = 1;
1912
-
1913
-
1914
- #line 778 "parser.rl"
1915
-
1916
-
1917
- static VALUE cParser_parse_quirks_mode(VALUE self)
1918
- {
1919
- char *p, *pe;
1920
- int cs = EVIL;
1921
- VALUE result = Qnil;
1922
- GET_PARSER;
1923
-
1924
-
1925
- #line 1926 "parser.c"
1926
- {
1927
- cs = JSON_quirks_mode_start;
1928
- }
1929
-
1930
- #line 788 "parser.rl"
1931
- p = json->source;
1932
- pe = p + json->len;
1933
-
1934
- #line 1935 "parser.c"
1886
+ #line 1887 "parser.c"
1935
1887
  {
1936
1888
  if ( p == pe )
1937
1889
  goto _test_eof;
@@ -1965,9 +1917,9 @@ st0:
1965
1917
  cs = 0;
1966
1918
  goto _out;
1967
1919
  tr2:
1968
- #line 770 "parser.rl"
1920
+ #line 753 "parser.rl"
1969
1921
  {
1970
- char *np = JSON_parse_value(json, p, pe, &result);
1922
+ char *np = JSON_parse_value(json, p, pe, &result, 0);
1971
1923
  if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
1972
1924
  }
1973
1925
  goto st10;
@@ -1975,7 +1927,7 @@ st10:
1975
1927
  if ( ++p == pe )
1976
1928
  goto _test_eof10;
1977
1929
  case 10:
1978
- #line 1979 "parser.c"
1930
+ #line 1931 "parser.c"
1979
1931
  switch( (*p) ) {
1980
1932
  case 13: goto st10;
1981
1933
  case 32: goto st10;
@@ -2064,42 +2016,16 @@ case 9:
2064
2016
  _out: {}
2065
2017
  }
2066
2018
 
2067
- #line 791 "parser.rl"
2068
-
2069
- if (cs >= JSON_quirks_mode_first_final && p == pe) {
2070
- return result;
2071
- } else {
2072
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
2073
- return Qnil;
2074
- }
2075
- }
2019
+ #line 780 "parser.rl"
2076
2020
 
2077
- /*
2078
- * call-seq: parse()
2079
- *
2080
- * Parses the current JSON text _source_ and returns the complete data
2081
- * structure as a result.
2082
- */
2083
- static VALUE cParser_parse(VALUE self)
2084
- {
2085
- GET_PARSER;
2086
-
2087
- if (json->quirks_mode) {
2088
- return cParser_parse_quirks_mode(self);
2021
+ if (cs >= JSON_first_final && p == pe) {
2022
+ return result;
2089
2023
  } else {
2090
- return cParser_parse_strict(self);
2024
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
2025
+ return Qnil;
2091
2026
  }
2092
2027
  }
2093
2028
 
2094
-
2095
- static JSON_Parser *JSON_allocate(void)
2096
- {
2097
- JSON_Parser *json = ALLOC(JSON_Parser);
2098
- MEMZERO(json, JSON_Parser, 1);
2099
- json->fbuffer = fbuffer_alloc(0);
2100
- return json;
2101
- }
2102
-
2103
2029
  static void JSON_mark(void *ptr)
2104
2030
  {
2105
2031
  JSON_Parser *json = ptr;
@@ -2107,6 +2033,7 @@ static void JSON_mark(void *ptr)
2107
2033
  rb_gc_mark_maybe(json->create_id);
2108
2034
  rb_gc_mark_maybe(json->object_class);
2109
2035
  rb_gc_mark_maybe(json->array_class);
2036
+ rb_gc_mark_maybe(json->decimal_class);
2110
2037
  rb_gc_mark_maybe(json->match_string);
2111
2038
  }
2112
2039
 
@@ -2136,8 +2063,10 @@ static const rb_data_type_t JSON_Parser_type = {
2136
2063
 
2137
2064
  static VALUE cJSON_parser_s_allocate(VALUE klass)
2138
2065
  {
2139
- JSON_Parser *json = JSON_allocate();
2140
- return TypedData_Wrap_Struct(klass, &JSON_Parser_type, json);
2066
+ JSON_Parser *json;
2067
+ VALUE obj = TypedData_Make_Struct(klass, JSON_Parser, &JSON_Parser_type, json);
2068
+ json->fbuffer = fbuffer_alloc(0);
2069
+ return obj;
2141
2070
  }
2142
2071
 
2143
2072
  /*
@@ -2152,35 +2081,30 @@ static VALUE cParser_source(VALUE self)
2152
2081
  return rb_str_dup(json->Vsource);
2153
2082
  }
2154
2083
 
2155
- /*
2156
- * call-seq: quirks_mode?()
2157
- *
2158
- * Returns a true, if this parser is in quirks_mode, false otherwise.
2159
- */
2160
- static VALUE cParser_quirks_mode_p(VALUE self)
2161
- {
2162
- GET_PARSER;
2163
- return json->quirks_mode ? Qtrue : Qfalse;
2164
- }
2165
-
2166
-
2167
- void Init_parser()
2084
+ void Init_parser(void)
2168
2085
  {
2086
+ #undef rb_intern
2169
2087
  rb_require("json/common");
2170
2088
  mJSON = rb_define_module("JSON");
2171
2089
  mExt = rb_define_module_under(mJSON, "Ext");
2172
2090
  cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
2173
2091
  eParserError = rb_path2class("JSON::ParserError");
2174
2092
  eNestingError = rb_path2class("JSON::NestingError");
2093
+ rb_gc_register_mark_object(eParserError);
2094
+ rb_gc_register_mark_object(eNestingError);
2175
2095
  rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
2176
2096
  rb_define_method(cParser, "initialize", cParser_initialize, -1);
2177
2097
  rb_define_method(cParser, "parse", cParser_parse, 0);
2178
2098
  rb_define_method(cParser, "source", cParser_source, 0);
2179
- rb_define_method(cParser, "quirks_mode?", cParser_quirks_mode_p, 0);
2180
2099
 
2181
2100
  CNaN = rb_const_get(mJSON, rb_intern("NaN"));
2101
+ rb_gc_register_mark_object(CNaN);
2102
+
2182
2103
  CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
2104
+ rb_gc_register_mark_object(CInfinity);
2105
+
2183
2106
  CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
2107
+ rb_gc_register_mark_object(CMinusInfinity);
2184
2108
 
2185
2109
  i_json_creatable_p = rb_intern("json_creatable?");
2186
2110
  i_json_create = rb_intern("json_create");
@@ -2190,9 +2114,9 @@ void Init_parser()
2190
2114
  i_max_nesting = rb_intern("max_nesting");
2191
2115
  i_allow_nan = rb_intern("allow_nan");
2192
2116
  i_symbolize_names = rb_intern("symbolize_names");
2193
- i_quirks_mode = rb_intern("quirks_mode");
2194
2117
  i_object_class = rb_intern("object_class");
2195
2118
  i_array_class = rb_intern("array_class");
2119
+ i_decimal_class = rb_intern("decimal_class");
2196
2120
  i_match = rb_intern("match");
2197
2121
  i_match_string = rb_intern("match_string");
2198
2122
  i_key_p = rb_intern("key?");
@@ -2200,18 +2124,8 @@ void Init_parser()
2200
2124
  i_aset = rb_intern("[]=");
2201
2125
  i_aref = rb_intern("[]");
2202
2126
  i_leftshift = rb_intern("<<");
2203
- #ifdef HAVE_RUBY_ENCODING_H
2204
- CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
2205
- CEncoding_UTF_16BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16be"));
2206
- CEncoding_UTF_16LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16le"));
2207
- CEncoding_UTF_32BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32be"));
2208
- CEncoding_UTF_32LE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-32le"));
2209
- CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
2210
- i_encoding = rb_intern("encoding");
2211
- i_encode = rb_intern("encode");
2212
- #else
2213
- i_iconv = rb_intern("iconv");
2214
- #endif
2127
+ i_new = rb_intern("new");
2128
+ i_BigDecimal = rb_intern("BigDecimal");
2215
2129
  }
2216
2130
 
2217
2131
  /*