Skip to content

Commit 05ba45c

Browse files
committed
Fall back to Data_* wrappers on ancient rubies
1 parent 0a7c982 commit 05ba45c

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

ext/json/ext/generator/generator.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ static size_t State_memsize(const void *ptr)
515515
return size;
516516
}
517517

518+
#ifdef NEW_TYPEDDATA_WRAPPER
518519
static const rb_data_type_t JSON_Generator_State_type = {
519520
"JSON/Generator/State",
520521
{NULL, State_free, State_memsize,},
@@ -523,6 +524,7 @@ static const rb_data_type_t JSON_Generator_State_type = {
523524
RUBY_TYPED_FREE_IMMEDIATELY,
524525
#endif
525526
};
527+
#endif
526528

527529
static JSON_Generator_State *State_allocate(void)
528530
{

ext/json/ext/generator/generator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ static VALUE cState_ascii_only_p(VALUE self);
147147
static VALUE cState_depth(VALUE self);
148148
static VALUE cState_depth_set(VALUE self, VALUE depth);
149149
static FBuffer *cState_prepare_buffer(VALUE self);
150+
#ifdef TypedData_Wrap_Struct
150151
static const rb_data_type_t JSON_Generator_State_type;
152+
#define NEW_TYPEDDATA_WRAPPER 1
153+
#else
154+
#define TypedData_Wrap_Struct(klass, ignore, json) Data_Wrap_Struct(klass, NULL, State_free, json)
155+
#define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json)
156+
#endif
151157

152158
#endif

ext/json/ext/parser/parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,7 @@ static size_t JSON_memsize(const void *ptr)
21232123
return sizeof(*json) + FBUFFER_CAPA(json->fbuffer);
21242124
}
21252125

2126+
#ifdef NEW_TYPEDDATA_WRAPPER
21262127
static const rb_data_type_t JSON_Parser_type = {
21272128
"JSON/Parser",
21282129
{JSON_mark, JSON_free, JSON_memsize,},
@@ -2131,6 +2132,7 @@ static const rb_data_type_t JSON_Parser_type = {
21312132
RUBY_TYPED_FREE_IMMEDIATELY,
21322133
#endif
21332134
};
2135+
#endif
21342136

21352137
static VALUE cJSON_parser_s_allocate(VALUE klass)
21362138
{

ext/json/ext/parser/parser.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ static void JSON_mark(void *json);
7373
static void JSON_free(void *json);
7474
static VALUE cJSON_parser_s_allocate(VALUE klass);
7575
static VALUE cParser_source(VALUE self);
76+
#ifdef TypedData_Wrap_Struct
7677
static const rb_data_type_t JSON_Parser_type;
78+
#define NEW_TYPEDDATA_WRAPPER 1
79+
#else
80+
#define TypedData_Wrap_Struct(klass, ignore, json) Data_Wrap_Struct(klass, JSON_mark, JSON_free, json)
81+
#define TypedData_Get_Struct(self, JSON_Parser, ignore, json) Data_Get_Struct(self, JSON_Parser, json)
82+
#endif
7783

7884
#endif

ext/json/ext/parser/parser.rl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ static VALUE convert_encoding(VALUE source)
611611
* the default.
612612
* * *create_additions*: If set to false, the Parser doesn't create
613613
* additions even if a matching class and create_id was found. This option
614-
* defaults to true.
614+
* defaults to false.
615615
* * *object_class*: Defaults to Hash
616616
* * *array_class*: Defaults to Array
617617
*/
@@ -846,6 +846,7 @@ static size_t JSON_memsize(const void *ptr)
846846
return sizeof(*json) + FBUFFER_CAPA(json->fbuffer);
847847
}
848848

849+
#ifdef NEW_TYPEDDATA_WRAPPER
849850
static const rb_data_type_t JSON_Parser_type = {
850851
"JSON/Parser",
851852
{JSON_mark, JSON_free, JSON_memsize,},
@@ -854,6 +855,7 @@ static const rb_data_type_t JSON_Parser_type = {
854855
RUBY_TYPED_FREE_IMMEDIATELY,
855856
#endif
856857
};
858+
#endif
857859

858860
static VALUE cJSON_parser_s_allocate(VALUE klass)
859861
{

0 commit comments

Comments
 (0)