clogger RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
						download: 
* [PATCH 4/6] prevent potential premature GC in byte_xs
      [irrelevant] <1392505748-13740-1-git-send-email-normalperson@yhbt.net>
@ 2014-02-15 23:09 ` Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2014-02-15 23:09 UTC (permalink / raw)
  To: clogger

If we convert an object to string, there is a potential the
compiler may optimize away the converted string if escaping
is needed.  Prevent that with RB_GC_GUARD.
---
 ext/clogger_ext/clogger.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c
index ed01534..8b05c34 100644
--- a/ext/clogger_ext/clogger.c
+++ b/ext/clogger_ext/clogger.c
@@ -166,10 +166,11 @@ static inline int need_escape(unsigned c)
 }
 
 /* we are encoding-agnostic, clients can send us all sorts of junk */
-static VALUE byte_xs_str(VALUE from)
+static VALUE byte_xs(VALUE obj)
 {
 	static const char esc[] = "0123456789ABCDEF";
 	unsigned char *new_ptr;
+	VALUE from = rb_obj_as_string(obj);
 	const unsigned char *ptr = (const unsigned char *)RSTRING_PTR(from);
 	long len = RSTRING_LEN(from);
 	long new_len = len;
@@ -203,14 +204,10 @@ static VALUE byte_xs_str(VALUE from)
 	}
 	assert(RSTRING_PTR(rv)[RSTRING_LEN(rv)] == '\0');
 
+	RB_GC_GUARD(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;
-- 
1.9.0.rc3.13.gda73b5f



^ permalink raw reply	[relevance 7%]

Results 1-1 of 1 | reverse results
    [irrelevant] <1392505748-13740-1-git-send-email-normalperson@yhbt.net>
2014-02-15 23:09 ` [PATCH 4/6] prevent potential premature GC in byte_xs Eric Wong


clogger RubyGem user+dev discussion/patches/pulls/bugs/help

Archives are clonable:
	git clone --mirror https://bogomips.org/clogger-public
	git clone --mirror http://ou63pmih66umazou.onion/clogger-public

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.clogger
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.clogger

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox