99#include "unicode.h"
1010#include <math.h>
1111
12- #ifndef RHASH_TBL
13- #define RHASH_TBL (hsh ) (RHASH(hsh)->tbl)
14- #endif
15-
1612#ifndef RHASH_SIZE
1713#define RHASH_SIZE (hsh ) (RHASH(hsh)->tbl->num_entries)
1814#endif
2117#define RFLOAT_VALUE (val ) (RFLOAT(val)->value)
2218#endif
2319
20+ #define option_given_p (opts , key ) RTEST(rb_funcall(opts, i_key_p, 1, key))
21+
2422#ifdef HAVE_RUBY_ENCODING_H
2523#include "ruby/encoding.h"
2624#define FORCE_UTF8 (obj ) rb_enc_associate((obj), rb_utf8_encoding())
@@ -43,7 +41,7 @@ static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
4341
4442static ID i_to_s , i_to_json , i_new , i_indent , i_space , i_space_before ,
4543 i_object_nl , i_array_nl , i_check_circular , i_max_nesting ,
46- i_allow_nan , i_pack , i_unpack , i_create_id , i_extend ;
44+ i_allow_nan , i_pack , i_unpack , i_create_id , i_extend , i_key_p ;
4745
4846typedef struct JSON_Generator_StateStruct {
4947 VALUE indent ;
@@ -543,15 +541,15 @@ static VALUE cState_configure(VALUE self, VALUE opts)
543541 state -> object_nl = tmp ;
544542 }
545543 tmp = ID2SYM (i_check_circular );
546- if (st_lookup ( RHASH_TBL ( opts ) , tmp , 0 )) {
544+ if (option_given_p ( opts , tmp )) {
547545 tmp = rb_hash_aref (opts , ID2SYM (i_check_circular ));
548546 state -> check_circular = RTEST (tmp );
549547 } else {
550548 state -> check_circular = 1 ;
551549 }
552550 tmp = ID2SYM (i_max_nesting );
553551 state -> max_nesting = 19 ;
554- if (st_lookup ( RHASH_TBL ( opts ) , tmp , 0 )) {
552+ if (option_given_p ( opts , tmp )) {
555553 VALUE max_nesting = rb_hash_aref (opts , tmp );
556554 if (RTEST (max_nesting )) {
557555 Check_Type (max_nesting , T_FIXNUM );
@@ -927,6 +925,7 @@ void Init_generator()
927925 i_unpack = rb_intern ("unpack" );
928926 i_create_id = rb_intern ("create_id" );
929927 i_extend = rb_intern ("extend" );
928+ i_key_p = rb_intern ("key?" );
930929#ifdef HAVE_RUBY_ENCODING_H
931930 mEncoding_UTF_8 = rb_funcall (rb_path2class ("Encoding" ), rb_intern ("find" ), 1 , rb_str_new2 ("utf-8" ));
932931 i_encoding = rb_intern ("encoding" );
0 commit comments