diff options
author | Florian Frank <flori@ping.de> | 2010-02-27 21:03:20 +0100 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2010-02-27 21:16:56 +0100 |
commit | 92b013ce8e0a5c3caefd15f450409ed69aa539f2 (patch) | |
tree | 0ee7a7f4b19c456c0d62fc91e0447c59775cd1b3 /ext/json | |
parent | 07d7b7141eb6b11414b16521d67bdf9f316caf19 (diff) | |
download | json-92b013ce8e0a5c3caefd15f450409ed69aa539f2.tar.gz |
Improved some tests
First stab at Rubinius compatibility
Diffstat (limited to 'ext/json')
-rw-r--r-- | ext/json/ext/extconf_generator.rb | 1 | ||||
-rw-r--r-- | ext/json/ext/extconf_parser.rb | 1 | ||||
-rw-r--r-- | ext/json/ext/generator.c | 5 | ||||
-rw-r--r-- | ext/json/ext/generator.h | 12 | ||||
-rw-r--r-- | ext/json/ext/parser.c | 13 | ||||
-rw-r--r-- | ext/json/ext/parser.h | 12 | ||||
-rw-r--r-- | ext/json/ext/parser.rl | 13 |
7 files changed, 19 insertions, 38 deletions
diff --git a/ext/json/ext/extconf_generator.rb b/ext/json/ext/extconf_generator.rb index be80319..a9e8562 100644 --- a/ext/json/ext/extconf_generator.rb +++ b/ext/json/ext/extconf_generator.rb @@ -14,7 +14,6 @@ if RUBY_VERSION >= '1.9' $CFLAGS << ' -DRUBY_19' end -have_header("ruby/st.h") || have_header("st.h") have_header("ruby/re.h") || have_header("re.h") have_header("ruby/encoding.h") create_makefile 'generator' diff --git a/ext/json/ext/extconf_parser.rb b/ext/json/ext/extconf_parser.rb index 7693cfc..4da1661 100644 --- a/ext/json/ext/extconf_parser.rb +++ b/ext/json/ext/extconf_parser.rb @@ -14,6 +14,5 @@ if RUBY_VERSION >= '1.9' $CFLAGS << ' -DRUBY_19' end -have_header("ruby/st.h") || have_header("st.h") have_header("re.h") create_makefile 'parser' diff --git a/ext/json/ext/generator.c b/ext/json/ext/generator.c index 8beca18..817e426 100644 --- a/ext/json/ext/generator.c +++ b/ext/json/ext/generator.c @@ -12,7 +12,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_pack, i_unpack, i_create_id, i_extend, i_key_p; /* * Copyright 2001-2004 Unicode, Inc. @@ -675,7 +675,7 @@ static VALUE cState_configure(VALUE self, VALUE opts) } tmp = ID2SYM(i_max_nesting); state->max_nesting = 19; - if (st_lookup(RHASH_TBL(opts), tmp, 0)) { + if (option_given_p(opts, tmp)) { VALUE max_nesting = rb_hash_aref(opts, tmp); if (RTEST(max_nesting)) { Check_Type(max_nesting, T_FIXNUM); @@ -1334,6 +1334,7 @@ void Init_generator() i_unpack = rb_intern("unpack"); i_create_id = rb_intern("create_id"); i_extend = rb_intern("extend"); + i_key_p = rb_intern("key?"); #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 f4fb34b..baa02a6 100644 --- a/ext/json/ext/generator.h +++ b/ext/json/ext/generator.h @@ -7,14 +7,6 @@ #include "ruby.h" -#if HAVE_RUBY_ST_H -#include "ruby/st.h" -#endif - -#if HAVE_ST_H -#include "st.h" -#endif - #if HAVE_RUBY_RE_H #include "ruby/re.h" #endif @@ -30,9 +22,7 @@ #define FORCE_UTF8(obj) #endif -#ifndef RHASH_TBL -#define RHASH_TBL(hsh) (RHASH(hsh)->tbl) -#endif +#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key)) #ifndef RHASH_SIZE #define RHASH_SIZE(hsh) (RHASH(hsh)->tbl->num_entries) diff --git a/ext/json/ext/parser.c b/ext/json/ext/parser.c index 0122571..72c39cc 100644 --- a/ext/json/ext/parser.c +++ b/ext/json/ext/parser.c @@ -79,7 +79,7 @@ static VALUE mJSON, mExt, cParser, eParserError, eNestingError; static VALUE CNaN, CInfinity, CMinusInfinity; static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions, - i_chr, i_max_nesting, i_allow_nan, i_object_class, i_array_class; + i_chr, i_max_nesting, i_allow_nan, i_object_class, i_array_class, i_key_p; #line 108 "parser.rl" @@ -1611,7 +1611,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) rb_raise(rb_eArgError, "opts needs to be like a hash"); } else { VALUE tmp = ID2SYM(i_max_nesting); - if (st_lookup(RHASH_TBL(opts), tmp, 0)) { + if (option_given_p(opts, tmp)) { VALUE max_nesting = rb_hash_aref(opts, tmp); if (RTEST(max_nesting)) { Check_Type(max_nesting, T_FIXNUM); @@ -1623,14 +1623,14 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) json->max_nesting = 19; } tmp = ID2SYM(i_allow_nan); - if (st_lookup(RHASH_TBL(opts), tmp, 0)) { + if (option_given_p(opts, tmp)) { VALUE allow_nan = rb_hash_aref(opts, tmp); json->allow_nan = RTEST(allow_nan) ? 1 : 0; } else { json->allow_nan = 0; } tmp = ID2SYM(i_create_additions); - if (st_lookup(RHASH_TBL(opts), tmp, 0)) { + if (option_given_p(opts, tmp)) { VALUE create_additions = rb_hash_aref(opts, tmp); if (RTEST(create_additions)) { json->create_id = rb_funcall(mJSON, i_create_id, 0); @@ -1641,13 +1641,13 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) json->create_id = rb_funcall(mJSON, i_create_id, 0); } tmp = ID2SYM(i_object_class); - if (st_lookup(RHASH_TBL(opts), tmp, 0)) { + if (option_given_p(opts, tmp)) { json->object_class = rb_hash_aref(opts, tmp); } else { json->object_class = Qnil; } tmp = ID2SYM(i_array_class); - if (st_lookup(RHASH_TBL(opts), tmp, 0)) { + if (option_given_p(opts, tmp)) { json->array_class = rb_hash_aref(opts, tmp); } else { json->array_class = Qnil; @@ -1897,6 +1897,7 @@ void Init_parser() i_allow_nan = rb_intern("allow_nan"); i_object_class = rb_intern("object_class"); i_array_class = rb_intern("array_class"); + i_key_p = rb_intern("key?"); #ifdef HAVE_RUBY_ENCODING_H CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8")); CEncoding_UTF_16BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16be")); diff --git a/ext/json/ext/parser.h b/ext/json/ext/parser.h index 5f2506d..3982af2 100644 --- a/ext/json/ext/parser.h +++ b/ext/json/ext/parser.h @@ -7,14 +7,6 @@ #include "re.h" #endif -#if HAVE_RUBY_ST_H -#include "ruby/st.h" -#endif - -#if HAVE_ST_H -#include "st.h" -#endif - #ifdef HAVE_RUBY_ENCODING_H #include "ruby/encoding.h" #define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding()) @@ -22,9 +14,7 @@ #define FORCE_UTF8(obj) #endif -#ifndef RHASH_TBL -#define RHASH_TBL(hsh) (RHASH(hsh)->tbl) -#endif +#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key)) /* unicode */ diff --git a/ext/json/ext/parser.rl b/ext/json/ext/parser.rl index b91ac00..f09c66d 100644 --- a/ext/json/ext/parser.rl +++ b/ext/json/ext/parser.rl @@ -77,7 +77,7 @@ static VALUE mJSON, mExt, cParser, eParserError, eNestingError; static VALUE CNaN, CInfinity, CMinusInfinity; static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions, - i_chr, i_max_nesting, i_allow_nan, i_object_class, i_array_class; + i_chr, i_max_nesting, i_allow_nan, i_object_class, i_array_class, i_key_p; %%{ machine JSON_common; @@ -609,7 +609,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) rb_raise(rb_eArgError, "opts needs to be like a hash"); } else { VALUE tmp = ID2SYM(i_max_nesting); - if (st_lookup(RHASH_TBL(opts), tmp, 0)) { + if (option_given_p(opts, tmp)) { VALUE max_nesting = rb_hash_aref(opts, tmp); if (RTEST(max_nesting)) { Check_Type(max_nesting, T_FIXNUM); @@ -621,14 +621,14 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) json->max_nesting = 19; } tmp = ID2SYM(i_allow_nan); - if (st_lookup(RHASH_TBL(opts), tmp, 0)) { + if (option_given_p(opts, tmp)) { VALUE allow_nan = rb_hash_aref(opts, tmp); json->allow_nan = RTEST(allow_nan) ? 1 : 0; } else { json->allow_nan = 0; } tmp = ID2SYM(i_create_additions); - if (st_lookup(RHASH_TBL(opts), tmp, 0)) { + if (option_given_p(opts, tmp)) { VALUE create_additions = rb_hash_aref(opts, tmp); if (RTEST(create_additions)) { json->create_id = rb_funcall(mJSON, i_create_id, 0); @@ -639,13 +639,13 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) json->create_id = rb_funcall(mJSON, i_create_id, 0); } tmp = ID2SYM(i_object_class); - if (st_lookup(RHASH_TBL(opts), tmp, 0)) { + if (option_given_p(opts, tmp)) { json->object_class = rb_hash_aref(opts, tmp); } else { json->object_class = Qnil; } tmp = ID2SYM(i_array_class); - if (st_lookup(RHASH_TBL(opts), tmp, 0)) { + if (option_given_p(opts, tmp)) { json->array_class = rb_hash_aref(opts, tmp); } else { json->array_class = Qnil; @@ -754,6 +754,7 @@ void Init_parser() i_allow_nan = rb_intern("allow_nan"); i_object_class = rb_intern("object_class"); i_array_class = rb_intern("array_class"); + i_key_p = rb_intern("key?"); #ifdef HAVE_RUBY_ENCODING_H CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8")); CEncoding_UTF_16BE = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-16be")); |