diff options
-rw-r--r-- | Rakefile | 162 | ||||
-rwxr-xr-x | benchmarks/generator2_benchmark.rb | 2 | ||||
-rwxr-xr-x | benchmarks/generator_benchmark.rb | 2 | ||||
-rw-r--r-- | ext/json/ext/parser/parser.c | 136 | ||||
-rw-r--r-- | java/lib/bytelist-1.0.6.jar | bin | 0 -> 10493 bytes | |||
-rw-r--r-- | java/lib/jcodings.jar | bin | 0 -> 242327 bytes | |||
-rw-r--r-- | java/src/json/ext/ByteListTranscoder.java (renamed from src/json/ext/ByteListTranscoder.java) | 0 | ||||
-rw-r--r-- | java/src/json/ext/Generator.java (renamed from src/json/ext/Generator.java) | 0 | ||||
-rw-r--r-- | java/src/json/ext/GeneratorMethods.java (renamed from src/json/ext/GeneratorMethods.java) | 0 | ||||
-rw-r--r-- | java/src/json/ext/GeneratorService.java (renamed from src/json/ext/GeneratorService.java) | 0 | ||||
-rw-r--r-- | java/src/json/ext/GeneratorState.java (renamed from src/json/ext/GeneratorState.java) | 0 | ||||
-rw-r--r-- | java/src/json/ext/OptionsReader.java (renamed from src/json/ext/OptionsReader.java) | 0 | ||||
-rw-r--r-- | java/src/json/ext/Parser.java (renamed from src/json/ext/Parser.java) | 146 | ||||
-rw-r--r-- | java/src/json/ext/Parser.rl (renamed from src/json/ext/Parser.rl) | 0 | ||||
-rw-r--r-- | java/src/json/ext/ParserService.java (renamed from src/json/ext/ParserService.java) | 0 | ||||
-rw-r--r-- | java/src/json/ext/RuntimeInfo.java (renamed from src/json/ext/RuntimeInfo.java) | 0 | ||||
-rw-r--r-- | java/src/json/ext/StringDecoder.java (renamed from src/json/ext/StringDecoder.java) | 0 | ||||
-rw-r--r-- | java/src/json/ext/StringEncoder.java (renamed from src/json/ext/StringEncoder.java) | 0 | ||||
-rw-r--r-- | java/src/json/ext/Utils.java (renamed from src/json/ext/Utils.java) | 0 | ||||
-rw-r--r-- | json-java.gemspec | 2 | ||||
-rw-r--r-- | lib/json/pure/generator.rb | 10 | ||||
-rwxr-xr-x | tests/test_json_addition.rb | 2 | ||||
-rwxr-xr-x | tests/test_json_generate.rb | 2 | ||||
-rwxr-xr-x | tests/test_json_rails.rb | 2 |
24 files changed, 268 insertions, 198 deletions
@@ -6,7 +6,7 @@ end begin require 'rake/extensiontask' rescue LoadError - puts "WARNING: rake-compiler is not installed. You will not be able to build the json gem until you install it." + warn "WARNING: rake-compiler is not installed. You will not be able to build the json gem until you install it." end require 'rbconfig' @@ -16,13 +16,15 @@ require 'rake/clean' CLOBBER.include Dir['benchmarks/data/*.{dat,log}'] CLEAN.include FileList['diagrams/*.*'], 'doc', 'coverage', 'tmp', FileList["ext/**/{Makefile,mkmf.log}"], 'build', 'dist', FileList['**/*.rbc'], - FileList["{ext,lib}/**/*.{so,bundle,#{CONFIG['DLEXT']},o,obj,pdb,lib,manifest,exp,def,jar}"] + FileList["{ext,lib}/**/*.{so,bundle,#{CONFIG['DLEXT']},o,obj,pdb,lib,manifest,exp,def,jar,class}"], + FileList['java/src/**/*.class'] MAKE = ENV['MAKE'] || %w[gmake make].find { |c| system(c, '-v') } PKG_NAME = 'json' PKG_TITLE = 'JSON Implementation for Ruby' PKG_VERSION = File.read('VERSION').chomp PKG_FILES = FileList["**/*"].exclude(/CVS|pkg|tmp|coverage|Makefile|\.nfs\./).exclude(/\.(so|bundle|o|class|#{CONFIG['DLEXT']})$/) + EXT_ROOT_DIR = 'ext/json/ext' EXT_PARSER_DIR = "#{EXT_ROOT_DIR}/parser" EXT_PARSER_DL = "#{EXT_PARSER_DIR}/parser.#{CONFIG['DLEXT']}" @@ -31,6 +33,14 @@ PKG_FILES << EXT_PARSER_SRC EXT_GENERATOR_DIR = "#{EXT_ROOT_DIR}/generator" EXT_GENERATOR_DL = "#{EXT_GENERATOR_DIR}/generator.#{CONFIG['DLEXT']}" EXT_GENERATOR_SRC = "#{EXT_GENERATOR_DIR}/generator.c" + +JAVA_DIR = "java/src/json/ext" +JAVA_PARSER_SRC = "#{JAVA_DIR}/Parser.java" +JAVA_SOURCES = FileList["#{JAVA_DIR}/*.java"] +JAVA_CLASSES = [] +JRUBY_PARSER_JAR = File.expand_path("lib/json/ext/parser.jar") +JRUBY_GENERATOR_JAR = File.expand_path("lib/json/ext/generator.jar") + RAGEL_CODEGEN = %w[rlcodegen rlgen-cd ragel].find { |c| system(c, '-v') } RAGEL_DOTGEN = %w[rlgen-dot rlgen-cd ragel].find { |c| system(c, '-v') } RAGEL_PATH = "#{EXT_PARSER_DIR}/parser.rl" @@ -45,16 +55,6 @@ def myruby(*args, &block) end end -def jruby(*args, &block) - @jruby ||= `which jruby`.chomp - options = (Hash === args.last) ? args.pop : {} - if args.length > 1 then - sh(*([@jruby] + args + [options]), &block) - else - sh("#{@jruby} #{args.first}", options, &block) - end -end - desc "Installing library (pure)" task :install_pure => :version do myruby 'install.rb' @@ -84,19 +84,6 @@ end desc "Compiling extension" task :compile_ext => [ EXT_PARSER_DL, EXT_GENERATOR_DL ] -desc "Compiling jruby extension" -task :compile_jruby do - sh 'ant -buildfile build.xml jar' -end - -desc "Package the jruby gem" -task :jruby_gem do - sh 'ant -buildfile build.xml clean gem' - sh 'gem build json-java.gemspec' - mkdir_p 'pkg' - mv "json-#{PKG_VERSION}-java.gem", 'pkg' -end - file EXT_PARSER_DL => EXT_PARSER_SRC do cd EXT_PARSER_DIR do myruby 'extconf.rb' @@ -116,6 +103,7 @@ end desc "Generate parser with ragel" task :ragel => EXT_PARSER_SRC +desc "Delete the ragel generated C source" task :ragel_clean do rm_rf EXT_PARSER_SRC end @@ -164,27 +152,17 @@ task :ragel_dot => [ :ragel_dot_png, :ragel_dot_ps ] desc "Testing library (pure ruby)" task :test_pure => :clean do ENV['JSON'] = 'pure' - ENV['RUBYOPT'] = "-Iext:lib #{ENV['RUBYOPT']}" - myruby "-S testrb #{Dir['./tests/*.rb'] * ' '}" + ENV['RUBYOPT'] = "-Ilib #{ENV['RUBYOPT']}" + myruby '-S', 'testrb', *Dir['tests/*.rb'] end desc "Testing library (extension)" task :test_ext => :compile_ext do ENV['JSON'] = 'ext' ENV['RUBYOPT'] = "-Iext:lib #{ENV['RUBYOPT']}" - myruby "-S testrb #{Dir['./tests/*.rb'] * ' '}" -end - -desc "Testing library (jruby)" -task :test_jruby => :compile_jruby do - ENV['JSON'] = 'ext' - ENV['RUBYOPT'] = "-Iext:lib #{ENV['RUBYOPT']}" - jruby "-S testrb #{Dir['./tests/*.rb'] * ' '}" + myruby '-S', 'testrb', *Dir['./tests/*.rb'] end -desc "Testing library (pure ruby and extension)" -task :test => [ :test_pure, :test_jruby, :test_ext ] - desc "Benchmarking parser" task :benchmark_parser do ENV['RUBYOPT'] = "-Ilib:ext #{ENV['RUBYOPT']}" @@ -312,17 +290,105 @@ EOT end end -desc "Build all gems and archives for a new release of the jruby extension." -task :release_jruby => [ :clean, :version, :jruby_gem ] +if defined?(RUBY_ENGINE) and RUBY_ENGINE == 'jruby' + file JAVA_PARSER_SRC => RAGEL_PATH do + cd JAVA_DIR do + if RAGEL_CODEGEN == 'ragel' + sh "ragel Parser.rl -J -o Parser.java" + else + sh "ragel -x Parser.rl | #{RAGEL_CODEGEN} -J" + end + end + end -desc "Build all gems and archives for a new release of json and json_pure." -task :release_ruby => [ :clean, :version, :cross, :native, :gem, ] do - sh "#$0 clean native gem" - sh "#$0 clean package" -end + JRUBY_JAR = File.join(Config::CONFIG["libdir"], "jruby.jar") + if File.exist?(JRUBY_JAR) + JAVA_SOURCES.each do |src| + classpath = (Dir['java/lib/*.jar'] << 'java/src' << JRUBY_JAR) * ':' + obj = src.sub(/\.java\Z/, '.class') + file obj => src do + sh 'javac', '-classpath', classpath, '-source', '1.5', src + end + JAVA_CLASSES << obj + end + else + warn "WARNING: Cannot find jruby in path => Cannot build jruby extension!" + end + + desc "Generate parser for java with ragel" + task :ragel_java => JAVA_PARSER_SRC + + desc "Delete the ragel generated Java source" + task :ragel_clean_java do + rm_rf JAVA_PARSER_SRC + end + + desc "Compiling jruby extension" + task :compile_jruby => JAVA_CLASSES + + desc "Package the jruby gem" + task :jruby_gem => :create_jar do + sh 'gem build json-java.gemspec' + mkdir_p 'pkg' + mv "json-#{PKG_VERSION}-java.gem", 'pkg' + end + + desc "Testing library (jruby)" + task :test_jruby => :create_jar do + ENV['JSON'] = 'ext' + myruby '-S', 'testrb', '-Ilib', *Dir['tests/*.rb'] + end + + desc "Create parser jar" + task :create_parser_jar => :compile_jruby do + cd 'java/src' do + parser_classes = FileList[ + "json/ext/ByteListTranscoder*.class", + "json/ext/OptionsReader*.class", + "json/ext/Parser*.class", + "json/ext/RuntimeInfo*.class", + "json/ext/StringDecoder*.class", + "json/ext/Utils*.class" + ] + sh 'jar', 'cf', File.basename(JRUBY_PARSER_JAR), *parser_classes + mv File.basename(JRUBY_PARSER_JAR), File.dirname(JRUBY_PARSER_JAR) + end + end + + desc "Create generator jar" + task :create_generator_jar => :compile_jruby do + cd 'java/src' do + generator_classes = FileList[ + "json/ext/ByteListTranscoder*.class", + "json/ext/OptionsReader*.class", + "json/ext/Generator*.class", + "json/ext/RuntimeInfo*.class", + "json/ext/StringEncoder*.class", + "json/ext/Utils*.class" + ] + sh 'jar', 'cf', File.basename(JRUBY_GENERATOR_JAR), *generator_classes + mv File.basename(JRUBY_GENERATOR_JAR), File.dirname(JRUBY_GENERATOR_JAR) + end + end + + desc "Create parser and generator jars" + task :create_jar => [ :create_parser_jar, :create_generator_jar ] -desc "Build all gems and archives for a new release." -task :release => [ :release_ruby, :release_jruby ] + desc "Build all gems and archives for a new release of the jruby extension." + task :release => [ :clean, :version, :jruby_gem ] + + desc "Testing library (jruby extension)" + task :test => :test_jruby +else + desc "Testing library (pure ruby and extension)" + task :test => [ :test_pure, :test_ext ] + + desc "Build all gems and archives for a new release of json and json_pure." + task :release => [ :clean, :version, :cross, :native, :gem, ] do + sh "#$0 clean native gem" + sh "#$0 clean package" + end +end desc "Compile in the the source directory" -task :default => [ :version, :compile_ext ] +task :default => [ :version ] diff --git a/benchmarks/generator2_benchmark.rb b/benchmarks/generator2_benchmark.rb index 3a32d05..9885143 100755 --- a/benchmarks/generator2_benchmark.rb +++ b/benchmarks/generator2_benchmark.rb @@ -138,7 +138,7 @@ class Generator2BenchmarkRails < Bullshit::RepeatCase histogram yes def benchmark_generator - @result = @big.to_json + @result = ActiveSupport::JSON.encode @big end alias reset_benchmark_generator generic_reset_method diff --git a/benchmarks/generator_benchmark.rb b/benchmarks/generator_benchmark.rb index 3f9b225..83fa577 100755 --- a/benchmarks/generator_benchmark.rb +++ b/benchmarks/generator_benchmark.rb @@ -140,7 +140,7 @@ class GeneratorBenchmarkRails < Bullshit::RepeatCase histogram yes def benchmark_generator - @result = @big.to_json + @result = ActiveSupport::JSON.encode @big end alias reset_benchmark_generator generic_reset_method diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index 1d639d2..a2f4601 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -94,7 +94,7 @@ static const int JSON_object_error = 0; static const int JSON_object_en_main = 1; -#line 143 "parser.rl" +#line 144 "parser.rl" static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -115,7 +115,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu cs = JSON_object_start; } -#line 158 "parser.rl" +#line 159 "parser.rl" #line 121 "parser.c" { @@ -158,7 +158,7 @@ st3: if ( ++p == pe ) goto _test_eof3; case 3: -#line 161 "parser.c" +#line 162 "parser.c" switch( (*p) ) { case 13: goto st3; case 32: goto st3; @@ -241,7 +241,7 @@ st9: if ( ++p == pe ) goto _test_eof9; case 9: -#line 244 "parser.c" +#line 245 "parser.c" switch( (*p) ) { case 13: goto st9; case 32: goto st9; @@ -330,14 +330,14 @@ case 18: goto st9; goto st18; tr4: -#line 134 "parser.rl" +#line 135 "parser.rl" { p--; {p++; cs = 27; goto _out;} } goto st27; st27: if ( ++p == pe ) goto _test_eof27; case 27: -#line 340 "parser.c" +#line 341 "parser.c" goto st0; st19: if ( ++p == pe ) @@ -435,7 +435,7 @@ case 26: _out: {} } -#line 159 "parser.rl" +#line 160 "parser.rl" if (cs >= JSON_object_first_final) { if (RTEST(json->create_id)) { @@ -454,7 +454,7 @@ case 26: } -#line 457 "parser.c" +#line 458 "parser.c" static const int JSON_value_start = 1; static const int JSON_value_first_final = 21; static const int JSON_value_error = 0; @@ -462,7 +462,7 @@ static const int JSON_value_error = 0; static const int JSON_value_en_main = 1; -#line 257 "parser.rl" +#line 258 "parser.rl" static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -470,14 +470,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul int cs = EVIL; -#line 473 "parser.c" +#line 474 "parser.c" { cs = JSON_value_start; } -#line 264 "parser.rl" +#line 265 "parser.rl" -#line 480 "parser.c" +#line 481 "parser.c" { if ( p == pe ) goto _test_eof; @@ -502,14 +502,14 @@ st0: cs = 0; goto _out; tr0: -#line 205 "parser.rl" +#line 206 "parser.rl" { char *np = JSON_parse_string(json, p, pe, result); if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;} } goto st21; tr2: -#line 210 "parser.rl" +#line 211 "parser.rl" { char *np; if(pe > p + 9 && !strncmp(MinusInfinity, p, 9)) { @@ -529,7 +529,7 @@ tr2: } goto st21; tr5: -#line 228 "parser.rl" +#line 229 "parser.rl" { char *np; json->current_nesting++; @@ -539,7 +539,7 @@ tr5: } goto st21; tr9: -#line 236 "parser.rl" +#line 237 "parser.rl" { char *np; json->current_nesting++; @@ -549,7 +549,7 @@ tr9: } goto st21; tr16: -#line 198 "parser.rl" +#line 199 "parser.rl" { if (json->allow_nan) { *result = CInfinity; @@ -559,7 +559,7 @@ tr16: } goto st21; tr18: -#line 191 "parser.rl" +#line 192 "parser.rl" { if (json->allow_nan) { *result = CNaN; @@ -569,19 +569,19 @@ tr18: } goto st21; tr22: -#line 185 "parser.rl" +#line 186 "parser.rl" { *result = Qfalse; } goto st21; tr25: -#line 182 "parser.rl" +#line 183 "parser.rl" { *result = Qnil; } goto st21; tr28: -#line 188 "parser.rl" +#line 189 "parser.rl" { *result = Qtrue; } @@ -590,9 +590,9 @@ st21: if ( ++p == pe ) goto _test_eof21; case 21: -#line 244 "parser.rl" +#line 245 "parser.rl" { p--; {p++; cs = 21; goto _out;} } -#line 595 "parser.c" +#line 596 "parser.c" goto st0; st2: if ( ++p == pe ) @@ -753,7 +753,7 @@ case 20: _out: {} } -#line 265 "parser.rl" +#line 266 "parser.rl" if (cs >= JSON_value_first_final) { return p; @@ -763,7 +763,7 @@ case 20: } -#line 766 "parser.c" +#line 767 "parser.c" static const int JSON_integer_start = 1; static const int JSON_integer_first_final = 5; static const int JSON_integer_error = 0; @@ -771,7 +771,7 @@ static const int JSON_integer_error = 0; static const int JSON_integer_en_main = 1; -#line 281 "parser.rl" +#line 282 "parser.rl" static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -779,15 +779,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res int cs = EVIL; -#line 782 "parser.c" +#line 783 "parser.c" { cs = JSON_integer_start; } -#line 288 "parser.rl" +#line 289 "parser.rl" json->memo = p; -#line 790 "parser.c" +#line 791 "parser.c" { if ( p == pe ) goto _test_eof; @@ -821,14 +821,14 @@ case 3: goto st0; goto tr4; tr4: -#line 278 "parser.rl" +#line 279 "parser.rl" { p--; {p++; cs = 5; goto _out;} } goto st5; st5: if ( ++p == pe ) goto _test_eof5; case 5: -#line 831 "parser.c" +#line 832 "parser.c" goto st0; st4: if ( ++p == pe ) @@ -847,7 +847,7 @@ case 4: _out: {} } -#line 290 "parser.rl" +#line 291 "parser.rl" if (cs >= JSON_integer_first_final) { long len = p - json->memo; @@ -859,7 +859,7 @@ case 4: } -#line 862 "parser.c" +#line 863 "parser.c" static const int JSON_float_start = 1; static const int JSON_float_first_final = 10; static const int JSON_float_error = 0; @@ -867,7 +867,7 @@ static const int JSON_float_error = 0; static const int JSON_float_en_main = 1; -#line 312 "parser.rl" +#line 313 "parser.rl" static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -875,15 +875,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul int cs = EVIL; -#line 878 "parser.c" +#line 879 "parser.c" { cs = JSON_float_start; } -#line 319 "parser.rl" +#line 320 "parser.rl" json->memo = p; -#line 886 "parser.c" +#line 887 "parser.c" { if ( p == pe ) goto _test_eof; @@ -941,14 +941,14 @@ case 5: goto st0; goto tr7; tr7: -#line 306 "parser.rl" +#line 307 "parser.rl" { p--; {p++; cs = 10; goto _out;} } goto st10; st10: if ( ++p == pe ) goto _test_eof10; case 10: -#line 951 "parser.c" +#line 952 "parser.c" goto st0; st6: if ( ++p == pe ) @@ -1009,7 +1009,7 @@ case 9: _out: {} } -#line 321 "parser.rl" +#line 322 "parser.rl" if (cs >= JSON_float_first_final) { long len = p - json->memo; @@ -1022,7 +1022,7 @@ case 9: -#line 1025 "parser.c" +#line 1026 "parser.c" static const int JSON_array_start = 1; static const int JSON_array_first_final = 17; static const int JSON_array_error = 0; @@ -1030,7 +1030,7 @@ static const int JSON_array_error = 0; static const int JSON_array_en_main = 1; -#line 357 "parser.rl" +#line 358 "parser.rl" static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -1044,14 +1044,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul *result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class); -#line 1047 "parser.c" +#line 1048 "parser.c" { cs = JSON_array_start; } -#line 370 "parser.rl" +#line 371 "parser.rl" -#line 1054 "parser.c" +#line 1055 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1090,7 +1090,7 @@ case 2: goto st2; goto st0; tr2: -#line 338 "parser.rl" +#line 339 "parser.rl" { VALUE v = Qnil; char *np = JSON_parse_value(json, p, pe, &v); @@ -1106,7 +1106,7 @@ st3: if ( ++p == pe ) goto _test_eof3; case 3: -#line 1109 "parser.c" +#line 1110 "parser.c" switch( (*p) ) { case 13: goto st3; case 32: goto st3; @@ -1206,14 +1206,14 @@ case 12: goto st3; goto st12; tr4: -#line 349 "parser.rl" +#line 350 "parser.rl" { p--; {p++; cs = 17; goto _out;} } goto st17; st17: if ( ++p == pe ) goto _test_eof17; case 17: -#line 1216 "parser.c" +#line 1217 "parser.c" goto st0; st13: if ( ++p == pe ) @@ -1269,7 +1269,7 @@ case 16: _out: {} } -#line 371 "parser.rl" +#line 372 "parser.rl" if(cs >= JSON_array_first_final) { return p + 1; @@ -1350,7 +1350,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd) } -#line 1353 "parser.c" +#line 1354 "parser.c" static const int JSON_string_start = 1; static const int JSON_string_first_final = 8; static const int JSON_string_error = 0; @@ -1358,7 +1358,7 @@ static const int JSON_string_error = 0; static const int JSON_string_en_main = 1; -#line 470 "parser.rl" +#line 471 "parser.rl" static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result) @@ -1367,15 +1367,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu *result = rb_str_buf_new(0); -#line 1370 "parser.c" +#line 1371 "parser.c" { cs = JSON_string_start; } -#line 478 "parser.rl" +#line 479 "parser.rl" json->memo = p; -#line 1378 "parser.c" +#line 1379 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1400,7 +1400,7 @@ case 2: goto st0; goto st2; tr2: -#line 456 "parser.rl" +#line 457 "parser.rl" { *result = json_string_unescape(*result, json->memo + 1, p); if (NIL_P(*result)) { @@ -1411,14 +1411,14 @@ tr2: {p = (( p + 1))-1;} } } -#line 467 "parser.rl" +#line 468 "parser.rl" { p--; {p++; cs = 8; goto _out;} } goto st8; st8: if ( ++p == pe ) goto _test_eof8; case 8: -#line 1421 "parser.c" +#line 1422 "parser.c" goto st0; st3: if ( ++p == pe ) @@ -1494,7 +1494,7 @@ case 7: _out: {} } -#line 480 "parser.rl" +#line 481 "parser.rl" if (json->symbolize_names && json->parsing_name) { *result = rb_str_intern(*result); @@ -1508,7 +1508,7 @@ case 7: -#line 1511 "parser.c" +#line 1512 "parser.c" static const int JSON_start = 1; static const int JSON_first_final = 10; static const int JSON_error = 0; @@ -1516,7 +1516,7 @@ static const int JSON_error = 0; static const int JSON_en_main = 1; -#line 517 "parser.rl" +#line 518 "parser.rl" /* @@ -1698,16 +1698,16 @@ static VALUE cParser_parse(VALUE self) GET_PARSER; -#line 1701 "parser.c" +#line 1702 "parser.c" { cs = JSON_start; } -#line 698 "parser.rl" +#line 699 "parser.rl" p = json->source; pe = p + json->len; -#line 1710 "parser.c" +#line 1711 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1763,7 +1763,7 @@ case 5: goto st1; goto st5; tr3: -#line 506 "parser.rl" +#line 507 "parser.rl" { char *np; json->current_nesting = 1; @@ -1772,7 +1772,7 @@ tr3: } goto st10; tr4: -#line 499 "parser.rl" +#line 500 "parser.rl" { char *np; json->current_nesting = 1; @@ -1784,7 +1784,7 @@ st10: if ( ++p == pe ) goto _test_eof10; case 10: -#line 1787 "parser.c" +#line 1788 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; @@ -1841,7 +1841,7 @@ case 9: _out: {} } -#line 701 "parser.rl" +#line 702 "parser.rl" if (cs >= JSON_first_final && p == pe) { return result; diff --git a/java/lib/bytelist-1.0.6.jar b/java/lib/bytelist-1.0.6.jar Binary files differnew file mode 100644 index 0000000..7918e7c --- /dev/null +++ b/java/lib/bytelist-1.0.6.jar diff --git a/java/lib/jcodings.jar b/java/lib/jcodings.jar Binary files differnew file mode 100644 index 0000000..e33fc99 --- /dev/null +++ b/java/lib/jcodings.jar diff --git a/src/json/ext/ByteListTranscoder.java b/java/src/json/ext/ByteListTranscoder.java index ed9e54b..ed9e54b 100644 --- a/src/json/ext/ByteListTranscoder.java +++ b/java/src/json/ext/ByteListTranscoder.java diff --git a/src/json/ext/Generator.java b/java/src/json/ext/Generator.java index 230d68f..230d68f 100644 --- a/src/json/ext/Generator.java +++ b/java/src/json/ext/Generator.java diff --git a/src/json/ext/GeneratorMethods.java b/java/src/json/ext/GeneratorMethods.java index 28a612d..28a612d 100644 --- a/src/json/ext/GeneratorMethods.java +++ b/java/src/json/ext/GeneratorMethods.java diff --git a/src/json/ext/GeneratorService.java b/java/src/json/ext/GeneratorService.java index b8deb22..b8deb22 100644 --- a/src/json/ext/GeneratorService.java +++ b/java/src/json/ext/GeneratorService.java diff --git a/src/json/ext/GeneratorState.java b/java/src/json/ext/GeneratorState.java index dc99000..dc99000 100644 --- a/src/json/ext/GeneratorState.java +++ b/java/src/json/ext/GeneratorState.java diff --git a/src/json/ext/OptionsReader.java b/java/src/json/ext/OptionsReader.java index 3bc8d5f..3bc8d5f 100644 --- a/src/json/ext/OptionsReader.java +++ b/java/src/json/ext/OptionsReader.java diff --git a/src/json/ext/Parser.java b/java/src/json/ext/Parser.java index e7c1b14..c8f6f3d 100644 --- a/src/json/ext/Parser.java +++ b/java/src/json/ext/Parser.java @@ -1,5 +1,5 @@ -// line 1 "src/json/ext/Parser.rl" +// line 1 "Parser.rl" /* * This code is copyrighted work by Daniel Luz <dev at mernen dot com>. * @@ -297,11 +297,11 @@ public class Parser extends RubyObject { } -// line 323 "src/json/ext/Parser.rl" +// line 323 "Parser.rl" -// line 305 "src/json/ext/Parser.java" +// line 305 "Parser.java" private static byte[] init__JSON_value_actions_0() { return new byte [] { @@ -415,7 +415,7 @@ static final int JSON_value_error = 0; static final int JSON_value_en_main = 1; -// line 429 "src/json/ext/Parser.rl" +// line 429 "Parser.rl" ParserResult parseValue(int p, int pe) { @@ -423,14 +423,14 @@ static final int JSON_value_en_main = 1; IRubyObject result = null; -// line 427 "src/json/ext/Parser.java" +// line 427 "Parser.java" { cs = JSON_value_start; } -// line 436 "src/json/ext/Parser.rl" +// line 436 "Parser.rl" -// line 434 "src/json/ext/Parser.java" +// line 434 "Parser.java" { int _klen; int _trans = 0; @@ -456,13 +456,13 @@ case 1: while ( _nacts-- > 0 ) { switch ( _JSON_value_actions[_acts++] ) { case 9: -// line 414 "src/json/ext/Parser.rl" +// line 414 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 466 "src/json/ext/Parser.java" +// line 466 "Parser.java" } } @@ -525,25 +525,25 @@ case 1: switch ( _JSON_value_actions[_acts++] ) { case 0: -// line 331 "src/json/ext/Parser.rl" +// line 331 "Parser.rl" { result = getRuntime().getNil(); } break; case 1: -// line 334 "src/json/ext/Parser.rl" +// line 334 "Parser.rl" { result = getRuntime().getFalse(); } break; case 2: -// line 337 "src/json/ext/Parser.rl" +// line 337 "Parser.rl" { result = getRuntime().getTrue(); } break; case 3: -// line 340 "src/json/ext/Parser.rl" +// line 340 "Parser.rl" { if (parser.allowNaN) { result = getConstant(CONST_NAN); @@ -553,7 +553,7 @@ case 1: } break; case 4: -// line 347 "src/json/ext/Parser.rl" +// line 347 "Parser.rl" { if (parser.allowNaN) { result = getConstant(CONST_INFINITY); @@ -563,7 +563,7 @@ case 1: } break; case 5: -// line 354 "src/json/ext/Parser.rl" +// line 354 "Parser.rl" { if (pe > p + 9 && absSubSequence(p, p + 9).toString().equals(JSON_MINUS_INFINITY)) { @@ -592,7 +592,7 @@ case 1: } break; case 6: -// line 380 "src/json/ext/Parser.rl" +// line 380 "Parser.rl" { ParserResult res = parseString(p, pe); if (res == null) { @@ -605,7 +605,7 @@ case 1: } break; case 7: -// line 390 "src/json/ext/Parser.rl" +// line 390 "Parser.rl" { currentNesting++; ParserResult res = parseArray(p, pe); @@ -620,7 +620,7 @@ case 1: } break; case 8: -// line 402 "src/json/ext/Parser.rl" +// line 402 "Parser.rl" { currentNesting++; ParserResult res = parseObject(p, pe); @@ -634,7 +634,7 @@ case 1: } } break; -// line 638 "src/json/ext/Parser.java" +// line 638 "Parser.java" } } } @@ -654,7 +654,7 @@ case 5: break; } } -// line 437 "src/json/ext/Parser.rl" +// line 437 "Parser.rl" if (cs >= JSON_value_first_final && result != null) { return new ParserResult(result, p); @@ -664,7 +664,7 @@ case 5: } -// line 668 "src/json/ext/Parser.java" +// line 668 "Parser.java" private static byte[] init__JSON_integer_actions_0() { return new byte [] { @@ -763,22 +763,22 @@ static final int JSON_integer_error = 0; static final int JSON_integer_en_main = 1; -// line 456 "src/json/ext/Parser.rl" +// line 456 "Parser.rl" ParserResult parseInteger(int p, int pe) { int cs = EVIL; -// line 774 "src/json/ext/Parser.java" +// line 774 "Parser.java" { cs = JSON_integer_start; } -// line 462 "src/json/ext/Parser.rl" +// line 462 "Parser.rl" int memo = p; -// line 782 "src/json/ext/Parser.java" +// line 782 "Parser.java" { int _klen; int _trans = 0; @@ -859,13 +859,13 @@ case 1: switch ( _JSON_integer_actions[_acts++] ) { case 0: -// line 450 "src/json/ext/Parser.rl" +// line 450 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 869 "src/json/ext/Parser.java" +// line 869 "Parser.java" } } } @@ -885,7 +885,7 @@ case 5: break; } } -// line 464 "src/json/ext/Parser.rl" +// line 464 "Parser.rl" if (cs < JSON_integer_first_final) { return null; @@ -900,7 +900,7 @@ case 5: } -// line 904 "src/json/ext/Parser.java" +// line 904 "Parser.java" private static byte[] init__JSON_float_actions_0() { return new byte [] { @@ -1002,22 +1002,22 @@ static final int JSON_float_error = 0; static final int JSON_float_en_main = 1; -// line 492 "src/json/ext/Parser.rl" +// line 492 "Parser.rl" ParserResult parseFloat(int p, int pe) { int cs = EVIL; -// line 1013 "src/json/ext/Parser.java" +// line 1013 "Parser.java" { cs = JSON_float_start; } -// line 498 "src/json/ext/Parser.rl" +// line 498 "Parser.rl" int memo = p; -// line 1021 "src/json/ext/Parser.java" +// line 1021 "Parser.java" { int _klen; int _trans = 0; @@ -1098,13 +1098,13 @@ case 1: switch ( _JSON_float_actions[_acts++] ) { case 0: -// line 483 "src/json/ext/Parser.rl" +// line 483 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 1108 "src/json/ext/Parser.java" +// line 1108 "Parser.java" } } } @@ -1124,7 +1124,7 @@ case 5: break; } } -// line 500 "src/json/ext/Parser.rl" +// line 500 "Parser.rl" if (cs < JSON_float_first_final) { return null; @@ -1139,7 +1139,7 @@ case 5: } -// line 1143 "src/json/ext/Parser.java" +// line 1143 "Parser.java" private static byte[] init__JSON_string_actions_0() { return new byte [] { @@ -1241,7 +1241,7 @@ static final int JSON_string_error = 0; static final int JSON_string_en_main = 1; -// line 544 "src/json/ext/Parser.rl" +// line 544 "Parser.rl" ParserResult parseString(int p, int pe) { @@ -1249,15 +1249,15 @@ static final int JSON_string_en_main = 1; RubyString result = null; -// line 1253 "src/json/ext/Parser.java" +// line 1253 "Parser.java" { cs = JSON_string_start; } -// line 551 "src/json/ext/Parser.rl" +// line 551 "Parser.rl" int memo = p; -// line 1261 "src/json/ext/Parser.java" +// line 1261 "Parser.java" { int _klen; int _trans = 0; @@ -1338,7 +1338,7 @@ case 1: switch ( _JSON_string_actions[_acts++] ) { case 0: -// line 519 "src/json/ext/Parser.rl" +// line 519 "Parser.rl" { int offset = byteList.begin(); ByteList decoded = decoder.decode(byteList, memo + 1 - offset, @@ -1353,13 +1353,13 @@ case 1: } break; case 1: -// line 532 "src/json/ext/Parser.rl" +// line 532 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 1363 "src/json/ext/Parser.java" +// line 1363 "Parser.java" } } } @@ -1379,7 +1379,7 @@ case 5: break; } } -// line 553 "src/json/ext/Parser.rl" +// line 553 "Parser.rl" if (cs >= JSON_string_first_final && result != null) { return new ParserResult(result, p + 1); @@ -1389,7 +1389,7 @@ case 5: } -// line 1393 "src/json/ext/Parser.java" +// line 1393 "Parser.java" private static byte[] init__JSON_array_actions_0() { return new byte [] { @@ -1502,7 +1502,7 @@ static final int JSON_array_error = 0; static final int JSON_array_en_main = 1; -// line 594 "src/json/ext/Parser.rl" +// line 594 "Parser.rl" ParserResult parseArray(int p, int pe) { @@ -1520,14 +1520,14 @@ static final int JSON_array_en_main = 1; IRubyObject.NULL_ARRAY, Block.NULL_BLOCK); -// line 1524 "src/json/ext/Parser.java" +// line 1524 "Parser.java" { cs = JSON_array_start; } -// line 611 "src/json/ext/Parser.rl" +// line 611 "Parser.rl" -// line 1531 "src/json/ext/Parser.java" +// line 1531 "Parser.java" { int _klen; int _trans = 0; @@ -1608,7 +1608,7 @@ case 1: switch ( _JSON_array_actions[_acts++] ) { case 0: -// line 567 "src/json/ext/Parser.rl" +// line 567 "Parser.rl" { ParserResult res = parseValue(p, pe); if (res == null) { @@ -1621,13 +1621,13 @@ case 1: } break; case 1: -// line 578 "src/json/ext/Parser.rl" +// line 578 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 1631 "src/json/ext/Parser.java" +// line 1631 "Parser.java" } } } @@ -1647,7 +1647,7 @@ case 5: break; } } -// line 612 "src/json/ext/Parser.rl" +// line 612 "Parser.rl" if (cs >= JSON_array_first_final) { return new ParserResult(result, p + 1); @@ -1657,7 +1657,7 @@ case 5: } -// line 1661 "src/json/ext/Parser.java" +// line 1661 "Parser.java" private static byte[] init__JSON_object_actions_0() { return new byte [] { @@ -1780,7 +1780,7 @@ static final int JSON_object_error = 0; static final int JSON_object_en_main = 1; -// line 668 "src/json/ext/Parser.rl" +// line 668 "Parser.rl" ParserResult parseObject(int p, int pe) { @@ -1799,14 +1799,14 @@ static final int JSON_object_en_main = 1; IRubyObject.NULL_ARRAY, Block.NULL_BLOCK); -// line 1803 "src/json/ext/Parser.java" +// line 1803 "Parser.java" { cs = JSON_object_start; } -// line 686 "src/json/ext/Parser.rl" +// line 686 "Parser.rl" -// line 1810 "src/json/ext/Parser.java" +// line 1810 "Parser.java" { int _klen; int _trans = 0; @@ -1887,7 +1887,7 @@ case 1: switch ( _JSON_object_actions[_acts++] ) { case 0: -// line 626 "src/json/ext/Parser.rl" +// line 626 "Parser.rl" { ParserResult res = parseValue(p, pe); if (res == null) { @@ -1900,7 +1900,7 @@ case 1: } break; case 1: -// line 637 "src/json/ext/Parser.rl" +// line 637 "Parser.rl" { ParserResult res = parseString(p, pe); if (res == null) { @@ -1920,13 +1920,13 @@ case 1: } break; case 2: -// line 655 "src/json/ext/Parser.rl" +// line 655 "Parser.rl" { p--; { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 1930 "src/json/ext/Parser.java" +// line 1930 "Parser.java" } } } @@ -1946,7 +1946,7 @@ case 5: break; } } -// line 687 "src/json/ext/Parser.rl" +// line 687 "Parser.rl" if (cs < JSON_object_first_final) { return null; @@ -1972,7 +1972,7 @@ case 5: } -// line 1976 "src/json/ext/Parser.java" +// line 1976 "Parser.java" private static byte[] init__JSON_actions_0() { return new byte [] { @@ -2076,7 +2076,7 @@ static final int JSON_error = 0; static final int JSON_en_main = 1; -// line 745 "src/json/ext/Parser.rl" +// line 745 "Parser.rl" public IRubyObject parse() { @@ -2085,16 +2085,16 @@ static final int JSON_en_main = 1; IRubyObject result = null; -// line 2089 "src/json/ext/Parser.java" +// line 2089 "Parser.java" { cs = JSON_start; } -// line 753 "src/json/ext/Parser.rl" +// line 753 "Parser.rl" p = byteList.begin(); pe = p + byteList.length(); -// line 2098 "src/json/ext/Parser.java" +// line 2098 "Parser.java" { int _klen; int _trans = 0; @@ -2175,7 +2175,7 @@ case 1: switch ( _JSON_actions[_acts++] ) { case 0: -// line 717 "src/json/ext/Parser.rl" +// line 717 "Parser.rl" { currentNesting = 1; ParserResult res = parseObject(p, pe); @@ -2189,7 +2189,7 @@ case 1: } break; case 1: -// line 729 "src/json/ext/Parser.rl" +// line 729 "Parser.rl" { currentNesting = 1; ParserResult res = parseArray(p, pe); @@ -2202,7 +2202,7 @@ case 1: } } break; -// line 2206 "src/json/ext/Parser.java" +// line 2206 "Parser.java" } } } @@ -2222,7 +2222,7 @@ case 5: break; } } -// line 756 "src/json/ext/Parser.rl" +// line 756 "Parser.rl" if (cs >= JSON_first_final && p == pe) { return result; diff --git a/src/json/ext/Parser.rl b/java/src/json/ext/Parser.rl index 00badc8..00badc8 100644 --- a/src/json/ext/Parser.rl +++ b/java/src/json/ext/Parser.rl diff --git a/src/json/ext/ParserService.java b/java/src/json/ext/ParserService.java index e0805a7..e0805a7 100644 --- a/src/json/ext/ParserService.java +++ b/java/src/json/ext/ParserService.java diff --git a/src/json/ext/RuntimeInfo.java b/java/src/json/ext/RuntimeInfo.java index f446afe..f446afe 100644 --- a/src/json/ext/RuntimeInfo.java +++ b/java/src/json/ext/RuntimeInfo.java diff --git a/src/json/ext/StringDecoder.java b/java/src/json/ext/StringDecoder.java index a4ee975..a4ee975 100644 --- a/src/json/ext/StringDecoder.java +++ b/java/src/json/ext/StringDecoder.java diff --git a/src/json/ext/StringEncoder.java b/java/src/json/ext/StringEncoder.java index 57bd19b..57bd19b 100644 --- a/src/json/ext/StringEncoder.java +++ b/java/src/json/ext/StringEncoder.java diff --git a/src/json/ext/Utils.java b/java/src/json/ext/Utils.java index 7a1dfee..7a1dfee 100644 --- a/src/json/ext/Utils.java +++ b/java/src/json/ext/Utils.java diff --git a/json-java.gemspec b/json-java.gemspec index c2d6c43..144f650 100644 --- a/json-java.gemspec +++ b/json-java.gemspec @@ -12,7 +12,7 @@ spec = Gem::Specification.new do |s| s.platform = 'java' s.rubyforge_project = "json-jruby" - s.files = Dir["../{docs,lib,tests}/**/*"] + s.files = Dir["{docs,lib,tests}/**/*"] end if $0 == __FILE__ diff --git a/lib/json/pure/generator.rb b/lib/json/pure/generator.rb index 335c6ae..94cb239 100644 --- a/lib/json/pure/generator.rb +++ b/lib/json/pure/generator.rb @@ -106,11 +106,13 @@ module JSON # an unconfigured instance. If _opts_ is a State object, it is just # returned. def self.from_state(opts) - case opts - when self + case + when self === opts opts - when Hash - new(opts) + when opts.respond_to?(:to_hash) + new(opts.to_hash) + when opts.respond_to?(:to_h) + new(opts.to_h) else SAFE_STATE_PROTOTYPE.dup end diff --git a/tests/test_json_addition.rb b/tests/test_json_addition.rb index 2c89e39..34f0a71 100755 --- a/tests/test_json_addition.rb +++ b/tests/test_json_addition.rb @@ -7,7 +7,7 @@ when 'pure' then require 'json/pure' when 'ext' then require 'json/ext' else require 'json' end -require 'json/add/core' +load 'json/add/core.rb' require 'date' class TC_JSONAddition < Test::Unit::TestCase diff --git a/tests/test_json_generate.rb b/tests/test_json_generate.rb index 69c967e..5380a06 100755 --- a/tests/test_json_generate.rb +++ b/tests/test_json_generate.rb @@ -84,6 +84,8 @@ EOT assert_raise(GeneratorError) { fast_generate(666) } end + + def test_states json = generate({1=>2}, nil) assert_equal('{"1":2}', json) diff --git a/tests/test_json_rails.rb b/tests/test_json_rails.rb index 7c3d51d..daa053c 100755 --- a/tests/test_json_rails.rb +++ b/tests/test_json_rails.rb @@ -7,7 +7,7 @@ when 'pure' then require 'json/pure' when 'ext' then require 'json/ext' else require 'json' end -require 'json/add/rails' +load 'json/add/rails.rb' require 'date' class TC_JSONRails < Test::Unit::TestCase |