Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/thin_parser/ext_help.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#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 DATA_GET(from,type,name,data_type) TypedData_Get_Struct(from,type,data_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);

#ifdef DEBUG
Expand Down
31 changes: 20 additions & 11 deletions ext/thin_parser/thin.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,27 @@ void Thin_HttpParser_free(void *data) {
TRACE();

if(data) {
free(data);
xfree(data);
}
}

static size_t Thin_HttpParser_memsize(const void *data) {
return data ? sizeof(http_parser) : 0;
}

static const rb_data_type_t Thin_HttpParser_type = {
"Thin::HttpParser",
{NULL, Thin_HttpParser_free, Thin_HttpParser_memsize,},
NULL, NULL, 0,
};


VALUE Thin_HttpParser_alloc(VALUE klass)
{
VALUE obj;
http_parser *hp = ALLOC_N(http_parser, 1);
http_parser *hp;
TRACE();
obj = TypedData_Make_Struct(klass, http_parser, &Thin_HttpParser_type, hp);
hp->http_field = http_field;
hp->request_method = request_method;
hp->request_uri = request_uri;
Expand All @@ -241,8 +252,6 @@ VALUE Thin_HttpParser_alloc(VALUE klass)
hp->header_done = header_done;
thin_http_parser_init(hp);

obj = Data_Wrap_Struct(klass, NULL, Thin_HttpParser_free, hp);

return obj;
}

Expand All @@ -256,7 +265,7 @@ VALUE Thin_HttpParser_alloc(VALUE klass)
VALUE Thin_HttpParser_init(VALUE self)
{
http_parser *http = NULL;
DATA_GET(self, http_parser, http);
DATA_GET(self, http_parser, http, &Thin_HttpParser_type);
thin_http_parser_init(http);

return self;
Expand All @@ -273,7 +282,7 @@ VALUE Thin_HttpParser_init(VALUE self)
VALUE Thin_HttpParser_reset(VALUE self)
{
http_parser *http = NULL;
DATA_GET(self, http_parser, http);
DATA_GET(self, http_parser, http, &Thin_HttpParser_type);
thin_http_parser_init(http);

return Qnil;
Expand All @@ -290,7 +299,7 @@ VALUE Thin_HttpParser_reset(VALUE self)
VALUE Thin_HttpParser_finish(VALUE self)
{
http_parser *http = NULL;
DATA_GET(self, http_parser, http);
DATA_GET(self, http_parser, http, &Thin_HttpParser_type);
thin_http_parser_finish(http);

return thin_http_parser_is_finished(http) ? Qtrue : Qfalse;
Expand Down Expand Up @@ -321,7 +330,7 @@ VALUE Thin_HttpParser_execute(VALUE self, VALUE req_hash, VALUE data, VALUE star
char *dptr = NULL;
long dlen = 0;

DATA_GET(self, http_parser, http);
DATA_GET(self, http_parser, http, &Thin_HttpParser_type);

from = FIX2INT(start);
dptr = RSTRING_PTR(data);
Expand Down Expand Up @@ -354,7 +363,7 @@ VALUE Thin_HttpParser_execute(VALUE self, VALUE req_hash, VALUE data, VALUE star
VALUE Thin_HttpParser_has_error(VALUE self)
{
http_parser *http = NULL;
DATA_GET(self, http_parser, http);
DATA_GET(self, http_parser, http, &Thin_HttpParser_type);

return thin_http_parser_has_error(http) ? Qtrue : Qfalse;
}
Expand All @@ -369,7 +378,7 @@ VALUE Thin_HttpParser_has_error(VALUE self)
VALUE Thin_HttpParser_is_finished(VALUE self)
{
http_parser *http = NULL;
DATA_GET(self, http_parser, http);
DATA_GET(self, http_parser, http, &Thin_HttpParser_type);

return thin_http_parser_is_finished(http) ? Qtrue : Qfalse;
}
Expand All @@ -385,7 +394,7 @@ VALUE Thin_HttpParser_is_finished(VALUE self)
VALUE Thin_HttpParser_nread(VALUE self)
{
http_parser *http = NULL;
DATA_GET(self, http_parser, http);
DATA_GET(self, http_parser, http, &Thin_HttpParser_type);

return INT2FIX(http->nread);
}
Expand Down
Loading