From 05ba45c2d46c8ff4807613b60b204f85a7720997 Mon Sep 17 00:00:00 2001 From: Florian Frank Date: Fri, 2 Jan 2015 23:22:09 +0100 Subject: Fall back to Data_* wrappers on ancient rubies --- ext/json/ext/generator/generator.c | 2 ++ ext/json/ext/generator/generator.h | 6 ++++++ ext/json/ext/parser/parser.c | 2 ++ ext/json/ext/parser/parser.h | 6 ++++++ ext/json/ext/parser/parser.rl | 4 +++- 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ext/json/ext/generator/generator.c b/ext/json/ext/generator/generator.c index f789a89..a474fbb 100644 --- a/ext/json/ext/generator/generator.c +++ b/ext/json/ext/generator/generator.c @@ -515,6 +515,7 @@ static size_t State_memsize(const void *ptr) return size; } +#ifdef NEW_TYPEDDATA_WRAPPER static const rb_data_type_t JSON_Generator_State_type = { "JSON/Generator/State", {NULL, State_free, State_memsize,}, @@ -523,6 +524,7 @@ static const rb_data_type_t JSON_Generator_State_type = { RUBY_TYPED_FREE_IMMEDIATELY, #endif }; +#endif static JSON_Generator_State *State_allocate(void) { diff --git a/ext/json/ext/generator/generator.h b/ext/json/ext/generator/generator.h index 7bf8408..02193f0 100644 --- a/ext/json/ext/generator/generator.h +++ b/ext/json/ext/generator/generator.h @@ -147,6 +147,12 @@ static VALUE cState_ascii_only_p(VALUE self); static VALUE cState_depth(VALUE self); static VALUE cState_depth_set(VALUE self, VALUE depth); static FBuffer *cState_prepare_buffer(VALUE self); +#ifdef TypedData_Wrap_Struct static const rb_data_type_t JSON_Generator_State_type; +#define NEW_TYPEDDATA_WRAPPER 1 +#else +#define TypedData_Wrap_Struct(klass, ignore, json) Data_Wrap_Struct(klass, NULL, State_free, json) +#define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json) +#endif #endif diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index efb4dac..8824b30 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -2123,6 +2123,7 @@ static size_t JSON_memsize(const void *ptr) return sizeof(*json) + FBUFFER_CAPA(json->fbuffer); } +#ifdef NEW_TYPEDDATA_WRAPPER static const rb_data_type_t JSON_Parser_type = { "JSON/Parser", {JSON_mark, JSON_free, JSON_memsize,}, @@ -2131,6 +2132,7 @@ static const rb_data_type_t JSON_Parser_type = { RUBY_TYPED_FREE_IMMEDIATELY, #endif }; +#endif static VALUE cJSON_parser_s_allocate(VALUE klass) { diff --git a/ext/json/ext/parser/parser.h b/ext/json/ext/parser/parser.h index 45afbc2..418637f 100644 --- a/ext/json/ext/parser/parser.h +++ b/ext/json/ext/parser/parser.h @@ -73,6 +73,12 @@ static void JSON_mark(void *json); static void JSON_free(void *json); static VALUE cJSON_parser_s_allocate(VALUE klass); static VALUE cParser_source(VALUE self); +#ifdef TypedData_Wrap_Struct static const rb_data_type_t JSON_Parser_type; +#define NEW_TYPEDDATA_WRAPPER 1 +#else +#define TypedData_Wrap_Struct(klass, ignore, json) Data_Wrap_Struct(klass, JSON_mark, JSON_free, json) +#define TypedData_Get_Struct(self, JSON_Parser, ignore, json) Data_Get_Struct(self, JSON_Parser, json) +#endif #endif diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl index d3ba554..2af1cc6 100644 --- a/ext/json/ext/parser/parser.rl +++ b/ext/json/ext/parser/parser.rl @@ -611,7 +611,7 @@ static VALUE convert_encoding(VALUE source) * the default. * * *create_additions*: If set to false, the Parser doesn't create * additions even if a matching class and create_id was found. This option - * defaults to true. + * defaults to false. * * *object_class*: Defaults to Hash * * *array_class*: Defaults to Array */ @@ -846,6 +846,7 @@ static size_t JSON_memsize(const void *ptr) return sizeof(*json) + FBUFFER_CAPA(json->fbuffer); } +#ifdef NEW_TYPEDDATA_WRAPPER static const rb_data_type_t JSON_Parser_type = { "JSON/Parser", {JSON_mark, JSON_free, JSON_memsize,}, @@ -854,6 +855,7 @@ static const rb_data_type_t JSON_Parser_type = { RUBY_TYPED_FREE_IMMEDIATELY, #endif }; +#endif static VALUE cJSON_parser_s_allocate(VALUE klass) { -- cgit v1.2.1