From 2ca88db578a4b9143a5dfaa66ce38b9463e7e166 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 6 Oct 2009 12:03:10 -0700 Subject: ext: ensure all objects we byte_xs are Strings Rack will be relaxing the spec to allow subclasses of String objects. Just in case they're not compatible, we'll convert them to strings. --- ext/clogger_ext/clogger.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'ext') diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c index f935c11..26d1ec6 100644 --- a/ext/clogger_ext/clogger.c +++ b/ext/clogger_ext/clogger.c @@ -124,7 +124,7 @@ static inline int need_escape(unsigned c) } /* we are encoding-agnostic, clients can send us all sorts of junk */ -static VALUE byte_xs(VALUE from) +static VALUE byte_xs_str(VALUE from) { static const char esc[] = "0123456789ABCDEF"; unsigned char *new_ptr; @@ -164,6 +164,11 @@ static VALUE byte_xs(VALUE from) return rv; } +static VALUE byte_xs(VALUE from) +{ + return byte_xs_str(rb_obj_as_string(from)); +} + static void clogger_mark(void *ptr) { struct clogger *c = ptr; @@ -459,7 +464,7 @@ static void append_request_env(struct clogger *c, VALUE key) { VALUE tmp = rb_hash_aref(c->env, key); - tmp = NIL_P(tmp) ? g_dash : byte_xs(rb_obj_as_string(tmp)); + tmp = NIL_P(tmp) ? g_dash : byte_xs(tmp); rb_str_buf_append(c->log_buf, tmp); } @@ -470,7 +475,7 @@ static void append_response(struct clogger *c, VALUE key) assert(rb_obj_class(c->headers) == cHeaderHash); v = rb_funcall(c->headers, sq_brace_id, 1, key); - v = NIL_P(v) ? g_dash : byte_xs(rb_obj_as_string(v)); + v = NIL_P(v) ? g_dash : byte_xs(v); rb_str_buf_append(c->log_buf, v); } -- cgit v1.2.3-24-ge0c7