9
9
#include "unicode.h"
10
10
#include <math.h>
11
11
12
- #ifndef RHASH_TBL
13
- #define RHASH_TBL (hsh ) (RHASH(hsh)->tbl)
14
- #endif
15
-
16
12
#ifndef RHASH_SIZE
17
13
#define RHASH_SIZE (hsh ) (RHASH(hsh)->tbl->num_entries)
18
14
#endif
21
17
#define RFLOAT_VALUE (val ) (RFLOAT(val)->value)
22
18
#endif
23
19
20
+ #define option_given_p (opts , key ) RTEST(rb_funcall(opts, i_key_p, 1, key))
21
+
24
22
#ifdef HAVE_RUBY_ENCODING_H
25
23
#include "ruby/encoding.h"
26
24
#define FORCE_UTF8 (obj ) rb_enc_associate((obj), rb_utf8_encoding())
@@ -43,7 +41,7 @@ static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
43
41
44
42
static ID i_to_s , i_to_json , i_new , i_indent , i_space , i_space_before ,
45
43
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 ;
47
45
48
46
typedef struct JSON_Generator_StateStruct {
49
47
VALUE indent ;
@@ -543,15 +541,15 @@ static VALUE cState_configure(VALUE self, VALUE opts)
543
541
state -> object_nl = tmp ;
544
542
}
545
543
tmp = ID2SYM (i_check_circular );
546
- if (st_lookup ( RHASH_TBL ( opts ) , tmp , 0 )) {
544
+ if (option_given_p ( opts , tmp )) {
547
545
tmp = rb_hash_aref (opts , ID2SYM (i_check_circular ));
548
546
state -> check_circular = RTEST (tmp );
549
547
} else {
550
548
state -> check_circular = 1 ;
551
549
}
552
550
tmp = ID2SYM (i_max_nesting );
553
551
state -> max_nesting = 19 ;
554
- if (st_lookup ( RHASH_TBL ( opts ) , tmp , 0 )) {
552
+ if (option_given_p ( opts , tmp )) {
555
553
VALUE max_nesting = rb_hash_aref (opts , tmp );
556
554
if (RTEST (max_nesting )) {
557
555
Check_Type (max_nesting , T_FIXNUM );
@@ -927,6 +925,7 @@ void Init_generator()
927
925
i_unpack = rb_intern ("unpack" );
928
926
i_create_id = rb_intern ("create_id" );
929
927
i_extend = rb_intern ("extend" );
928
+ i_key_p = rb_intern ("key?" );
930
929
#ifdef HAVE_RUBY_ENCODING_H
931
930
mEncoding_UTF_8 = rb_funcall (rb_path2class ("Encoding" ), rb_intern ("find" ), 1 , rb_str_new2 ("utf-8" ));
932
931
i_encoding = rb_intern ("encoding" );
0 commit comments