16 #define rb_intern_str(string) SYM2ID(rb_str_intern(string))
19 #ifndef rb_obj_instance_variables
20 #define rb_obj_instance_variables(object) rb_funcall(object, rb_intern("instance_variables"), 0)
23 #define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
27 #define UNI_STRICT_CONVERSION 1
31 typedef unsigned char UTF8;
33 #define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
34 #define UNI_MAX_BMP (UTF32)0x0000FFFF
35 #define UNI_MAX_UTF16 (UTF32)0x0010FFFF
36 #define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
37 #define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
39 #define UNI_SUR_HIGH_START (UTF32)0xD800
40 #define UNI_SUR_HIGH_END (UTF32)0xDBFF
41 #define UNI_SUR_LOW_START (UTF32)0xDC00
42 #define UNI_SUR_LOW_END (UTF32)0xDFFF
44 static const int halfShift = 10;
46 static const UTF32 halfBase = 0x0010000UL;
47 static const UTF32 halfMask = 0x3FFUL;
49 static unsigned char isLegalUTF8(
const UTF8 *source,
unsigned long length);
50 static void unicode_escape(
char *
buf,
UTF16 character);
54 static char *fstrndup(
const char *
ptr,
unsigned long len);
79 #define GET_STATE_TO(self, state) \
80 TypedData_Get_Struct(self, JSON_Generator_State, &JSON_Generator_State_type, state)
82 #define GET_STATE(self) \
83 JSON_Generator_State *state; \
84 GET_STATE_TO(self, state)
86 #define GENERATE_JSON(type) \
89 JSON_Generator_State *state; \
91 rb_scan_args(argc, argv, "01", &Vstate); \
92 Vstate = cState_from_state_s(cState, Vstate); \
93 TypedData_Get_Struct(Vstate, JSON_Generator_State, &JSON_Generator_State_type, state); \
94 buffer = cState_prepare_buffer(Vstate); \
95 generate_json_##type(buffer, Vstate, state, self); \
96 return fbuffer_to_s(buffer)
100 #ifdef RUBY_INTEGER_UNIFICATION
109 static VALUE mString_to_json_raw_object(
VALUE self);
116 static void State_free(
void *state);
127 #ifdef RUBY_INTEGER_UNIFICATION
155 #define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
156 static inline void *ruby_zalloc(
size_t n)
163 #ifdef TypedData_Make_Struct
165 #define NEW_TYPEDDATA_WRAPPER 1
167 #define TypedData_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, State_free, json)
168 #define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json)