summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/json/parser/parser.c14
-rw-r--r--ext/json/parser/parser.h5
-rw-r--r--ext/json/parser/parser.rl14
3 files changed, 10 insertions, 23 deletions
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c
index f3ede6ffe8..ae9be78ec2 100644
--- a/ext/json/parser/parser.c
+++ b/ext/json/parser/parser.c
@@ -2110,14 +2110,6 @@ static VALUE cParser_parse(VALUE self)
}
}
-
-static JSON_Parser *JSON_allocate(void)
-{
- JSON_Parser *json = ZALLOC(JSON_Parser);
- json->fbuffer = fbuffer_alloc(0);
- return json;
-}
-
static void JSON_mark(void *ptr)
{
JSON_Parser *json = ptr;
@@ -2154,8 +2146,10 @@ static const rb_data_type_t JSON_Parser_type = {
static VALUE cJSON_parser_s_allocate(VALUE klass)
{
- JSON_Parser *json = JSON_allocate();
- return TypedData_Wrap_Struct(klass, &JSON_Parser_type, json);
+ JSON_Parser *json;
+ VALUE obj = TypedData_Make_Struct(klass, JSON_Parser, &JSON_Parser_type, json);
+ json->fbuffer = fbuffer_alloc(0);
+ return obj;
}
/*
diff --git a/ext/json/parser/parser.h b/ext/json/parser/parser.h
index e98f26a297..abcc2571f1 100644
--- a/ext/json/parser/parser.h
+++ b/ext/json/parser/parser.h
@@ -68,7 +68,6 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
static VALUE convert_encoding(VALUE source);
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self);
static VALUE cParser_parse(VALUE self);
-static JSON_Parser *JSON_allocate(void);
static void JSON_mark(void *json);
static void JSON_free(void *json);
static VALUE cJSON_parser_s_allocate(VALUE klass);
@@ -82,11 +81,11 @@ static inline void *ruby_zalloc(size_t n)
return p;
}
#endif
-#ifdef TypedData_Wrap_Struct
+#ifdef TypedData_Make_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_Make_Struct(klass, type, ignore, json) Data_Make_Struct(klass, type, NULL, JSON_free, json)
#define TypedData_Get_Struct(self, JSON_Parser, ignore, json) Data_Get_Struct(self, JSON_Parser, json)
#endif
diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl
index 0516aff9e7..327e08cd81 100644
--- a/ext/json/parser/parser.rl
+++ b/ext/json/parser/parser.rl
@@ -833,14 +833,6 @@ static VALUE cParser_parse(VALUE self)
}
}
-
-static JSON_Parser *JSON_allocate(void)
-{
- JSON_Parser *json = ZALLOC(JSON_Parser);
- json->fbuffer = fbuffer_alloc(0);
- return json;
-}
-
static void JSON_mark(void *ptr)
{
JSON_Parser *json = ptr;
@@ -877,8 +869,10 @@ static const rb_data_type_t JSON_Parser_type = {
static VALUE cJSON_parser_s_allocate(VALUE klass)
{
- JSON_Parser *json = JSON_allocate();
- return TypedData_Wrap_Struct(klass, &JSON_Parser_type, json);
+ JSON_Parser *json;
+ VALUE obj = TypedData_Make_Struct(klass, JSON_Parser, &JSON_Parser_type, json);
+ json->fbuffer = fbuffer_alloc(0);
+ return obj;
}
/*