summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2010-04-23 23:21:05 +0200
committerFlorian Frank <flori@ping.de>2010-04-23 23:24:53 +0200
commita8812e990071c0ed5fbdd824846bd753488e36ca (patch)
treefc7db59a79a9738f5017dab11ed1739ff3e5d910
parent927b2ba893fc927b4ac5e5222f1d84d49c93a3c5 (diff)
parentca292f9a9ba00cc6c5982015abeec8f1bb00eb90 (diff)
downloadjson-a8812e990071c0ed5fbdd824846bd753488e36ca.tar.gz
Merge branch 'rbx-fix'v1.4.0
Supports rubinius now. Avoided depending on MRI internals too much.
-rw-r--r--Rakefile2
-rwxr-xr-xbenchmarks/generator2_benchmark.rb8
-rwxr-xr-xbenchmarks/generator_benchmark.rb8
-rwxr-xr-xbenchmarks/parser_benchmark.rb10
-rw-r--r--ext/json/ext/extconf_generator.rb3
-rw-r--r--ext/json/ext/extconf_parser.rb3
-rw-r--r--ext/json/ext/generator.c54
-rw-r--r--ext/json/ext/generator.h1
-rw-r--r--ext/json/ext/parser.c38
-rw-r--r--ext/json/ext/parser.rl2
10 files changed, 41 insertions, 88 deletions
diff --git a/Rakefile b/Rakefile
index 57dae70..a7ca0ed 100644
--- a/Rakefile
+++ b/Rakefile
@@ -13,7 +13,7 @@ require 'rbconfig'
include Config
require 'rake/clean'
-CLOBBER.include Dir['benchmarks/data/*.{dat,log}']
+CLOBBER.include Dir['benchmarks/data/*.{dat,log}'], FileList['**/*.rbc']
CLEAN.include FileList['diagrams/*.*'], 'doc', 'coverage', 'tmp',
FileList["ext/**/{Makefile,mkmf.log}"],
FileList["{ext,lib}/**/*.{so,bundle,#{CONFIG['DLEXT']},o,obj,pdb,lib,manifest,exp,def}"]
diff --git a/benchmarks/generator2_benchmark.rb b/benchmarks/generator2_benchmark.rb
index 56f173c..3a32d05 100755
--- a/benchmarks/generator2_benchmark.rb
+++ b/benchmarks/generator2_benchmark.rb
@@ -66,7 +66,7 @@ class Generator2BenchmarkExt < Bullshit::RepeatCase
include JSONGeneratorCommon
warmup yes
- iterations 500
+ iterations 2000
truncate_data do
enabled false
@@ -92,7 +92,7 @@ class Generator2BenchmarkPure < Bullshit::RepeatCase
include JSONGeneratorCommon
warmup yes
- iterations 100
+ iterations 400
truncate_data do
enabled false
@@ -117,7 +117,7 @@ class Generator2BenchmarkRails < Bullshit::RepeatCase
include Generator2BenchmarkCommon
warmup yes
- iterations 100
+ iterations 400
truncate_data do
enabled false
@@ -148,7 +148,7 @@ class Generator2BenchmarkYajl < Bullshit::RepeatCase
include Generator2BenchmarkCommon
warmup yes
- iterations 500
+ iterations 2000
truncate_data do
enabled false
diff --git a/benchmarks/generator_benchmark.rb b/benchmarks/generator_benchmark.rb
index 272fc1d..3f9b225 100755
--- a/benchmarks/generator_benchmark.rb
+++ b/benchmarks/generator_benchmark.rb
@@ -68,7 +68,7 @@ class GeneratorBenchmarkExt < Bullshit::RepeatCase
include JSONGeneratorCommon
warmup yes
- iterations 500
+ iterations 2000
truncate_data do
enabled false
@@ -94,7 +94,7 @@ class GeneratorBenchmarkPure < Bullshit::RepeatCase
include JSONGeneratorCommon
warmup yes
- iterations 100
+ iterations 400
truncate_data do
enabled false
@@ -119,7 +119,7 @@ class GeneratorBenchmarkRails < Bullshit::RepeatCase
include GeneratorBenchmarkCommon
warmup yes
- iterations 100
+ iterations 400
truncate_data do
enabled false
@@ -150,7 +150,7 @@ class GeneratorBenchmarkYajl < Bullshit::RepeatCase
include GeneratorBenchmarkCommon
warmup yes
- iterations 500
+ iterations 2000
truncate_data do
enabled false
diff --git a/benchmarks/parser_benchmark.rb b/benchmarks/parser_benchmark.rb
index 33a0a67..9ce7e25 100755
--- a/benchmarks/parser_benchmark.rb
+++ b/benchmarks/parser_benchmark.rb
@@ -41,7 +41,7 @@ class ParserBenchmarkExt < Bullshit::RepeatCase
include ParserBenchmarkCommon
warmup yes
- iterations 500
+ iterations 2000
truncate_data do
enabled false
@@ -78,7 +78,7 @@ class ParserBenchmarkPure < Bullshit::RepeatCase
include ParserBenchmarkCommon
warmup yes
- iterations 100
+ iterations 400
truncate_data do
enabled false
@@ -113,7 +113,7 @@ end
class ParserBenchmarkYAML < Bullshit::RepeatCase
warmup yes
- iterations 100
+ iterations 400
truncate_data do
enabled false
@@ -150,7 +150,7 @@ end
class ParserBenchmarkRails < Bullshit::RepeatCase
warmup yes
- iterations 100
+ iterations 400
truncate_data do
enabled false
@@ -187,7 +187,7 @@ end
class ParserBenchmarkYajl < Bullshit::RepeatCase
warmup yes
- iterations 500
+ iterations 2000
truncate_data do
enabled false
diff --git a/ext/json/ext/extconf_generator.rb b/ext/json/ext/extconf_generator.rb
index a9e8562..38f678d 100644
--- a/ext/json/ext/extconf_generator.rb
+++ b/ext/json/ext/extconf_generator.rb
@@ -10,9 +10,6 @@ if CONFIG['CC'] =~ /gcc/
# $CFLAGS << ' -O0 -ggdb'
#end
end
-if RUBY_VERSION >= '1.9'
- $CFLAGS << ' -DRUBY_19'
-end
have_header("ruby/re.h") || have_header("re.h")
have_header("ruby/encoding.h")
diff --git a/ext/json/ext/extconf_parser.rb b/ext/json/ext/extconf_parser.rb
index 4da1661..786a831 100644
--- a/ext/json/ext/extconf_parser.rb
+++ b/ext/json/ext/extconf_parser.rb
@@ -10,9 +10,6 @@ if CONFIG['CC'] =~ /gcc/
# $CFLAGS << ' -O0 -ggdb'
#end
end
-if RUBY_VERSION >= '1.9'
- $CFLAGS << ' -DRUBY_19'
-end
have_header("re.h")
create_makefile 'parser'
diff --git a/ext/json/ext/generator.c b/ext/json/ext/generator.c
index d9da01e..05e0f7d 100644
--- a/ext/json/ext/generator.c
+++ b/ext/json/ext/generator.c
@@ -13,7 +13,7 @@ static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
static ID i_to_s, i_to_json, i_new, i_indent, i_space, i_space_before,
i_object_nl, i_array_nl, i_max_nesting, i_allow_nan, i_ascii_only,
i_pack, i_unpack, i_create_id, i_extend, i_key_p, i_aref, i_send,
- i_respond_to_p;
+ i_respond_to_p, i_match;
/*
* Copyright 2001-2004 Unicode, Inc.
@@ -728,51 +728,6 @@ static VALUE cState_aref(VALUE self, VALUE name)
}
}
-/*
- * The fbuffer2rstring breaks encapsulation of Ruby's String datatype to avoid
- * calling memcpy while creating a RString from a c string. This is rather
- * hackish code, I am not sure if it's a good idea to keep it.
- */
-#ifdef RUBY_19
-#define STR_NOEMBED FL_USER1
-
-#define STR_SET_EMBED_LEN(str, n) do { \
- long tmp_n = (n);\
- RBASIC(str)->flags &= ~RSTRING_EMBED_LEN_MASK;\
- RBASIC(str)->flags |= (tmp_n) << RSTRING_EMBED_LEN_SHIFT;\
-} while (0)
-
-#define STR_SET_NOEMBED(str) do {\
- FL_SET(str, STR_NOEMBED);\
- STR_SET_EMBED_LEN(str, 0);\
-} while (0)
-
-static VALUE fbuffer2rstring(FBuffer *buffer)
-{
- NEWOBJ(str, struct RString);
- OBJSETUP(str, rb_cString, T_STRING);
-
- str->as.heap.ptr = FBUFFER_PTR(buffer);
- str->as.heap.len = FBUFFER_LEN(buffer);
- str->as.heap.aux.capa = FBUFFER_CAPA(buffer);
- STR_SET_NOEMBED(str);
-
- return (VALUE) str;
-}
-#else
-static VALUE fbuffer2rstring(FBuffer *buffer)
-{
- NEWOBJ(str, struct RString);
- OBJSETUP(str, rb_cString, T_STRING);
-
- str->ptr = FBUFFER_PTR(buffer);
- str->len = FBUFFER_LEN(buffer);
- str->aux.capa = FBUFFER_CAPA(buffer);
-
- return (VALUE) str;
-}
-#endif
-
static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj, long depth)
{
VALUE tmp;
@@ -889,7 +844,7 @@ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *s
fbuffer_append_integer(buffer, FIX2INT(obj));
break;
case T_BIGNUM:
- tmp = rb_big2str0(obj, 10, 1);
+ tmp = rb_funcall(obj, i_to_s, 0);
fbuffer_append(buffer, RSTRING_PAIR(tmp));
break;
case T_FLOAT:
@@ -958,7 +913,7 @@ static VALUE cState_partial_generate(VALUE self, VALUE obj, VALUE depth)
if (state->array_nl) fbuffer_append(state->array_delim, state->array_nl, state->array_nl_len);
generate_json(buffer, self, state, obj, NIL_P(depth) ? 0 : FIX2INT(depth));
- result = fbuffer2rstring(buffer);
+ result = rb_str_new(FBUFFER_PAIR(buffer));
fbuffer_free_only_buffer(buffer);
FORCE_UTF8(result);
return result;
@@ -978,7 +933,7 @@ static VALUE cState_generate(VALUE self, VALUE obj)
args[0] = rb_str_new2("\\A\\s*(?:\\[.*\\]|\\{.*\\})\\s*\\Z");
args[1] = CRegexp_MULTILINE;
re = rb_class_new_instance(2, args, rb_cRegexp);
- if (NIL_P(rb_reg_match(re, result))) {
+ if (NIL_P(rb_funcall(re, i_match, 1, result))) {
rb_raise(eGeneratorError, "only generation of JSON objects or arrays allowed");
}
return result;
@@ -1369,6 +1324,7 @@ void Init_generator()
i_aref = rb_intern("[]");
i_send = rb_intern("__send__");
i_respond_to_p = rb_intern("respond_to?");
+ i_match = rb_intern("match");
#ifdef HAVE_RUBY_ENCODING_H
CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
i_encoding = rb_intern("encoding");
diff --git a/ext/json/ext/generator.h b/ext/json/ext/generator.h
index baa02a6..72d7c8a 100644
--- a/ext/json/ext/generator.h
+++ b/ext/json/ext/generator.h
@@ -147,7 +147,6 @@ static JSON_Generator_State *State_allocate();
static VALUE cState_s_allocate(VALUE klass);
static VALUE cState_configure(VALUE self, VALUE opts);
static VALUE cState_to_h(VALUE self);
-static VALUE fbuffer2rstring(FBuffer *buffer);
static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj, long depth);
static VALUE cState_partial_generate(VALUE self, VALUE obj, VALUE depth);
static VALUE cState_generate(VALUE self, VALUE obj);
diff --git a/ext/json/ext/parser.c b/ext/json/ext/parser.c
index 0dadf74..e1d5bca 100644
--- a/ext/json/ext/parser.c
+++ b/ext/json/ext/parser.c
@@ -1274,6 +1274,7 @@ case 16:
return p + 1;
} else {
rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+ return NULL;
}
}
@@ -1348,7 +1349,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
}
-#line 1352 "parser.c"
+#line 1353 "parser.c"
static const int JSON_string_start = 1;
static const int JSON_string_first_final = 8;
static const int JSON_string_error = 0;
@@ -1356,7 +1357,7 @@ static const int JSON_string_error = 0;
static const int JSON_string_en_main = 1;
-#line 469 "parser.rl"
+#line 470 "parser.rl"
static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -1365,15 +1366,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
*result = rb_str_buf_new(0);
-#line 1369 "parser.c"
+#line 1370 "parser.c"
{
cs = JSON_string_start;
}
-#line 477 "parser.rl"
+#line 478 "parser.rl"
json->memo = p;
-#line 1377 "parser.c"
+#line 1378 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1398,7 +1399,7 @@ case 2:
goto st0;
goto st2;
tr2:
-#line 455 "parser.rl"
+#line 456 "parser.rl"
{
*result = json_string_unescape(*result, json->memo + 1, p);
if (NIL_P(*result)) {
@@ -1409,14 +1410,14 @@ tr2:
{p = (( p + 1))-1;}
}
}
-#line 466 "parser.rl"
+#line 467 "parser.rl"
{ p--; {p++; cs = 8; goto _out;} }
goto st8;
st8:
if ( ++p == pe )
goto _test_eof8;
case 8:
-#line 1420 "parser.c"
+#line 1421 "parser.c"
goto st0;
st3:
if ( ++p == pe )
@@ -1492,7 +1493,7 @@ case 7:
_out: {}
}
-#line 479 "parser.rl"
+#line 480 "parser.rl"
if (json->symbolize_names && json->parsing_name) {
*result = rb_str_intern(*result);
@@ -1506,7 +1507,7 @@ case 7:
-#line 1510 "parser.c"
+#line 1511 "parser.c"
static const int JSON_start = 1;
static const int JSON_first_final = 10;
static const int JSON_error = 0;
@@ -1514,7 +1515,7 @@ static const int JSON_error = 0;
static const int JSON_en_main = 1;
-#line 516 "parser.rl"
+#line 517 "parser.rl"
/*
@@ -1696,16 +1697,16 @@ static VALUE cParser_parse(VALUE self)
GET_PARSER;
-#line 1700 "parser.c"
+#line 1701 "parser.c"
{
cs = JSON_start;
}
-#line 697 "parser.rl"
+#line 698 "parser.rl"
p = json->source;
pe = p + json->len;
-#line 1709 "parser.c"
+#line 1710 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1761,7 +1762,7 @@ case 5:
goto st1;
goto st5;
tr3:
-#line 505 "parser.rl"
+#line 506 "parser.rl"
{
char *np;
json->current_nesting = 1;
@@ -1770,7 +1771,7 @@ tr3:
}
goto st10;
tr4:
-#line 498 "parser.rl"
+#line 499 "parser.rl"
{
char *np;
json->current_nesting = 1;
@@ -1782,7 +1783,7 @@ st10:
if ( ++p == pe )
goto _test_eof10;
case 10:
-#line 1786 "parser.c"
+#line 1787 "parser.c"
switch( (*p) ) {
case 13: goto st10;
case 32: goto st10;
@@ -1839,12 +1840,13 @@ case 9:
_out: {}
}
-#line 700 "parser.rl"
+#line 701 "parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;
} else {
rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+ return Qnil;
}
}
diff --git a/ext/json/ext/parser.rl b/ext/json/ext/parser.rl
index 6e196cf..6a581ec 100644
--- a/ext/json/ext/parser.rl
+++ b/ext/json/ext/parser.rl
@@ -373,6 +373,7 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
return p + 1;
} else {
rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+ return NULL;
}
}
@@ -702,6 +703,7 @@ static VALUE cParser_parse(VALUE self)
return result;
} else {
rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+ return Qnil;
}
}