1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

thread.c (thread_initialize): avoid RSTRING_PTR and NUMT2INT

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2015-07-15 18:11:05 +00:00
parent 66a36e9b13
commit 5522e010e5
2 changed files with 11 additions and 6 deletions

View file

@ -1,3 +1,7 @@
Thu Jul 16 02:56:14 2015 Eric Wong <e@80x24.org>
* thread.c (thread_initialize): avoid RSTRING_PTR and NUMT2INT
Thu Jul 16 01:00:46 2015 Naohisa Goto <ngotogenome@gmail.com>
* test/ruby/test_process.rb (test_exec_close_reserved_fd): test for

View file

@ -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);
}