json_pure 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ 2009-05-10 (1.1.5)
2
+ * Started to build gems with rake-compiler gem.
3
+ * Applied patch object/array class patch from Brian Candler
4
+ <B.Candler@pobox.com> and fixes.
1
5
  2009-04-01 (1.1.4)
2
6
  * Fixed a bug in the creation of serialized generic rails objects reported by
3
7
  Friedrich Graeter <graeter@hydrixos.org>.
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  begin
2
2
  require 'rake/gempackagetask'
3
+ require 'rake/extensiontask'
3
4
  rescue LoadError
4
5
  end
5
6
  require 'rake/clean'
@@ -7,10 +8,9 @@ require 'rake/clean'
7
8
  require 'rbconfig'
8
9
  include Config
9
10
 
10
- ON_WINDOWS = RUBY_PLATFORM =~ /mswin32/i
11
11
  PKG_NAME = 'json'
12
12
  PKG_VERSION = File.read('VERSION').chomp
13
- PKG_FILES = FileList["**/*"].exclude(/CVS|pkg|coverage|Makefile/).exclude(/\.(so|bundle|o|#{CONFIG['DLEXT']})$/)
13
+ PKG_FILES = FileList["**/*"].exclude(/CVS|pkg|tmp|coverage|Makefile/).exclude(/\.(so|bundle|o|#{CONFIG['DLEXT']})$/)
14
14
  EXT_ROOT_DIR = 'ext/json/ext'
15
15
  EXT_PARSER_DIR = "#{EXT_ROOT_DIR}/parser"
16
16
  EXT_PARSER_DL = "#{EXT_ROOT_DIR}/parser.#{CONFIG['DLEXT']}"
@@ -22,10 +22,9 @@ EXT_GENERATOR_SRC = "#{EXT_GENERATOR_DIR}/generator.c"
22
22
  RAGEL_CODEGEN = %w[rlcodegen rlgen-cd ragel].find { |c| system(c, '-v') }
23
23
  RAGEL_DOTGEN = %w[rlgen-dot rlgen-cd ragel].find { |c| system(c, '-v') }
24
24
  RAGEL_PATH = "#{EXT_PARSER_DIR}/parser.rl"
25
- CLEAN.include 'doc', 'coverage', FileList['diagrams/*.*'],
26
- FileList["ext/**/*.{so,bundle,#{CONFIG['DLEXT']},o,obj,pdb,lib,manifest,exp,def}"],
27
- FileList["ext/**/{Makefile,mkmf.log}"]
28
-
25
+ CLEAN.include FileList['diagrams/*.*'], 'doc', 'coverage', 'tmp',
26
+ FileList["ext/**/{Makefile,mkmf.log}"],
27
+ FileList["{ext,lib}/**/*.{so,bundle,#{CONFIG['DLEXT']},o,obj,pdb,lib,manifest,exp,def}"]
29
28
 
30
29
  desc "Installing library (pure)"
31
30
  task :install_pure => :version do
@@ -44,22 +43,18 @@ task :install_ext_really do
44
43
  end
45
44
 
46
45
  desc "Installing library (extension)"
47
- task :install_ext => [ :compile, :install_pure, :install_ext_really ]
46
+ task :install_ext => [ :compile_ext, :install_pure, :install_ext_really ]
48
47
 
48
+ desc "Installing library (extension)"
49
49
  task :install => :install_ext
50
50
 
51
51
  desc "Compiling extension"
52
- task :compile => [ EXT_PARSER_DL, EXT_GENERATOR_DL ]
52
+ task :compile_ext => [ EXT_PARSER_DL, EXT_GENERATOR_DL ]
53
53
 
54
54
  file EXT_PARSER_DL => EXT_PARSER_SRC do
55
55
  cd EXT_PARSER_DIR do
56
56
  ruby 'extconf.rb'
57
- if ON_WINDOWS
58
- system 'nmake'
59
- system "mt -manifest parser.#{CONFIG['DLEXT']}.manifest -outputresource:parser.#{CONFIG['DLEXT']};2"
60
- else
61
- system 'make'
62
- end
57
+ system 'make'
63
58
  end
64
59
  cp "#{EXT_PARSER_DIR}/parser.#{CONFIG['DLEXT']}", EXT_ROOT_DIR
65
60
  end
@@ -67,12 +62,7 @@ end
67
62
  file EXT_GENERATOR_DL => EXT_GENERATOR_SRC do
68
63
  cd EXT_GENERATOR_DIR do
69
64
  ruby 'extconf.rb'
70
- if ON_WINDOWS
71
- system 'nmake'
72
- system "mt -manifest generator.#{CONFIG['DLEXT']}.manifest -outputresource:generator.#{CONFIG['DLEXT']};2"
73
- else
74
- system 'make'
75
- end
65
+ system 'make'
76
66
  end
77
67
  cp "#{EXT_GENERATOR_DIR}/generator.#{CONFIG['DLEXT']}", EXT_ROOT_DIR
78
68
  end
@@ -133,12 +123,15 @@ task :test_pure => :clean do
133
123
  end
134
124
 
135
125
  desc "Testing library (extension)"
136
- task :test_ext => :compile do
126
+ task :test_ext => :compile_ext do
137
127
  ENV['JSON'] = 'ext'
138
128
  ENV['RUBYOPT'] = "-Iext:lib #{ENV['RUBYOPT']}"
139
129
  system "testrb #{Dir['tests/*.rb'] * ' '}"
140
130
  end
141
131
 
132
+ desc "Testing library (pure ruby and extension)"
133
+ task :test => [ :test_pure, :test_ext ]
134
+
142
135
  desc "Benchmarking parser"
143
136
  task :benchmark_parser do
144
137
  ruby 'benchmarks/parser_benchmark.rb'
@@ -162,7 +155,7 @@ task :doc => [ :version, EXT_PARSER_SRC ] do
162
155
  system "rdoc -S -o doc -m main.txt doc-templates/main.txt lib/json.rb #{FileList['lib/json/**/*.rb']} #{EXT_PARSER_SRC} #{EXT_GENERATOR_SRC}"
163
156
  end
164
157
 
165
- if defined? Gem
158
+ if defined?(Gem) and defined?(Rake::GemPackageTask) and defined?(Rake::ExtensionTask)
166
159
  spec_pure = Gem::Specification.new do |s|
167
160
  s.name = 'json_pure'
168
161
  s.version = PKG_VERSION
@@ -174,7 +167,7 @@ if defined? Gem
174
167
  s.require_path = 'lib'
175
168
 
176
169
  s.bindir = "bin"
177
- s.executables = ["edit_json.rb"]
170
+ s.executables = [ "edit_json.rb", "prettify_json.rb" ]
178
171
  s.default_executable = "edit_json.rb"
179
172
 
180
173
  s.has_rdoc = true
@@ -202,16 +195,14 @@ if defined? Gem
202
195
 
203
196
  s.files = PKG_FILES
204
197
 
205
- s.extensions <<
206
- "#{EXT_PARSER_DIR}/extconf.rb" <<
207
- "#{EXT_GENERATOR_DIR}/extconf.rb"
198
+ s.extensions = FileList['ext/**/extconf.rb']
208
199
 
209
200
  s.require_path = EXT_ROOT_DIR
210
201
  s.require_paths << 'ext'
211
202
  s.require_paths << 'lib'
212
203
 
213
204
  s.bindir = "bin"
214
- s.executables = ["edit_json.rb"]
205
+ s.executables = [ "edit_json.rb", "prettify_json.rb" ]
215
206
  s.default_executable = "edit_json.rb"
216
207
 
217
208
  s.has_rdoc = true
@@ -227,52 +218,26 @@ if defined? Gem
227
218
  end
228
219
 
229
220
  Rake::GemPackageTask.new(spec_ext) do |pkg|
230
- pkg.need_tar = true
231
- pkg.package_files += PKG_FILES
221
+ pkg.need_tar = true
222
+ pkg.package_files = PKG_FILES
232
223
  end
233
224
 
234
- task :package_win => :compile do
235
- mkdir_p 'pkg'
236
- spec_win_ext = Gem::Specification.new do |s|
237
- s.name = 'json'
238
- s.platform = Gem::Platform::WIN32
239
- s.version = PKG_VERSION
240
- s.summary = "A JSON implementation as a Ruby extension"
241
- s.description = ""
242
-
243
- s.files = PKG_FILES.to_a <<
244
- "#{EXT_ROOT_DIR}/parser.#{CONFIG['DLEXT']}" <<
245
- "#{EXT_ROOT_DIR}/generator.#{CONFIG['DLEXT']}"
246
-
247
- s.require_path = EXT_ROOT_DIR
248
- s.require_paths << 'ext'
249
- s.require_paths << 'lib'
250
-
251
- s.bindir = "bin"
252
- s.executables = ["edit_json.rb", "prettify_json.rb"]
253
- s.default_executable = "edit_json.rb"
254
-
255
- s.has_rdoc = true
256
- s.rdoc_options <<
257
- '--title' << 'JSON -- A JSON implemention' <<
258
- '--main' << 'JSON' << '--line-numbers'
259
- s.test_files.concat Dir['tests/*.rb']
260
-
261
- s.author = "Florian Frank"
262
- s.email = "flori@ping.de"
263
- s.homepage = "http://json.rubyforge.org"
264
- s.rubyforge_project = "json"
265
- end
266
-
267
- gem_file = "json-#{spec_win_ext.version}-#{spec_win_ext.platform}.gem"
268
- Gem::Builder.new(spec_win_ext).build
269
- mv gem_file, 'pkg'
225
+ Rake::ExtensionTask.new do |ext|
226
+ ext.name = 'parser'
227
+ ext.gem_spec = spec_ext
228
+ ext.cross_compile = true
229
+ ext.cross_platform = 'i386-mswin32'
230
+ ext.ext_dir = 'ext/json/ext/parser'
231
+ ext.lib_dir = 'lib/json/ext'
270
232
  end
271
- end
272
-
273
- task :mrproper => [ :ragel_clean, :clean, :clean_benchmark_data ] do
274
- for dir in [ EXT_PARSER_DIR, EXT_GENERATOR_DIR ]
275
- cd(dir) { rm_f %w[Makefile mkmf.log] }
233
+
234
+ Rake::ExtensionTask.new do |ext|
235
+ ext.name = 'generator'
236
+ ext.gem_spec = spec_ext
237
+ ext.cross_compile = true
238
+ ext.cross_platform = 'i386-mswin32'
239
+ ext.ext_dir = 'ext/json/ext/generator'
240
+ ext.lib_dir = 'lib/json/ext'
276
241
  end
277
242
  end
278
243
 
@@ -288,16 +253,16 @@ module JSON
288
253
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
289
254
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
290
255
  VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
291
- VARIANT_BINARY = #{!!ON_WINDOWS}
292
256
  end
293
257
  EOT
294
258
  end
295
259
  end
296
260
 
297
- if ON_WINDOWS
298
- task :release => [ :version, :clean, :package_win ]
299
- else
300
- task :release => [ :version, :mrproper, :package ]
261
+ # TODO task :release => [ :version, :clean, :package_win ]
262
+ desc "Build all gems and archives for a new release."
263
+ task :release => [ :clean, :version, :cross, :native, :gem ] do
264
+ system "#$0 clean native gem"
265
+ system "#$0 clean package"
301
266
  end
302
267
 
303
- task :default => [ :version, :compile ]
268
+ task :default => [ :version, :compile_ext ]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.4
1
+ 1.1.5
@@ -63,6 +63,7 @@ class GeneratorBenchmarkExt < Bullshit::RepeatCase
63
63
  truncate_data do
64
64
  alpha_level 0.05
65
65
  window_size 50
66
+ slope_angle 0.1
66
67
  end
67
68
 
68
69
  autocorrelation do
@@ -87,6 +88,7 @@ class GeneratorBenchmarkPure < Bullshit::RepeatCase
87
88
  truncate_data do
88
89
  alpha_level 0.05
89
90
  window_size 50
91
+ slope_angle 0.1
90
92
  end
91
93
 
92
94
  autocorrelation do
@@ -110,6 +112,7 @@ class GeneratorBenchmarkRails < Bullshit::RepeatCase
110
112
  truncate_data do
111
113
  alpha_level 0.05
112
114
  window_size 50
115
+ slope_angle 0.1
113
116
  end
114
117
 
115
118
  autocorrelation do
@@ -43,6 +43,7 @@ class ParserBenchmarkExt < Bullshit::RepeatCase
43
43
  truncate_data do
44
44
  alpha_level 0.05
45
45
  window_size 50
46
+ slope_angle 0.1
46
47
  end
47
48
 
48
49
  autocorrelation do
@@ -72,6 +73,7 @@ class ParserBenchmarkPure < Bullshit::RepeatCase
72
73
  truncate_data do
73
74
  alpha_level 0.05
74
75
  window_size 50
76
+ slope_angle 0.1
75
77
  end
76
78
 
77
79
  autocorrelation do
@@ -99,6 +101,7 @@ class ParserBenchmarkYAML < Bullshit::RepeatCase
99
101
  truncate_data do
100
102
  alpha_level 0.05
101
103
  window_size 50
104
+ slope_angle 0.1
102
105
  end
103
106
 
104
107
  autocorrelation do
@@ -134,6 +137,7 @@ class ParserBenchmarkRails < Bullshit::RepeatCase
134
137
  truncate_data do
135
138
  alpha_level 0.05
136
139
  window_size 50
140
+ slope_angle 0.1
137
141
  end
138
142
 
139
143
  autocorrelation do
@@ -76,8 +76,7 @@
76
76
  #
77
77
  # == Speed Comparisons
78
78
  #
79
- # I have created some benchmark results on on ruby 1.8.6 (2008-08-11
80
- # patchlevel 287) [i686-linux] (see the benchmarks/data-p4-3Ghz-ruby18
79
+ # I have created some benchmark results (see the benchmarks/data-p4-3Ghz
81
80
  # subdir of the package) for the JSON-parser to estimate the speed up in the C
82
81
  # extension:
83
82
  #
@@ -29,7 +29,7 @@ static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
29
29
  static VALUE CNaN, CInfinity, CMinusInfinity;
30
30
 
31
31
  static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
32
- i_chr, i_max_nesting, i_allow_nan;
32
+ i_chr, i_max_nesting, i_allow_nan, i_object_class, i_array_class;
33
33
 
34
34
  #define MinusInfinity "-Infinity"
35
35
 
@@ -42,6 +42,8 @@ typedef struct JSON_ParserStruct {
42
42
  int max_nesting;
43
43
  int current_nesting;
44
44
  int allow_nan;
45
+ VALUE object_class;
46
+ VALUE array_class;
45
47
  } JSON_Parser;
46
48
 
47
49
  static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result);
@@ -56,11 +58,11 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
56
58
  Data_Get_Struct(self, JSON_Parser, json);
57
59
 
58
60
 
59
- #line 82 "parser.rl"
61
+ #line 84 "parser.rl"
60
62
 
61
63
 
62
64
 
63
- #line 64 "parser.c"
65
+ #line 66 "parser.c"
64
66
  static const int JSON_object_start = 1;
65
67
  static const int JSON_object_first_final = 27;
66
68
  static const int JSON_object_error = 0;
@@ -68,29 +70,30 @@ static const int JSON_object_error = 0;
68
70
  static const int JSON_object_en_main = 1;
69
71
 
70
72
 
71
- #line 115 "parser.rl"
73
+ #line 117 "parser.rl"
72
74
 
73
75
 
74
76
  static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
75
77
  {
76
78
  int cs = EVIL;
77
79
  VALUE last_name = Qnil;
80
+ VALUE object_class = json->object_class;
78
81
 
79
82
  if (json->max_nesting && json->current_nesting > json->max_nesting) {
80
83
  rb_raise(eNestingError, "nesting of %d is to deep", json->current_nesting);
81
84
  }
82
85
 
83
- *result = rb_hash_new();
86
+ *result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
84
87
 
85
88
 
86
- #line 87 "parser.c"
89
+ #line 90 "parser.c"
87
90
  {
88
91
  cs = JSON_object_start;
89
92
  }
90
93
 
91
- #line 129 "parser.rl"
94
+ #line 132 "parser.rl"
92
95
 
93
- #line 94 "parser.c"
96
+ #line 97 "parser.c"
94
97
  {
95
98
  if ( p == pe )
96
99
  goto _test_eof;
@@ -118,7 +121,7 @@ case 2:
118
121
  goto st2;
119
122
  goto st0;
120
123
  tr2:
121
- #line 101 "parser.rl"
124
+ #line 103 "parser.rl"
122
125
  {
123
126
  char *np = JSON_parse_string(json, p, pe, &last_name);
124
127
  if (np == NULL) { p--; {p++; cs = 3; goto _out;} } else {p = (( np))-1;}
@@ -128,7 +131,7 @@ st3:
128
131
  if ( ++p == pe )
129
132
  goto _test_eof3;
130
133
  case 3:
131
- #line 132 "parser.c"
134
+ #line 135 "parser.c"
132
135
  switch( (*p) ) {
133
136
  case 13: goto st3;
134
137
  case 32: goto st3;
@@ -195,7 +198,7 @@ case 8:
195
198
  goto st8;
196
199
  goto st0;
197
200
  tr11:
198
- #line 90 "parser.rl"
201
+ #line 92 "parser.rl"
199
202
  {
200
203
  VALUE v = Qnil;
201
204
  char *np = JSON_parse_value(json, p, pe, &v);
@@ -211,7 +214,7 @@ st9:
211
214
  if ( ++p == pe )
212
215
  goto _test_eof9;
213
216
  case 9:
214
- #line 215 "parser.c"
217
+ #line 218 "parser.c"
215
218
  switch( (*p) ) {
216
219
  case 13: goto st9;
217
220
  case 32: goto st9;
@@ -300,14 +303,14 @@ case 18:
300
303
  goto st9;
301
304
  goto st18;
302
305
  tr4:
303
- #line 106 "parser.rl"
306
+ #line 108 "parser.rl"
304
307
  { p--; {p++; cs = 27; goto _out;} }
305
308
  goto st27;
306
309
  st27:
307
310
  if ( ++p == pe )
308
311
  goto _test_eof27;
309
312
  case 27:
310
- #line 311 "parser.c"
313
+ #line 314 "parser.c"
311
314
  goto st0;
312
315
  st19:
313
316
  if ( ++p == pe )
@@ -405,7 +408,7 @@ case 26:
405
408
  _out: {}
406
409
  }
407
410
 
408
- #line 130 "parser.rl"
411
+ #line 133 "parser.rl"
409
412
 
410
413
  if (cs >= JSON_object_first_final) {
411
414
  if (RTEST(json->create_id)) {
@@ -424,7 +427,7 @@ case 26:
424
427
  }
425
428
 
426
429
 
427
- #line 428 "parser.c"
430
+ #line 431 "parser.c"
428
431
  static const int JSON_value_start = 1;
429
432
  static const int JSON_value_first_final = 21;
430
433
  static const int JSON_value_error = 0;
@@ -432,7 +435,7 @@ static const int JSON_value_error = 0;
432
435
  static const int JSON_value_en_main = 1;
433
436
 
434
437
 
435
- #line 228 "parser.rl"
438
+ #line 231 "parser.rl"
436
439
 
437
440
 
438
441
  static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -440,14 +443,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
440
443
  int cs = EVIL;
441
444
 
442
445
 
443
- #line 444 "parser.c"
446
+ #line 447 "parser.c"
444
447
  {
445
448
  cs = JSON_value_start;
446
449
  }
447
450
 
448
- #line 235 "parser.rl"
451
+ #line 238 "parser.rl"
449
452
 
450
- #line 451 "parser.c"
453
+ #line 454 "parser.c"
451
454
  {
452
455
  if ( p == pe )
453
456
  goto _test_eof;
@@ -472,14 +475,14 @@ st0:
472
475
  cs = 0;
473
476
  goto _out;
474
477
  tr0:
475
- #line 176 "parser.rl"
478
+ #line 179 "parser.rl"
476
479
  {
477
480
  char *np = JSON_parse_string(json, p, pe, result);
478
481
  if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
479
482
  }
480
483
  goto st21;
481
484
  tr2:
482
- #line 181 "parser.rl"
485
+ #line 184 "parser.rl"
483
486
  {
484
487
  char *np;
485
488
  if(pe > p + 9 && !strncmp(MinusInfinity, p, 9)) {
@@ -499,7 +502,7 @@ tr2:
499
502
  }
500
503
  goto st21;
501
504
  tr5:
502
- #line 199 "parser.rl"
505
+ #line 202 "parser.rl"
503
506
  {
504
507
  char *np;
505
508
  json->current_nesting++;
@@ -509,7 +512,7 @@ tr5:
509
512
  }
510
513
  goto st21;
511
514
  tr9:
512
- #line 207 "parser.rl"
515
+ #line 210 "parser.rl"
513
516
  {
514
517
  char *np;
515
518
  json->current_nesting++;
@@ -519,7 +522,7 @@ tr9:
519
522
  }
520
523
  goto st21;
521
524
  tr16:
522
- #line 169 "parser.rl"
525
+ #line 172 "parser.rl"
523
526
  {
524
527
  if (json->allow_nan) {
525
528
  *result = CInfinity;
@@ -529,7 +532,7 @@ tr16:
529
532
  }
530
533
  goto st21;
531
534
  tr18:
532
- #line 162 "parser.rl"
535
+ #line 165 "parser.rl"
533
536
  {
534
537
  if (json->allow_nan) {
535
538
  *result = CNaN;
@@ -539,19 +542,19 @@ tr18:
539
542
  }
540
543
  goto st21;
541
544
  tr22:
542
- #line 156 "parser.rl"
545
+ #line 159 "parser.rl"
543
546
  {
544
547
  *result = Qfalse;
545
548
  }
546
549
  goto st21;
547
550
  tr25:
548
- #line 153 "parser.rl"
551
+ #line 156 "parser.rl"
549
552
  {
550
553
  *result = Qnil;
551
554
  }
552
555
  goto st21;
553
556
  tr28:
554
- #line 159 "parser.rl"
557
+ #line 162 "parser.rl"
555
558
  {
556
559
  *result = Qtrue;
557
560
  }
@@ -560,9 +563,9 @@ st21:
560
563
  if ( ++p == pe )
561
564
  goto _test_eof21;
562
565
  case 21:
563
- #line 215 "parser.rl"
566
+ #line 218 "parser.rl"
564
567
  { p--; {p++; cs = 21; goto _out;} }
565
- #line 566 "parser.c"
568
+ #line 569 "parser.c"
566
569
  goto st0;
567
570
  st2:
568
571
  if ( ++p == pe )
@@ -723,7 +726,7 @@ case 20:
723
726
  _out: {}
724
727
  }
725
728
 
726
- #line 236 "parser.rl"
729
+ #line 239 "parser.rl"
727
730
 
728
731
  if (cs >= JSON_value_first_final) {
729
732
  return p;
@@ -733,7 +736,7 @@ case 20:
733
736
  }
734
737
 
735
738
 
736
- #line 737 "parser.c"
739
+ #line 740 "parser.c"
737
740
  static const int JSON_integer_start = 1;
738
741
  static const int JSON_integer_first_final = 5;
739
742
  static const int JSON_integer_error = 0;
@@ -741,7 +744,7 @@ static const int JSON_integer_error = 0;
741
744
  static const int JSON_integer_en_main = 1;
742
745
 
743
746
 
744
- #line 252 "parser.rl"
747
+ #line 255 "parser.rl"
745
748
 
746
749
 
747
750
  static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -749,15 +752,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
749
752
  int cs = EVIL;
750
753
 
751
754
 
752
- #line 753 "parser.c"
755
+ #line 756 "parser.c"
753
756
  {
754
757
  cs = JSON_integer_start;
755
758
  }
756
759
 
757
- #line 259 "parser.rl"
760
+ #line 262 "parser.rl"
758
761
  json->memo = p;
759
762
 
760
- #line 761 "parser.c"
763
+ #line 764 "parser.c"
761
764
  {
762
765
  if ( p == pe )
763
766
  goto _test_eof;
@@ -791,14 +794,14 @@ case 3:
791
794
  goto st0;
792
795
  goto tr4;
793
796
  tr4:
794
- #line 249 "parser.rl"
797
+ #line 252 "parser.rl"
795
798
  { p--; {p++; cs = 5; goto _out;} }
796
799
  goto st5;
797
800
  st5:
798
801
  if ( ++p == pe )
799
802
  goto _test_eof5;
800
803
  case 5:
801
- #line 802 "parser.c"
804
+ #line 805 "parser.c"
802
805
  goto st0;
803
806
  st4:
804
807
  if ( ++p == pe )
@@ -817,7 +820,7 @@ case 4:
817
820
  _out: {}
818
821
  }
819
822
 
820
- #line 261 "parser.rl"
823
+ #line 264 "parser.rl"
821
824
 
822
825
  if (cs >= JSON_integer_first_final) {
823
826
  long len = p - json->memo;
@@ -829,7 +832,7 @@ case 4:
829
832
  }
830
833
 
831
834
 
832
- #line 833 "parser.c"
835
+ #line 836 "parser.c"
833
836
  static const int JSON_float_start = 1;
834
837
  static const int JSON_float_first_final = 10;
835
838
  static const int JSON_float_error = 0;
@@ -837,7 +840,7 @@ static const int JSON_float_error = 0;
837
840
  static const int JSON_float_en_main = 1;
838
841
 
839
842
 
840
- #line 283 "parser.rl"
843
+ #line 286 "parser.rl"
841
844
 
842
845
 
843
846
  static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -845,15 +848,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
845
848
  int cs = EVIL;
846
849
 
847
850
 
848
- #line 849 "parser.c"
851
+ #line 852 "parser.c"
849
852
  {
850
853
  cs = JSON_float_start;
851
854
  }
852
855
 
853
- #line 290 "parser.rl"
856
+ #line 293 "parser.rl"
854
857
  json->memo = p;
855
858
 
856
- #line 857 "parser.c"
859
+ #line 860 "parser.c"
857
860
  {
858
861
  if ( p == pe )
859
862
  goto _test_eof;
@@ -911,14 +914,14 @@ case 5:
911
914
  goto st0;
912
915
  goto tr7;
913
916
  tr7:
914
- #line 277 "parser.rl"
917
+ #line 280 "parser.rl"
915
918
  { p--; {p++; cs = 10; goto _out;} }
916
919
  goto st10;
917
920
  st10:
918
921
  if ( ++p == pe )
919
922
  goto _test_eof10;
920
923
  case 10:
921
- #line 922 "parser.c"
924
+ #line 925 "parser.c"
922
925
  goto st0;
923
926
  st6:
924
927
  if ( ++p == pe )
@@ -979,7 +982,7 @@ case 9:
979
982
  _out: {}
980
983
  }
981
984
 
982
- #line 292 "parser.rl"
985
+ #line 295 "parser.rl"
983
986
 
984
987
  if (cs >= JSON_float_first_final) {
985
988
  long len = p - json->memo;
@@ -992,7 +995,7 @@ case 9:
992
995
 
993
996
 
994
997
 
995
- #line 996 "parser.c"
998
+ #line 999 "parser.c"
996
999
  static const int JSON_array_start = 1;
997
1000
  static const int JSON_array_first_final = 17;
998
1001
  static const int JSON_array_error = 0;
@@ -1000,27 +1003,28 @@ static const int JSON_array_error = 0;
1000
1003
  static const int JSON_array_en_main = 1;
1001
1004
 
1002
1005
 
1003
- #line 328 "parser.rl"
1006
+ #line 331 "parser.rl"
1004
1007
 
1005
1008
 
1006
1009
  static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
1007
1010
  {
1008
1011
  int cs = EVIL;
1012
+ VALUE array_class = json->array_class;
1009
1013
 
1010
1014
  if (json->max_nesting && json->current_nesting > json->max_nesting) {
1011
1015
  rb_raise(eNestingError, "nesting of %d is to deep", json->current_nesting);
1012
1016
  }
1013
- *result = rb_ary_new();
1017
+ *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
1014
1018
 
1015
1019
 
1016
- #line 1017 "parser.c"
1020
+ #line 1021 "parser.c"
1017
1021
  {
1018
1022
  cs = JSON_array_start;
1019
1023
  }
1020
1024
 
1021
- #line 340 "parser.rl"
1025
+ #line 344 "parser.rl"
1022
1026
 
1023
- #line 1024 "parser.c"
1027
+ #line 1028 "parser.c"
1024
1028
  {
1025
1029
  if ( p == pe )
1026
1030
  goto _test_eof;
@@ -1059,7 +1063,7 @@ case 2:
1059
1063
  goto st2;
1060
1064
  goto st0;
1061
1065
  tr2:
1062
- #line 309 "parser.rl"
1066
+ #line 312 "parser.rl"
1063
1067
  {
1064
1068
  VALUE v = Qnil;
1065
1069
  char *np = JSON_parse_value(json, p, pe, &v);
@@ -1075,7 +1079,7 @@ st3:
1075
1079
  if ( ++p == pe )
1076
1080
  goto _test_eof3;
1077
1081
  case 3:
1078
- #line 1079 "parser.c"
1082
+ #line 1083 "parser.c"
1079
1083
  switch( (*p) ) {
1080
1084
  case 13: goto st3;
1081
1085
  case 32: goto st3;
@@ -1175,14 +1179,14 @@ case 12:
1175
1179
  goto st3;
1176
1180
  goto st12;
1177
1181
  tr4:
1178
- #line 320 "parser.rl"
1182
+ #line 323 "parser.rl"
1179
1183
  { p--; {p++; cs = 17; goto _out;} }
1180
1184
  goto st17;
1181
1185
  st17:
1182
1186
  if ( ++p == pe )
1183
1187
  goto _test_eof17;
1184
1188
  case 17:
1185
- #line 1186 "parser.c"
1189
+ #line 1190 "parser.c"
1186
1190
  goto st0;
1187
1191
  st13:
1188
1192
  if ( ++p == pe )
@@ -1238,7 +1242,7 @@ case 16:
1238
1242
  _out: {}
1239
1243
  }
1240
1244
 
1241
- #line 341 "parser.rl"
1245
+ #line 345 "parser.rl"
1242
1246
 
1243
1247
  if(cs >= JSON_array_first_final) {
1244
1248
  return p + 1;
@@ -1304,7 +1308,7 @@ static VALUE json_string_unescape(char *p, char *pe)
1304
1308
  }
1305
1309
 
1306
1310
 
1307
- #line 1308 "parser.c"
1311
+ #line 1312 "parser.c"
1308
1312
  static const int JSON_string_start = 1;
1309
1313
  static const int JSON_string_first_final = 8;
1310
1314
  static const int JSON_string_error = 0;
@@ -1312,7 +1316,7 @@ static const int JSON_string_error = 0;
1312
1316
  static const int JSON_string_en_main = 1;
1313
1317
 
1314
1318
 
1315
- #line 425 "parser.rl"
1319
+ #line 429 "parser.rl"
1316
1320
 
1317
1321
 
1318
1322
  static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -1321,15 +1325,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
1321
1325
 
1322
1326
  *result = rb_str_new("", 0);
1323
1327
 
1324
- #line 1325 "parser.c"
1328
+ #line 1329 "parser.c"
1325
1329
  {
1326
1330
  cs = JSON_string_start;
1327
1331
  }
1328
1332
 
1329
- #line 433 "parser.rl"
1333
+ #line 437 "parser.rl"
1330
1334
  json->memo = p;
1331
1335
 
1332
- #line 1333 "parser.c"
1336
+ #line 1337 "parser.c"
1333
1337
  {
1334
1338
  if ( p == pe )
1335
1339
  goto _test_eof;
@@ -1354,7 +1358,7 @@ case 2:
1354
1358
  goto st0;
1355
1359
  goto st2;
1356
1360
  tr2:
1357
- #line 411 "parser.rl"
1361
+ #line 415 "parser.rl"
1358
1362
  {
1359
1363
  *result = json_string_unescape(json->memo + 1, p);
1360
1364
  if (NIL_P(*result)) {
@@ -1365,14 +1369,14 @@ tr2:
1365
1369
  {p = (( p + 1))-1;}
1366
1370
  }
1367
1371
  }
1368
- #line 422 "parser.rl"
1372
+ #line 426 "parser.rl"
1369
1373
  { p--; {p++; cs = 8; goto _out;} }
1370
1374
  goto st8;
1371
1375
  st8:
1372
1376
  if ( ++p == pe )
1373
1377
  goto _test_eof8;
1374
1378
  case 8:
1375
- #line 1376 "parser.c"
1379
+ #line 1380 "parser.c"
1376
1380
  goto st0;
1377
1381
  st3:
1378
1382
  if ( ++p == pe )
@@ -1448,7 +1452,7 @@ case 7:
1448
1452
  _out: {}
1449
1453
  }
1450
1454
 
1451
- #line 435 "parser.rl"
1455
+ #line 439 "parser.rl"
1452
1456
 
1453
1457
  if (cs >= JSON_string_first_final) {
1454
1458
  return p + 1;
@@ -1459,7 +1463,7 @@ case 7:
1459
1463
 
1460
1464
 
1461
1465
 
1462
- #line 1463 "parser.c"
1466
+ #line 1467 "parser.c"
1463
1467
  static const int JSON_start = 1;
1464
1468
  static const int JSON_first_final = 10;
1465
1469
  static const int JSON_error = 0;
@@ -1467,7 +1471,7 @@ static const int JSON_error = 0;
1467
1471
  static const int JSON_en_main = 1;
1468
1472
 
1469
1473
 
1470
- #line 469 "parser.rl"
1474
+ #line 473 "parser.rl"
1471
1475
 
1472
1476
 
1473
1477
  /*
@@ -1502,6 +1506,8 @@ static const int JSON_en_main = 1;
1502
1506
  * * *create_additions*: If set to false, the Parser doesn't create
1503
1507
  * additions even if a matchin class and create_id was found. This option
1504
1508
  * defaults to true.
1509
+ * * *object_class*: Defaults to Hash
1510
+ * * *array_class*: Defaults to Array
1505
1511
  */
1506
1512
  static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1507
1513
  {
@@ -1551,11 +1557,25 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
1551
1557
  } else {
1552
1558
  json->create_id = rb_funcall(mJSON, i_create_id, 0);
1553
1559
  }
1560
+ tmp = ID2SYM(i_object_class);
1561
+ if (st_lookup(RHASH_TBL(opts), tmp, 0)) {
1562
+ json->object_class = rb_hash_aref(opts, tmp);
1563
+ } else {
1564
+ json->object_class = Qnil;
1565
+ }
1566
+ tmp = ID2SYM(i_array_class);
1567
+ if (st_lookup(RHASH_TBL(opts), tmp, 0)) {
1568
+ json->array_class = rb_hash_aref(opts, tmp);
1569
+ } else {
1570
+ json->array_class = Qnil;
1571
+ }
1554
1572
  }
1555
1573
  } else {
1556
1574
  json->max_nesting = 19;
1557
1575
  json->allow_nan = 0;
1558
1576
  json->create_id = rb_funcall(mJSON, i_create_id, 0);
1577
+ json->object_class = Qnil;
1578
+ json->array_class = Qnil;
1559
1579
  }
1560
1580
  json->current_nesting = 0;
1561
1581
  /*
@@ -1590,16 +1610,16 @@ static VALUE cParser_parse(VALUE self)
1590
1610
  GET_STRUCT;
1591
1611
 
1592
1612
 
1593
- #line 1594 "parser.c"
1613
+ #line 1614 "parser.c"
1594
1614
  {
1595
1615
  cs = JSON_start;
1596
1616
  }
1597
1617
 
1598
- #line 591 "parser.rl"
1618
+ #line 611 "parser.rl"
1599
1619
  p = json->source;
1600
1620
  pe = p + json->len;
1601
1621
 
1602
- #line 1603 "parser.c"
1622
+ #line 1623 "parser.c"
1603
1623
  {
1604
1624
  if ( p == pe )
1605
1625
  goto _test_eof;
@@ -1655,7 +1675,7 @@ case 5:
1655
1675
  goto st1;
1656
1676
  goto st5;
1657
1677
  tr3:
1658
- #line 458 "parser.rl"
1678
+ #line 462 "parser.rl"
1659
1679
  {
1660
1680
  char *np;
1661
1681
  json->current_nesting = 1;
@@ -1664,7 +1684,7 @@ tr3:
1664
1684
  }
1665
1685
  goto st10;
1666
1686
  tr4:
1667
- #line 451 "parser.rl"
1687
+ #line 455 "parser.rl"
1668
1688
  {
1669
1689
  char *np;
1670
1690
  json->current_nesting = 1;
@@ -1676,7 +1696,7 @@ st10:
1676
1696
  if ( ++p == pe )
1677
1697
  goto _test_eof10;
1678
1698
  case 10:
1679
- #line 1680 "parser.c"
1699
+ #line 1700 "parser.c"
1680
1700
  switch( (*p) ) {
1681
1701
  case 13: goto st10;
1682
1702
  case 32: goto st10;
@@ -1733,7 +1753,7 @@ case 9:
1733
1753
  _out: {}
1734
1754
  }
1735
1755
 
1736
- #line 594 "parser.rl"
1756
+ #line 614 "parser.rl"
1737
1757
 
1738
1758
  if (cs >= JSON_first_final && p == pe) {
1739
1759
  return result;
@@ -1753,6 +1773,8 @@ static void JSON_mark(JSON_Parser *json)
1753
1773
  {
1754
1774
  rb_gc_mark_maybe(json->Vsource);
1755
1775
  rb_gc_mark_maybe(json->create_id);
1776
+ rb_gc_mark_maybe(json->object_class);
1777
+ rb_gc_mark_maybe(json->array_class);
1756
1778
  }
1757
1779
 
1758
1780
  static void JSON_free(JSON_Parser *json)
@@ -1802,4 +1824,6 @@ void Init_parser()
1802
1824
  i_chr = rb_intern("chr");
1803
1825
  i_max_nesting = rb_intern("max_nesting");
1804
1826
  i_allow_nan = rb_intern("allow_nan");
1827
+ i_object_class = rb_intern("object_class");
1828
+ i_array_class = rb_intern("array_class");
1805
1829
  }