about summary refs log tree commit homepage
path: root/ext/unicorn/http11/http11.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-04-21 11:14:47 -0700
committerEric Wong <normalperson@yhbt.net>2009-04-21 11:16:30 -0700
commitcd0c49fbc22aa4b13f8c11917d8fd01e9c31eb2e (patch)
treefddd2baae915caab8d590249d80f02de414113ef /ext/unicorn/http11/http11.c
parent44d731cebec9c95e3a5cfc1fe7b7aeafcb3fe3b4 (diff)
downloadunicorn-cd0c49fbc22aa4b13f8c11917d8fd01e9c31eb2e.tar.gz
I don't see the point of using a macro here as it's never called
in a hot path.  It's a very minor size reduction in the binary,
but also makes the rest of the code less noisy/screamy.
Diffstat (limited to 'ext/unicorn/http11/http11.c')
-rw-r--r--ext/unicorn/http11/http11.c22
1 files changed, 13 insertions, 9 deletions
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);