about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-08-29 16:15:18 -0700
committerEric Wong <normalperson@yhbt.net>2009-08-29 16:15:18 -0700
commitcb1772c91444c0c4eb3e4cf17cac5e265cb2a551 (patch)
tree77f5f3037d1f0e04499a1f7e13020bd6f7d1b42c
parentde46287e9ea70e63e77d17c862ee6bf5ab105e96 (diff)
parented276bd6ba03b89201bfdfd1730b428b224372f0 (diff)
* dcvr:clogger:
  ext: several cleanups and robustness improvements
  ext: explicitly gc_mark each struct element
-rw-r--r--ext/clogger_ext/clogger.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c
index 493f5ae..de38ba2 100644
--- a/ext/clogger_ext/clogger.c
+++ b/ext/clogger_ext/clogger.c
@@ -188,7 +188,7 @@ struct response_ops { long nr; VALUE ops; };
 static VALUE swap_sent_headers(VALUE kv, VALUE memo)
 {
         struct response_ops *tmp = (struct response_ops *)memo;
-        VALUE key = RARRAY_PTR(kv)[0];
+        VALUE key = rb_obj_as_string(RARRAY_PTR(kv)[0]);
         long i = RARRAY_LEN(tmp->ops);
         VALUE *ary = RARRAY_PTR(tmp->ops);
         VALUE value;
@@ -248,7 +248,13 @@ static void clogger_mark(void *ptr)
 {
         struct clogger *c = ptr;
 
-        rb_gc_mark_locations(&c->app, &c->response);
+        rb_gc_mark(c->app);
+        rb_gc_mark(c->fmt_ops);
+        rb_gc_mark(c->logger);
+        rb_gc_mark(c->log_buf);
+        rb_gc_mark(c->env);
+        rb_gc_mark(c->cookies);
+        rb_gc_mark(c->response);
 }
 
 static VALUE clogger_alloc(VALUE klass)
@@ -331,10 +337,11 @@ static VALUE clogger_wrap_body(VALUE self)
         return clogger_get(self)->wrap_body == 0 ? Qfalse : Qtrue;
 }
 
-static void append_status(struct clogger *c, VALUE status)
+static void append_status(struct clogger *c)
 {
         char buf[sizeof("999")];
         int nr;
+        VALUE status = RARRAY_PTR(c->response)[0];
 
         if (TYPE(status) != T_FIXNUM) {
                 status = rb_funcall(status, to_i_id, 0);
@@ -536,7 +543,7 @@ static void special_var(struct clogger *c, enum clogger_special var)
                 append_body_bytes_sent(c);
                 break;
         case CL_SP_status:
-                append_status(c, RARRAY_PTR(c->response)[0]);
+                append_status(c);
                 break;
         case CL_SP_request:
                 append_request(c);
@@ -667,6 +674,7 @@ static VALUE body_iter_i(VALUE str, VALUE memop)
 {
         off_t *len = (off_t *)memop;
 
+        str = rb_obj_as_string(str);
         *len += RSTRING_LEN(str);
 
         return rb_yield(str);
@@ -676,7 +684,6 @@ static VALUE wrap_each(struct clogger *c)
 {
         VALUE body = RARRAY_PTR(c->response)[2];
 
-        rb_need_block();
         c->body_bytes_sent = 0;
         rb_iterate(rb_each, body, body_iter_i, (VALUE)&c->body_bytes_sent);
 
@@ -695,6 +702,8 @@ static VALUE clogger_each(VALUE self)
 {
         struct clogger *c = clogger_get(self);
 
+        rb_need_block();
+
         return rb_ensure(wrap_each, (VALUE)c, cwrite, (VALUE)c);
 }