From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: spew@80x24.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 8E3FA640010 for ; Wed, 15 Jul 2015 00:35:31 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] thread.c (thread_initialize): avoid RSTRING_PTR and NUMT2INT Date: Wed, 15 Jul 2015 00:35:31 +0000 Message-Id: <1436920531-29544-1-git-send-email-e@80x24.org> List-Id: 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