Skip to content

Commit 9656252

Browse files
authored
Merge pull request #87 from nobu/typed-data
Use typed data APIs
2 parents beb0c7f + c95152c commit 9656252

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

ext/ruby_http_parser/ext_help.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
#define ext_help_h
33

44
#define RAISE_NOT_NULL(T) if(T == NULL) rb_raise(rb_eArgError, "NULL found for " # T " when shouldn't be.");
5-
#define DATA_GET(from,type,name) Data_Get_Struct(from,type,name); RAISE_NOT_NULL(name);
5+
#ifdef TypedData_Get_Struct
6+
#define DATA_GET_STRUCT(from,type,name) TypedData_Get_Struct(from,type,&type##_type,name)
7+
#else
8+
#define DATA_GET_STRUCT(from,type,name) Data_Get_Struct(from,type,name)
9+
#endif
10+
#define DATA_GET(from,type,name) DATA_GET_STRUCT(from,type,name); RAISE_NOT_NULL(name);
611
#define REQUIRE_TYPE(V, T) if(TYPE(V) != T) rb_raise(rb_eTypeError, "Wrong argument type for " # V " required " # T);
712

813
/* for compatibility with Ruby 1.8.5, which doesn't declare RSTRING_PTR */

ext/ruby_http_parser/ruby_http_parser.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ void ParserWrapper_free(void *data) {
8181
}
8282
}
8383

84+
static const rb_data_type_t ParserWrapper_type = {
85+
"ParserWrapper",
86+
{
87+
ParserWrapper_mark,
88+
ParserWrapper_free,
89+
},
90+
};
91+
8492
static VALUE cParser;
8593
static VALUE cRequestParser;
8694
static VALUE cResponseParser;
@@ -293,7 +301,7 @@ VALUE Parser_alloc_by_type(VALUE klass, enum ryah_http_parser_type type) {
293301

294302
ParserWrapper_init(wrapper);
295303

296-
return Data_Wrap_Struct(klass, ParserWrapper_mark, ParserWrapper_free, wrapper);
304+
return TypedData_Wrap_Struct(klass, &ParserWrapper_type, wrapper);
297305
}
298306

299307
VALUE Parser_alloc(VALUE klass) {

0 commit comments

Comments
 (0)