Skip to content

Commit

Permalink
Merge branch 'rbx-fix'
Browse files Browse the repository at this point in the history
Supports rubinius now. Avoided depending on MRI internals too much.
  • Loading branch information
flori committed Apr 23, 2010
2 parents 927b2ba + ca292f9 commit a8812e9
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 88 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -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}"]
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/generator2_benchmark.rb
Expand Up @@ -66,7 +66,7 @@ class Generator2BenchmarkExt < Bullshit::RepeatCase
include JSONGeneratorCommon

warmup yes
iterations 500
iterations 2000

truncate_data do
enabled false
Expand All @@ -92,7 +92,7 @@ class Generator2BenchmarkPure < Bullshit::RepeatCase
include JSONGeneratorCommon

warmup yes
iterations 100
iterations 400

truncate_data do
enabled false
Expand All @@ -117,7 +117,7 @@ class Generator2BenchmarkRails < Bullshit::RepeatCase
include Generator2BenchmarkCommon

warmup yes
iterations 100
iterations 400

truncate_data do
enabled false
Expand Down Expand Up @@ -148,7 +148,7 @@ class Generator2BenchmarkYajl < Bullshit::RepeatCase
include Generator2BenchmarkCommon

warmup yes
iterations 500
iterations 2000

truncate_data do
enabled false
Expand Down
8 changes: 4 additions & 4 deletions benchmarks/generator_benchmark.rb
Expand Up @@ -68,7 +68,7 @@ class GeneratorBenchmarkExt < Bullshit::RepeatCase
include JSONGeneratorCommon

warmup yes
iterations 500
iterations 2000

truncate_data do
enabled false
Expand All @@ -94,7 +94,7 @@ class GeneratorBenchmarkPure < Bullshit::RepeatCase
include JSONGeneratorCommon

warmup yes
iterations 100
iterations 400

truncate_data do
enabled false
Expand All @@ -119,7 +119,7 @@ class GeneratorBenchmarkRails < Bullshit::RepeatCase
include GeneratorBenchmarkCommon

warmup yes
iterations 100
iterations 400

truncate_data do
enabled false
Expand Down Expand Up @@ -150,7 +150,7 @@ class GeneratorBenchmarkYajl < Bullshit::RepeatCase
include GeneratorBenchmarkCommon

warmup yes
iterations 500
iterations 2000

truncate_data do
enabled false
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/parser_benchmark.rb
Expand Up @@ -41,7 +41,7 @@ class ParserBenchmarkExt < Bullshit::RepeatCase
include ParserBenchmarkCommon

warmup yes
iterations 500
iterations 2000

truncate_data do
enabled false
Expand Down Expand Up @@ -78,7 +78,7 @@ class ParserBenchmarkPure < Bullshit::RepeatCase
include ParserBenchmarkCommon

warmup yes
iterations 100
iterations 400

truncate_data do
enabled false
Expand Down Expand Up @@ -113,7 +113,7 @@ def benchmark_parser_symbolic

class ParserBenchmarkYAML < Bullshit::RepeatCase
warmup yes
iterations 100
iterations 400

truncate_data do
enabled false
Expand Down Expand Up @@ -150,7 +150,7 @@ def generic_reset_method

class ParserBenchmarkRails < Bullshit::RepeatCase
warmup yes
iterations 100
iterations 400

truncate_data do
enabled false
Expand Down Expand Up @@ -187,7 +187,7 @@ def generic_reset_method

class ParserBenchmarkYajl < Bullshit::RepeatCase
warmup yes
iterations 500
iterations 2000

truncate_data do
enabled false
Expand Down
3 changes: 0 additions & 3 deletions ext/json/ext/extconf_generator.rb
Expand Up @@ -10,9 +10,6 @@
# $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")
Expand Down
3 changes: 0 additions & 3 deletions ext/json/ext/extconf_parser.rb
Expand Up @@ -10,9 +10,6 @@
# $CFLAGS << ' -O0 -ggdb'
#end
end
if RUBY_VERSION >= '1.9'
$CFLAGS << ' -DRUBY_19'
end

have_header("re.h")
create_makefile 'parser'
54 changes: 5 additions & 49 deletions ext/json/ext/generator.c
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
1 change: 0 additions & 1 deletion ext/json/ext/generator.h
Expand Up @@ -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);
Expand Down

0 comments on commit a8812e9

Please sign in to comment.