summaryrefslogtreecommitdiff
path: root/ext/json/parser
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-27 11:12:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-27 11:12:58 +0000
commitd29ff247936236673cf117cff558f55c787750a8 (patch)
treea411d51ef37a52160c5deff7220a99ba0147fd6c /ext/json/parser
parent81e9d9799a0911058157404c1976f00598fc7b6a (diff)
json: backward compatibilities
* ext/json/generator/generator.c (JSON_Generator_State_type): add #ifdef for backward compatibility. * ext/json/parser/parser.rl (JSON_Parser_type): ditto. * ext/json/generator/generator.h (ZALLOC): add fallback definition. * ext/json/parser/parser.h (ZALLOC): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49038 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/json/parser')
-rw-r--r--ext/json/parser/parser.c5
-rw-r--r--ext/json/parser/parser.h10
-rw-r--r--ext/json/parser/parser.rl5
3 files changed, 16 insertions, 4 deletions
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c
index f9d0d193b6..b9f753c56d 100644
--- a/ext/json/parser/parser.c
+++ b/ext/json/parser/parser.c
@@ -2094,8 +2094,7 @@ static VALUE cParser_parse(VALUE self)
static JSON_Parser *JSON_allocate(void)
{
- JSON_Parser *json = ALLOC(JSON_Parser);
- MEMZERO(json, JSON_Parser, 1);
+ JSON_Parser *json = ZALLOC(JSON_Parser);
json->fbuffer = fbuffer_alloc(0);
return json;
}
@@ -2126,8 +2125,10 @@ static size_t JSON_memsize(const void *ptr)
static const rb_data_type_t JSON_Parser_type = {
"JSON/Parser",
{JSON_mark, JSON_free, JSON_memsize,},
+#ifdef RUBY_TYPED_FREE_IMMEDIATELY
0, 0,
RUBY_TYPED_FREE_IMMEDIATELY,
+#endif
};
static VALUE cJSON_parser_s_allocate(VALUE klass)
diff --git a/ext/json/parser/parser.h b/ext/json/parser/parser.h
index 45afbc2732..980999a6d7 100644
--- a/ext/json/parser/parser.h
+++ b/ext/json/parser/parser.h
@@ -75,4 +75,14 @@ static VALUE cJSON_parser_s_allocate(VALUE klass);
static VALUE cParser_source(VALUE self);
static const rb_data_type_t JSON_Parser_type;
+#ifndef ZALLOC
+#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
+static inline void *ruby_zalloc(size_t n)
+{
+ void *p = ruby_xmalloc(n);
+ memset(p, 0, n);
+ return p;
+}
+#endif
+
#endif
diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl
index 3d7b5a65fb..0b6fb041c5 100644
--- a/ext/json/parser/parser.rl
+++ b/ext/json/parser/parser.rl
@@ -817,8 +817,7 @@ static VALUE cParser_parse(VALUE self)
static JSON_Parser *JSON_allocate(void)
{
- JSON_Parser *json = ALLOC(JSON_Parser);
- MEMZERO(json, JSON_Parser, 1);
+ JSON_Parser *json = ZALLOC(JSON_Parser);
json->fbuffer = fbuffer_alloc(0);
return json;
}
@@ -849,8 +848,10 @@ static size_t JSON_memsize(const void *ptr)
static const rb_data_type_t JSON_Parser_type = {
"JSON/Parser",
{JSON_mark, JSON_free, JSON_memsize,},
+#ifdef RUBY_TYPED_FREE_IMMEDIATELY
0, 0,
RUBY_TYPED_FREE_IMMEDIATELY,
+#endif
};
static VALUE cJSON_parser_s_allocate(VALUE klass)