summaryrefslogtreecommitdiff
path: root/ext/json
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-13 05:19:12 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-13 05:19:12 +0000
commitf5219fee6307461c7ead4358290958679d9d0d38 (patch)
treef54cbc4f820ffb7394b1e631ffd78465a0743321 /ext/json
parent4607f95f7380f3eeef16230a7d55e07dc4c9f6cc (diff)
* ext/json: merge upstream from flori/json
change usage of TypedData. [Feature #10739][ruby-core:67564] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/json')
-rw-r--r--ext/json/generator/generator.c6
-rw-r--r--ext/json/generator/generator.h18
-rw-r--r--ext/json/parser/parser.c6
-rw-r--r--ext/json/parser/parser.h17
-rw-r--r--ext/json/parser/parser.rl6
5 files changed, 18 insertions, 35 deletions
diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c
index 9641ecb..baf5360 100644
--- a/ext/json/generator/generator.c
+++ b/ext/json/generator/generator.c
@@ -515,7 +515,7 @@ static size_t State_memsize(const void *ptr)
return size;
}
-#ifdef HAVE_TYPE_RB_DATA_TYPE_T
+#ifdef NEW_TYPEDDATA_WRAPPER
static const rb_data_type_t JSON_Generator_State_type = {
"JSON/Generator/State",
{NULL, State_free, State_memsize,},
@@ -535,11 +535,7 @@ static JSON_Generator_State *State_allocate(void)
static VALUE cState_s_allocate(VALUE klass)
{
JSON_Generator_State *state = State_allocate();
-#ifdef HAVE_TYPE_RB_DATA_TYPE_T
return TypedData_Wrap_Struct(klass, &JSON_Generator_State_type, state);
-#else
- return Data_Wrap_Struct(klass, NULL, State_free, state);
-#endif
}
/*
diff --git a/ext/json/generator/generator.h b/ext/json/generator/generator.h
index b2d2f0a..416159a 100644
--- a/ext/json/generator/generator.h
+++ b/ext/json/generator/generator.h
@@ -78,13 +78,8 @@ typedef struct JSON_Generator_StateStruct {
long buffer_initial_length;
} JSON_Generator_State;
-#ifdef HAVE_TYPE_RB_DATA_TYPE_T
#define GET_STATE_TO(self, state) \
TypedData_Get_Struct(self, JSON_Generator_State, &JSON_Generator_State_type, state)
-#else
-#define GET_STATE_TO(self, state) \
- Data_Get_Struct(self, JSON_Generator_State, state)
-#endif
#define GET_STATE(self) \
JSON_Generator_State *state; \
@@ -97,7 +92,7 @@ typedef struct JSON_Generator_StateStruct {
\
rb_scan_args(argc, argv, "01", &Vstate); \
Vstate = cState_from_state_s(cState, Vstate); \
- GET_STATE_TO(Vstate, state); \
+ TypedData_Get_Struct(Vstate, JSON_Generator_State, &JSON_Generator_State_type, state); \
buffer = cState_prepare_buffer(Vstate); \
generate_json_##type(buffer, Vstate, state, self); \
return fbuffer_to_s(buffer)
@@ -152,10 +147,6 @@ 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 HAVE_TYPE_RB_DATA_TYPE_T
-static const rb_data_type_t JSON_Generator_State_type;
-#endif
-
#ifndef ZALLOC
#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
static inline void *ruby_zalloc(size_t n)
@@ -165,5 +156,12 @@ static inline void *ruby_zalloc(size_t n)
return p;
}
#endif
+#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/parser/parser.c b/ext/json/parser/parser.c
index f4617aa..eed58e5 100644
--- a/ext/json/parser/parser.c
+++ b/ext/json/parser/parser.c
@@ -2122,7 +2122,7 @@ static size_t JSON_memsize(const void *ptr)
return sizeof(*json) + FBUFFER_CAPA(json->fbuffer);
}
-#ifdef HAVE_TYPE_RB_DATA_TYPE_T
+#ifdef NEW_TYPEDDATA_WRAPPER
static const rb_data_type_t JSON_Parser_type = {
"JSON/Parser",
{JSON_mark, JSON_free, JSON_memsize,},
@@ -2136,11 +2136,7 @@ static const rb_data_type_t JSON_Parser_type = {
static VALUE cJSON_parser_s_allocate(VALUE klass)
{
JSON_Parser *json = JSON_allocate();
-#ifdef HAVE_TYPE_RB_DATA_TYPE_T
return TypedData_Wrap_Struct(klass, &JSON_Parser_type, json);
-#else
- return Data_Wrap_Struct(klass, JSON_mark, JSON_free, json);
-#endif
}
/*
diff --git a/ext/json/parser/parser.h b/ext/json/parser/parser.h
index 394b79a..e98f26a 100644
--- a/ext/json/parser/parser.h
+++ b/ext/json/parser/parser.h
@@ -49,15 +49,9 @@ typedef struct JSON_ParserStruct {
#define GET_PARSER \
GET_PARSER_INIT; \
if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance")
-#ifdef HAVE_TYPE_RB_DATA_TYPE_T
#define GET_PARSER_INIT \
JSON_Parser *json; \
TypedData_Get_Struct(self, JSON_Parser, &JSON_Parser_type, json)
-#else
-#define GET_PARSER_INIT \
- JSON_Parser *json; \
- Data_Get_Struct(self, JSON_Parser, json)
-#endif
#define MinusInfinity "-Infinity"
#define EVIL 0x666
@@ -79,10 +73,6 @@ 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 HAVE_TYPE_RB_DATA_TYPE_T
-static const rb_data_type_t JSON_Parser_type;
-#endif
-
#ifndef ZALLOC
#define ZALLOC(type) ((type *)ruby_zalloc(sizeof(type)))
static inline void *ruby_zalloc(size_t n)
@@ -92,5 +82,12 @@ static inline void *ruby_zalloc(size_t n)
return p;
}
#endif
+#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/parser/parser.rl b/ext/json/parser/parser.rl
index e29f46d..b9b51aa 100644
--- a/ext/json/parser/parser.rl
+++ b/ext/json/parser/parser.rl
@@ -845,7 +845,7 @@ static size_t JSON_memsize(const void *ptr)
return sizeof(*json) + FBUFFER_CAPA(json->fbuffer);
}
-#ifdef HAVE_TYPE_RB_DATA_TYPE_T
+#ifdef NEW_TYPEDDATA_WRAPPER
static const rb_data_type_t JSON_Parser_type = {
"JSON/Parser",
{JSON_mark, JSON_free, JSON_memsize,},
@@ -859,11 +859,7 @@ static const rb_data_type_t JSON_Parser_type = {
static VALUE cJSON_parser_s_allocate(VALUE klass)
{
JSON_Parser *json = JSON_allocate();
-#ifdef HAVE_TYPE_RB_DATA_TYPE_T
return TypedData_Wrap_Struct(klass, &JSON_Parser_type, json);
-#else
- return Data_Wrap_Struct(klass, JSON_mark, JSON_free, json);
-#endif
}
/*