dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] thread.c (thread_initialize): avoid RSTRING_PTR and NUMT2INT
@ 2015-07-15  0:35 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-07-15  0:35 UTC (permalink / raw)
  To: spew

Favor passing VALUE args as-is and using PRisVALUE in format strings
to prevent premature GC.  In this case, we are not fixing any real
bug because location path has other references, but this makes code
easier-to-review.
---
 thread.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/thread.c b/thread.c
index 6569ddc..fc0ca39 100644
--- a/thread.c
+++ b/thread.c
@@ -769,17 +769,18 @@ thread_initialize(VALUE thread, VALUE args)
     GetThreadPtr(thread, th);
     if (th->first_args) {
 	VALUE proc = th->first_proc, line, loc;
-	const char *file;
+	VALUE file;
         if (!proc || !RTEST(loc = rb_proc_location(proc))) {
             rb_raise(rb_eThreadError, "already initialized thread");
         }
-	file = RSTRING_PTR(RARRAY_AREF(loc, 0));
+	file = RARRAY_AREF(loc, 0);
 	if (NIL_P(line = RARRAY_AREF(loc, 1))) {
-	    rb_raise(rb_eThreadError, "already initialized thread - %s",
-		     file);
+	    rb_raise(rb_eThreadError,
+		     "already initialized thread - %"PRIsVALUE, file);
 	}
-        rb_raise(rb_eThreadError, "already initialized thread - %s:%d",
-                 file, NUM2INT(line));
+        rb_raise(rb_eThreadError,
+		 "already initialized thread - %"PRIsVALUE":%"PRIsVALUE,
+                 file, line);
     }
     return thread_create_core(thread, args, 0);
 }
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-07-15  0:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-15  0:35 [PATCH] thread.c (thread_initialize): avoid RSTRING_PTR and NUMT2INT Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).