json_pure 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,19 +7,10 @@
7
7
 
8
8
  #include "ruby.h"
9
9
 
10
- #if HAVE_RUBY_RE_H
10
+ #ifdef HAVE_RUBY_RE_H
11
11
  #include "ruby/re.h"
12
- #endif
13
-
14
- #if HAVE_RE_H
15
- #include "re.h"
16
- #endif
17
-
18
- #ifdef HAVE_RUBY_ENCODING_H
19
- #include "ruby/encoding.h"
20
- #define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
21
12
  #else
22
- #define FORCE_UTF8(obj)
13
+ #include "re.h"
23
14
  #endif
24
15
 
25
16
  #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
@@ -45,38 +36,6 @@
45
36
  #define RSTRING_LEN(string) RSTRING(string)->len
46
37
  #endif
47
38
 
48
- /* We don't need to guard objects for rbx, so let's do nothing at all. */
49
- #ifndef RB_GC_GUARD
50
- #define RB_GC_GUARD(object)
51
- #endif
52
-
53
- /* fbuffer implementation */
54
-
55
- typedef struct FBufferStruct {
56
- unsigned long initial_length;
57
- char *ptr;
58
- unsigned long len;
59
- unsigned long capa;
60
- } FBuffer;
61
-
62
- #define FBUFFER_INITIAL_LENGTH 4096
63
-
64
- #define FBUFFER_PTR(fb) (fb->ptr)
65
- #define FBUFFER_LEN(fb) (fb->len)
66
- #define FBUFFER_CAPA(fb) (fb->capa)
67
- #define FBUFFER_PAIR(fb) FBUFFER_PTR(fb), FBUFFER_LEN(fb)
68
-
69
- static char *fstrndup(const char *ptr, unsigned long len);
70
- static FBuffer *fbuffer_alloc();
71
- static FBuffer *fbuffer_alloc_with_length(unsigned long initial_length);
72
- static void fbuffer_free(FBuffer *fb);
73
- static void fbuffer_clear(FBuffer *fb);
74
- static void fbuffer_append(FBuffer *fb, const char *newstr, unsigned long len);
75
- static void fbuffer_append_long(FBuffer *fb, long number);
76
- static void fbuffer_append_char(FBuffer *fb, char newchr);
77
- static FBuffer *fbuffer_dup(FBuffer *fb);
78
- static VALUE fbuffer_to_s(FBuffer *fb);
79
-
80
39
  /* unicode defintions */
81
40
 
82
41
  #define UNI_STRICT_CONVERSION 1
@@ -106,6 +65,7 @@ static void unicode_escape(char *buf, UTF16 character);
106
65
  static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character);
107
66
  static void convert_UTF8_to_JSON_ASCII(FBuffer *buffer, VALUE string);
108
67
  static void convert_UTF8_to_JSON(FBuffer *buffer, VALUE string);
68
+ static char *fstrndup(const char *ptr, unsigned long len);
109
69
 
110
70
  /* ruby api and some helpers */
111
71
 
@@ -128,6 +88,7 @@ typedef struct JSON_Generator_StateStruct {
128
88
  char ascii_only;
129
89
  char quirks_mode;
130
90
  long depth;
91
+ long buffer_initial_length;
131
92
  } JSON_Generator_State;
132
93
 
133
94
  #define GET_STATE(self) \
@@ -1,5 +1,4 @@
1
1
  require 'mkmf'
2
- require 'rbconfig'
3
2
 
4
3
  unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
5
4
  $CFLAGS << ' -O3'
@@ -11,6 +10,4 @@ if CONFIG['CC'] =~ /gcc/
11
10
  #end
12
11
  end
13
12
 
14
- have_header("re.h")
15
- have_header("ruby/st.h")
16
13
  create_makefile 'json/ext/parser'
@@ -1,5 +1,6 @@
1
1
 
2
2
  #line 1 "parser.rl"
3
+ #include "../fbuffer/fbuffer.h"
3
4
  #include "parser.h"
4
5
 
5
6
  /* unicode */
@@ -83,11 +84,11 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
83
84
  i_match_string, i_aset, i_leftshift;
84
85
 
85
86
 
86
- #line 109 "parser.rl"
87
+ #line 110 "parser.rl"
87
88
 
88
89
 
89
90
 
90
- #line 91 "parser.c"
91
+ #line 92 "parser.c"
91
92
  static const int JSON_object_start = 1;
92
93
  static const int JSON_object_first_final = 27;
93
94
  static const int JSON_object_error = 0;
@@ -95,7 +96,7 @@ static const int JSON_object_error = 0;
95
96
  static const int JSON_object_en_main = 1;
96
97
 
97
98
 
98
- #line 150 "parser.rl"
99
+ #line 151 "parser.rl"
99
100
 
100
101
 
101
102
  static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -111,14 +112,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
111
112
  *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
112
113
 
113
114
 
114
- #line 115 "parser.c"
115
+ #line 116 "parser.c"
115
116
  {
116
117
  cs = JSON_object_start;
117
118
  }
118
119
 
119
- #line 165 "parser.rl"
120
+ #line 166 "parser.rl"
120
121
 
121
- #line 122 "parser.c"
122
+ #line 123 "parser.c"
122
123
  {
123
124
  if ( p == pe )
124
125
  goto _test_eof;
@@ -146,7 +147,7 @@ case 2:
146
147
  goto st2;
147
148
  goto st0;
148
149
  tr2:
149
- #line 132 "parser.rl"
150
+ #line 133 "parser.rl"
150
151
  {
151
152
  char *np;
152
153
  json->parsing_name = 1;
@@ -159,7 +160,7 @@ st3:
159
160
  if ( ++p == pe )
160
161
  goto _test_eof3;
161
162
  case 3:
162
- #line 163 "parser.c"
163
+ #line 164 "parser.c"
163
164
  switch( (*p) ) {
164
165
  case 13: goto st3;
165
166
  case 32: goto st3;
@@ -226,7 +227,7 @@ case 8:
226
227
  goto st8;
227
228
  goto st0;
228
229
  tr11:
229
- #line 117 "parser.rl"
230
+ #line 118 "parser.rl"
230
231
  {
231
232
  VALUE v = Qnil;
232
233
  char *np = JSON_parse_value(json, p, pe, &v);
@@ -246,7 +247,7 @@ st9:
246
247
  if ( ++p == pe )
247
248
  goto _test_eof9;
248
249
  case 9:
249
- #line 250 "parser.c"
250
+ #line 251 "parser.c"
250
251
  switch( (*p) ) {
251
252
  case 13: goto st9;
252
253
  case 32: goto st9;
@@ -335,14 +336,14 @@ case 18:
335
336
  goto st9;
336
337
  goto st18;
337
338
  tr4:
338
- #line 140 "parser.rl"
339
+ #line 141 "parser.rl"
339
340
  { p--; {p++; cs = 27; goto _out;} }
340
341
  goto st27;
341
342
  st27:
342
343
  if ( ++p == pe )
343
344
  goto _test_eof27;
344
345
  case 27:
345
- #line 346 "parser.c"
346
+ #line 347 "parser.c"
346
347
  goto st0;
347
348
  st19:
348
349
  if ( ++p == pe )
@@ -440,7 +441,7 @@ case 26:
440
441
  _out: {}
441
442
  }
442
443
 
443
- #line 166 "parser.rl"
444
+ #line 167 "parser.rl"
444
445
 
445
446
  if (cs >= JSON_object_first_final) {
446
447
  if (json->create_additions) {
@@ -460,7 +461,7 @@ case 26:
460
461
 
461
462
 
462
463
 
463
- #line 464 "parser.c"
464
+ #line 465 "parser.c"
464
465
  static const int JSON_value_start = 1;
465
466
  static const int JSON_value_first_final = 21;
466
467
  static const int JSON_value_error = 0;
@@ -468,7 +469,7 @@ static const int JSON_value_error = 0;
468
469
  static const int JSON_value_en_main = 1;
469
470
 
470
471
 
471
- #line 265 "parser.rl"
472
+ #line 266 "parser.rl"
472
473
 
473
474
 
474
475
  static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -476,14 +477,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
476
477
  int cs = EVIL;
477
478
 
478
479
 
479
- #line 480 "parser.c"
480
+ #line 481 "parser.c"
480
481
  {
481
482
  cs = JSON_value_start;
482
483
  }
483
484
 
484
- #line 272 "parser.rl"
485
+ #line 273 "parser.rl"
485
486
 
486
- #line 487 "parser.c"
487
+ #line 488 "parser.c"
487
488
  {
488
489
  if ( p == pe )
489
490
  goto _test_eof;
@@ -508,14 +509,14 @@ st0:
508
509
  cs = 0;
509
510
  goto _out;
510
511
  tr0:
511
- #line 213 "parser.rl"
512
+ #line 214 "parser.rl"
512
513
  {
513
514
  char *np = JSON_parse_string(json, p, pe, result);
514
515
  if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
515
516
  }
516
517
  goto st21;
517
518
  tr2:
518
- #line 218 "parser.rl"
519
+ #line 219 "parser.rl"
519
520
  {
520
521
  char *np;
521
522
  if(pe > p + 9 - json->quirks_mode && !strncmp(MinusInfinity, p, 9)) {
@@ -535,7 +536,7 @@ tr2:
535
536
  }
536
537
  goto st21;
537
538
  tr5:
538
- #line 236 "parser.rl"
539
+ #line 237 "parser.rl"
539
540
  {
540
541
  char *np;
541
542
  json->current_nesting++;
@@ -545,7 +546,7 @@ tr5:
545
546
  }
546
547
  goto st21;
547
548
  tr9:
548
- #line 244 "parser.rl"
549
+ #line 245 "parser.rl"
549
550
  {
550
551
  char *np;
551
552
  json->current_nesting++;
@@ -555,7 +556,7 @@ tr9:
555
556
  }
556
557
  goto st21;
557
558
  tr16:
558
- #line 206 "parser.rl"
559
+ #line 207 "parser.rl"
559
560
  {
560
561
  if (json->allow_nan) {
561
562
  *result = CInfinity;
@@ -565,7 +566,7 @@ tr16:
565
566
  }
566
567
  goto st21;
567
568
  tr18:
568
- #line 199 "parser.rl"
569
+ #line 200 "parser.rl"
569
570
  {
570
571
  if (json->allow_nan) {
571
572
  *result = CNaN;
@@ -575,19 +576,19 @@ tr18:
575
576
  }
576
577
  goto st21;
577
578
  tr22:
578
- #line 193 "parser.rl"
579
+ #line 194 "parser.rl"
579
580
  {
580
581
  *result = Qfalse;
581
582
  }
582
583
  goto st21;
583
584
  tr25:
584
- #line 190 "parser.rl"
585
+ #line 191 "parser.rl"
585
586
  {
586
587
  *result = Qnil;
587
588
  }
588
589
  goto st21;
589
590
  tr28:
590
- #line 196 "parser.rl"
591
+ #line 197 "parser.rl"
591
592
  {
592
593
  *result = Qtrue;
593
594
  }
@@ -596,9 +597,9 @@ st21:
596
597
  if ( ++p == pe )
597
598
  goto _test_eof21;
598
599
  case 21:
599
- #line 252 "parser.rl"
600
+ #line 253 "parser.rl"
600
601
  { p--; {p++; cs = 21; goto _out;} }
601
- #line 602 "parser.c"
602
+ #line 603 "parser.c"
602
603
  goto st0;
603
604
  st2:
604
605
  if ( ++p == pe )
@@ -759,7 +760,7 @@ case 20:
759
760
  _out: {}
760
761
  }
761
762
 
762
- #line 273 "parser.rl"
763
+ #line 274 "parser.rl"
763
764
 
764
765
  if (cs >= JSON_value_first_final) {
765
766
  return p;
@@ -769,7 +770,7 @@ case 20:
769
770
  }
770
771
 
771
772
 
772
- #line 773 "parser.c"
773
+ #line 774 "parser.c"
773
774
  static const int JSON_integer_start = 1;
774
775
  static const int JSON_integer_first_final = 3;
775
776
  static const int JSON_integer_error = 0;
@@ -777,7 +778,7 @@ static const int JSON_integer_error = 0;
777
778
  static const int JSON_integer_en_main = 1;
778
779
 
779
780
 
780
- #line 289 "parser.rl"
781
+ #line 290 "parser.rl"
781
782
 
782
783
 
783
784
  static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -785,15 +786,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
785
786
  int cs = EVIL;
786
787
 
787
788
 
788
- #line 789 "parser.c"
789
+ #line 790 "parser.c"
789
790
  {
790
791
  cs = JSON_integer_start;
791
792
  }
792
793
 
793
- #line 296 "parser.rl"
794
+ #line 297 "parser.rl"
794
795
  json->memo = p;
795
796
 
796
- #line 797 "parser.c"
797
+ #line 798 "parser.c"
797
798
  {
798
799
  if ( p == pe )
799
800
  goto _test_eof;
@@ -827,14 +828,14 @@ case 3:
827
828
  goto st0;
828
829
  goto tr4;
829
830
  tr4:
830
- #line 286 "parser.rl"
831
+ #line 287 "parser.rl"
831
832
  { p--; {p++; cs = 4; goto _out;} }
832
833
  goto st4;
833
834
  st4:
834
835
  if ( ++p == pe )
835
836
  goto _test_eof4;
836
837
  case 4:
837
- #line 838 "parser.c"
838
+ #line 839 "parser.c"
838
839
  goto st0;
839
840
  st5:
840
841
  if ( ++p == pe )
@@ -853,11 +854,14 @@ case 5:
853
854
  _out: {}
854
855
  }
855
856
 
856
- #line 298 "parser.rl"
857
+ #line 299 "parser.rl"
857
858
 
858
859
  if (cs >= JSON_integer_first_final) {
859
860
  long len = p - json->memo;
860
- *result = rb_Integer(rb_str_new(json->memo, len));
861
+ fbuffer_clear(json->fbuffer);
862
+ fbuffer_append(json->fbuffer, json->memo, len);
863
+ fbuffer_append_char(json->fbuffer, '\0');
864
+ *result = rb_cstr2inum(FBUFFER_PTR(json->fbuffer), 10);
861
865
  return p + 1;
862
866
  } else {
863
867
  return NULL;
@@ -865,7 +869,7 @@ case 5:
865
869
  }
866
870
 
867
871
 
868
- #line 869 "parser.c"
872
+ #line 873 "parser.c"
869
873
  static const int JSON_float_start = 1;
870
874
  static const int JSON_float_first_final = 8;
871
875
  static const int JSON_float_error = 0;
@@ -873,7 +877,7 @@ static const int JSON_float_error = 0;
873
877
  static const int JSON_float_en_main = 1;
874
878
 
875
879
 
876
- #line 320 "parser.rl"
880
+ #line 324 "parser.rl"
877
881
 
878
882
 
879
883
  static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -881,15 +885,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
881
885
  int cs = EVIL;
882
886
 
883
887
 
884
- #line 885 "parser.c"
888
+ #line 889 "parser.c"
885
889
  {
886
890
  cs = JSON_float_start;
887
891
  }
888
892
 
889
- #line 327 "parser.rl"
893
+ #line 331 "parser.rl"
890
894
  json->memo = p;
891
895
 
892
- #line 893 "parser.c"
896
+ #line 897 "parser.c"
893
897
  {
894
898
  if ( p == pe )
895
899
  goto _test_eof;
@@ -947,14 +951,14 @@ case 8:
947
951
  goto st0;
948
952
  goto tr9;
949
953
  tr9:
950
- #line 314 "parser.rl"
954
+ #line 318 "parser.rl"
951
955
  { p--; {p++; cs = 9; goto _out;} }
952
956
  goto st9;
953
957
  st9:
954
958
  if ( ++p == pe )
955
959
  goto _test_eof9;
956
960
  case 9:
957
- #line 958 "parser.c"
961
+ #line 962 "parser.c"
958
962
  goto st0;
959
963
  st5:
960
964
  if ( ++p == pe )
@@ -1015,11 +1019,14 @@ case 7:
1015
1019
  _out: {}
1016
1020
  }
1017
1021
 
1018
- #line 329 "parser.rl"
1022
+ #line 333 "parser.rl"
1019
1023
 
1020
1024
  if (cs >= JSON_float_first_final) {
1021
1025
  long len = p - json->memo;
1022
- *result = rb_Float(rb_str_new(json->memo, len));
1026
+ fbuffer_clear(json->fbuffer);
1027
+ fbuffer_append(json->fbuffer, json->memo, len);
1028
+ fbuffer_append_char(json->fbuffer, '\0');
1029
+ *result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
1023
1030
  return p + 1;
1024
1031
  } else {
1025
1032
  return NULL;
@@ -1028,7 +1035,7 @@ case 7:
1028
1035
 
1029
1036
 
1030
1037
 
1031
- #line 1032 "parser.c"
1038
+ #line 1039 "parser.c"
1032
1039
  static const int JSON_array_start = 1;
1033
1040
  static const int JSON_array_first_final = 17;
1034
1041
  static const int JSON_array_error = 0;
@@ -1036,7 +1043,7 @@ static const int JSON_array_error = 0;
1036
1043
  static const int JSON_array_en_main = 1;
1037
1044
 
1038
1045
 
1039
- #line 369 "parser.rl"
1046
+ #line 376 "parser.rl"
1040
1047
 
1041
1048
 
1042
1049
  static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -1050,14 +1057,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
1050
1057
  *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
1051
1058
 
1052
1059
 
1053
- #line 1054 "parser.c"
1060
+ #line 1061 "parser.c"
1054
1061
  {
1055
1062
  cs = JSON_array_start;
1056
1063
  }
1057
1064
 
1058
- #line 382 "parser.rl"
1065
+ #line 389 "parser.rl"
1059
1066
 
1060
- #line 1061 "parser.c"
1067
+ #line 1068 "parser.c"
1061
1068
  {
1062
1069
  if ( p == pe )
1063
1070
  goto _test_eof;
@@ -1096,7 +1103,7 @@ case 2:
1096
1103
  goto st2;
1097
1104
  goto st0;
1098
1105
  tr2:
1099
- #line 346 "parser.rl"
1106
+ #line 353 "parser.rl"
1100
1107
  {
1101
1108
  VALUE v = Qnil;
1102
1109
  char *np = JSON_parse_value(json, p, pe, &v);
@@ -1116,7 +1123,7 @@ st3:
1116
1123
  if ( ++p == pe )
1117
1124
  goto _test_eof3;
1118
1125
  case 3:
1119
- #line 1120 "parser.c"
1126
+ #line 1127 "parser.c"
1120
1127
  switch( (*p) ) {
1121
1128
  case 13: goto st3;
1122
1129
  case 32: goto st3;
@@ -1216,14 +1223,14 @@ case 12:
1216
1223
  goto st3;
1217
1224
  goto st12;
1218
1225
  tr4:
1219
- #line 361 "parser.rl"
1226
+ #line 368 "parser.rl"
1220
1227
  { p--; {p++; cs = 17; goto _out;} }
1221
1228
  goto st17;
1222
1229
  st17:
1223
1230
  if ( ++p == pe )
1224
1231
  goto _test_eof17;
1225
1232
  case 17:
1226
- #line 1227 "parser.c"
1233
+ #line 1234 "parser.c"
1227
1234
  goto st0;
1228
1235
  st13:
1229
1236
  if ( ++p == pe )
@@ -1279,7 +1286,7 @@ case 16:
1279
1286
  _out: {}
1280
1287
  }
1281
1288
 
1282
- #line 383 "parser.rl"
1289
+ #line 390 "parser.rl"
1283
1290
 
1284
1291
  if(cs >= JSON_array_first_final) {
1285
1292
  return p + 1;
@@ -1360,7 +1367,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
1360
1367
  }
1361
1368
 
1362
1369
 
1363
- #line 1364 "parser.c"
1370
+ #line 1371 "parser.c"
1364
1371
  static const int JSON_string_start = 1;
1365
1372
  static const int JSON_string_first_final = 8;
1366
1373
  static const int JSON_string_error = 0;
@@ -1368,7 +1375,7 @@ static const int JSON_string_error = 0;
1368
1375
  static const int JSON_string_en_main = 1;
1369
1376
 
1370
1377
 
1371
- #line 482 "parser.rl"
1378
+ #line 489 "parser.rl"
1372
1379
 
1373
1380
 
1374
1381
  static int
@@ -1390,15 +1397,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
1390
1397
 
1391
1398
  *result = rb_str_buf_new(0);
1392
1399
 
1393
- #line 1394 "parser.c"
1400
+ #line 1401 "parser.c"
1394
1401
  {
1395
1402
  cs = JSON_string_start;
1396
1403
  }
1397
1404
 
1398
- #line 503 "parser.rl"
1405
+ #line 510 "parser.rl"
1399
1406
  json->memo = p;
1400
1407
 
1401
- #line 1402 "parser.c"
1408
+ #line 1409 "parser.c"
1402
1409
  {
1403
1410
  if ( p == pe )
1404
1411
  goto _test_eof;
@@ -1423,7 +1430,7 @@ case 2:
1423
1430
  goto st0;
1424
1431
  goto st2;
1425
1432
  tr2:
1426
- #line 468 "parser.rl"
1433
+ #line 475 "parser.rl"
1427
1434
  {
1428
1435
  *result = json_string_unescape(*result, json->memo + 1, p);
1429
1436
  if (NIL_P(*result)) {
@@ -1434,14 +1441,14 @@ tr2:
1434
1441
  {p = (( p + 1))-1;}
1435
1442
  }
1436
1443
  }
1437
- #line 479 "parser.rl"
1444
+ #line 486 "parser.rl"
1438
1445
  { p--; {p++; cs = 8; goto _out;} }
1439
1446
  goto st8;
1440
1447
  st8:
1441
1448
  if ( ++p == pe )
1442
1449
  goto _test_eof8;
1443
1450
  case 8:
1444
- #line 1445 "parser.c"
1451
+ #line 1452 "parser.c"
1445
1452
  goto st0;
1446
1453
  st3:
1447
1454
  if ( ++p == pe )
@@ -1517,7 +1524,7 @@ case 7:
1517
1524
  _out: {}
1518
1525
  }
1519
1526
 
1520
- #line 505 "parser.rl"
1527
+ #line 512 "parser.rl"
1521
1528
 
1522
1529
  if (json->create_additions && RTEST(match_string = json->match_string)) {
1523
1530
  VALUE klass;
@@ -1618,9 +1625,6 @@ static VALUE convert_encoding(VALUE source)
1618
1625
  * defaults to true.
1619
1626
  * * *object_class*: Defaults to Hash
1620
1627
  * * *array_class*: Defaults to Array
1621
- * * *quirks_mode*: Enables quirks_mode for parser, that is for example
1622
- * parsing single JSON values instead of documents is possible.
1623
- *
1624
1628
  */
1625
1629
  static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1626
1630
  {
@@ -1707,6 +1711,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1707
1711
  json->object_class = Qnil;
1708
1712
  json->array_class = Qnil;
1709
1713
  }
1714
+ source = rb_convert_type(source, T_STRING, "String", "to_str");
1710
1715
  if (!json->quirks_mode) {
1711
1716
  source = convert_encoding(StringValue(source));
1712
1717
  }
@@ -1718,7 +1723,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1718
1723
  }
1719
1724
 
1720
1725
 
1721
- #line 1719 "parser.c"
1726
+ #line 1727 "parser.c"
1722
1727
  static const int JSON_start = 1;
1723
1728
  static const int JSON_first_final = 10;
1724
1729
  static const int JSON_error = 0;
@@ -1726,7 +1731,7 @@ static const int JSON_error = 0;
1726
1731
  static const int JSON_en_main = 1;
1727
1732
 
1728
1733
 
1729
- #line 726 "parser.rl"
1734
+ #line 734 "parser.rl"
1730
1735
 
1731
1736
 
1732
1737
  static VALUE cParser_parse_strict(VALUE self)
@@ -1737,16 +1742,16 @@ static VALUE cParser_parse_strict(VALUE self)
1737
1742
  GET_PARSER;
1738
1743
 
1739
1744
 
1740
- #line 1738 "parser.c"
1745
+ #line 1746 "parser.c"
1741
1746
  {
1742
1747
  cs = JSON_start;
1743
1748
  }
1744
1749
 
1745
- #line 736 "parser.rl"
1750
+ #line 744 "parser.rl"
1746
1751
  p = json->source;
1747
1752
  pe = p + json->len;
1748
1753
 
1749
- #line 1747 "parser.c"
1754
+ #line 1755 "parser.c"
1750
1755
  {
1751
1756
  if ( p == pe )
1752
1757
  goto _test_eof;
@@ -1802,7 +1807,7 @@ case 5:
1802
1807
  goto st1;
1803
1808
  goto st5;
1804
1809
  tr3:
1805
- #line 715 "parser.rl"
1810
+ #line 723 "parser.rl"
1806
1811
  {
1807
1812
  char *np;
1808
1813
  json->current_nesting = 1;
@@ -1811,7 +1816,7 @@ tr3:
1811
1816
  }
1812
1817
  goto st10;
1813
1818
  tr4:
1814
- #line 708 "parser.rl"
1819
+ #line 716 "parser.rl"
1815
1820
  {
1816
1821
  char *np;
1817
1822
  json->current_nesting = 1;
@@ -1823,7 +1828,7 @@ st10:
1823
1828
  if ( ++p == pe )
1824
1829
  goto _test_eof10;
1825
1830
  case 10:
1826
- #line 1824 "parser.c"
1831
+ #line 1832 "parser.c"
1827
1832
  switch( (*p) ) {
1828
1833
  case 13: goto st10;
1829
1834
  case 32: goto st10;
@@ -1880,7 +1885,7 @@ case 9:
1880
1885
  _out: {}
1881
1886
  }
1882
1887
 
1883
- #line 739 "parser.rl"
1888
+ #line 747 "parser.rl"
1884
1889
 
1885
1890
  if (cs >= JSON_first_final && p == pe) {
1886
1891
  return result;
@@ -1892,7 +1897,7 @@ case 9:
1892
1897
 
1893
1898
 
1894
1899
 
1895
- #line 1893 "parser.c"
1900
+ #line 1901 "parser.c"
1896
1901
  static const int JSON_quirks_mode_start = 1;
1897
1902
  static const int JSON_quirks_mode_first_final = 10;
1898
1903
  static const int JSON_quirks_mode_error = 0;
@@ -1900,7 +1905,7 @@ static const int JSON_quirks_mode_error = 0;
1900
1905
  static const int JSON_quirks_mode_en_main = 1;
1901
1906
 
1902
1907
 
1903
- #line 764 "parser.rl"
1908
+ #line 772 "parser.rl"
1904
1909
 
1905
1910
 
1906
1911
  static VALUE cParser_parse_quirks_mode(VALUE self)
@@ -1911,16 +1916,16 @@ static VALUE cParser_parse_quirks_mode(VALUE self)
1911
1916
  GET_PARSER;
1912
1917
 
1913
1918
 
1914
- #line 1912 "parser.c"
1919
+ #line 1920 "parser.c"
1915
1920
  {
1916
1921
  cs = JSON_quirks_mode_start;
1917
1922
  }
1918
1923
 
1919
- #line 774 "parser.rl"
1924
+ #line 782 "parser.rl"
1920
1925
  p = json->source;
1921
1926
  pe = p + json->len;
1922
1927
 
1923
- #line 1921 "parser.c"
1928
+ #line 1929 "parser.c"
1924
1929
  {
1925
1930
  if ( p == pe )
1926
1931
  goto _test_eof;
@@ -1954,7 +1959,7 @@ st0:
1954
1959
  cs = 0;
1955
1960
  goto _out;
1956
1961
  tr2:
1957
- #line 756 "parser.rl"
1962
+ #line 764 "parser.rl"
1958
1963
  {
1959
1964
  char *np = JSON_parse_value(json, p, pe, &result);
1960
1965
  if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -1964,7 +1969,7 @@ st10:
1964
1969
  if ( ++p == pe )
1965
1970
  goto _test_eof10;
1966
1971
  case 10:
1967
- #line 1965 "parser.c"
1972
+ #line 1973 "parser.c"
1968
1973
  switch( (*p) ) {
1969
1974
  case 13: goto st10;
1970
1975
  case 32: goto st10;
@@ -2053,7 +2058,7 @@ case 9:
2053
2058
  _out: {}
2054
2059
  }
2055
2060
 
2056
- #line 777 "parser.rl"
2061
+ #line 785 "parser.rl"
2057
2062
 
2058
2063
  if (cs >= JSON_quirks_mode_first_final && p == pe) {
2059
2064
  return result;
@@ -2085,6 +2090,7 @@ static JSON_Parser *JSON_allocate()
2085
2090
  {
2086
2091
  JSON_Parser *json = ALLOC(JSON_Parser);
2087
2092
  MEMZERO(json, JSON_Parser, 1);
2093
+ json->fbuffer = fbuffer_alloc(0);
2088
2094
  return json;
2089
2095
  }
2090
2096
 
@@ -2099,6 +2105,7 @@ static void JSON_mark(JSON_Parser *json)
2099
2105
 
2100
2106
  static void JSON_free(JSON_Parser *json)
2101
2107
  {
2108
+ fbuffer_free(json->fbuffer);
2102
2109
  ruby_xfree(json);
2103
2110
  }
2104
2111