diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/unicorn/http11/ext_help.h | 3 | ||||
-rw-r--r-- | ext/unicorn/http11/http11.c | 22 |
2 files changed, 13 insertions, 12 deletions
diff --git a/ext/unicorn/http11/ext_help.h b/ext/unicorn/http11/ext_help.h index 08c0e1e..17f7b01 100644 --- a/ext/unicorn/http11/ext_help.h +++ b/ext/unicorn/http11/ext_help.h @@ -1,9 +1,6 @@ #ifndef ext_help_h #define ext_help_h -#define RAISE_NOT_NULL(T) if(T == NULL) rb_raise(rb_eArgError, "NULL found for " # T " when shouldn't be."); -#define DATA_GET(from,type,name) Data_Get_Struct(from,type,name); RAISE_NOT_NULL(name); -#define REQUIRE_TYPE(V, T) if(TYPE(V) != T) rb_raise(rb_eTypeError, "Wrong argument type for " # V " required " # T); #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) #ifdef DEBUG diff --git a/ext/unicorn/http11/http11.c b/ext/unicorn/http11/http11.c index 3b21d27..3ca9ca1 100644 --- a/ext/unicorn/http11/http11.c +++ b/ext/unicorn/http11/http11.c @@ -9,6 +9,16 @@ #include <string.h> #include "http11_parser.h" +static http_parser *data_get(VALUE self) +{ + http_parser *http; + + Data_Get_Struct(self, http_parser, http); + if (!http) + rb_raise(rb_eArgError, "NULL found for http when shouldn't be."); + return http; +} + #ifndef RSTRING_PTR #define RSTRING_PTR(s) (RSTRING(s)->ptr) #endif @@ -324,9 +334,7 @@ static VALUE HttpParser_alloc(VALUE klass) */ static VALUE HttpParser_init(VALUE self) { - http_parser *http = NULL; - DATA_GET(self, http_parser, http); - http_parser_init(http); + http_parser_init(data_get(self)); return self; } @@ -341,9 +349,7 @@ static VALUE HttpParser_init(VALUE self) */ static VALUE HttpParser_reset(VALUE self) { - http_parser *http = NULL; - DATA_GET(self, http_parser, http); - http_parser_init(http); + http_parser_init(data_get(self)); return Qnil; } @@ -364,12 +370,10 @@ static VALUE HttpParser_reset(VALUE self) static VALUE HttpParser_execute(VALUE self, VALUE req_hash, VALUE data) { - http_parser *http; + http_parser *http = data_get(self); char *dptr = RSTRING_PTR(data); long dlen = RSTRING_LEN(data); - DATA_GET(self, http_parser, http); - if (http->nread < dlen) { http->data = (void *)req_hash; http_parser_execute(http, dptr, dlen); |