diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | test/ruby/test_thread.rb | 6 | ||||
-rw-r--r-- | thread.c | 8 | ||||
-rw-r--r-- | thread_pthread.c | 7 | ||||
-rw-r--r-- | version.h | 6 |
5 files changed, 26 insertions, 7 deletions
@@ -1,3 +1,9 @@ +Sat Apr 16 00:56:45 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * thread.c (rb_thread_setname): defer setting native thread name + set in initialize until the native thread is created. + [ruby-core:74963] [Bug #12290] + Fri Apr 15 21:10:00 2016 SHIBATA Hiroshi <hsbt@ruby-lang.org> * lib/irb/ext/save-history.rb: Fix NoMethodError when method is not defined. diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index dc929ce4fd..c90c369bb7 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -1082,4 +1082,10 @@ q.pop t.kill t.join end + + def test_thread_setname_in_initialize + bug12290 = '[ruby-core:74963] [Bug #12290]' + c = Class.new(Thread) {def initialize() self.name = "foo"; super; end} + assert_equal("foo", c.new {Thread.current.name}.value) + end end @@ -711,6 +711,8 @@ thread_create_core(VALUE thval, VALUE args, VALUE (*fn)(ANYARGS)) return thval; } +#define threadptr_initialized(th) ((th)->first_args != 0) + /* * call-seq: * Thread.new { ... } -> thread @@ -742,7 +744,7 @@ thread_s_new(int argc, VALUE *argv, VALUE klass) rb_obj_call_init(thread, argc, argv); GetThreadPtr(thread, th); - if (!th->first_args) { + if (!threadptr_initialized(th)) { rb_raise(rb_eThreadError, "uninitialized thread - check `%"PRIsVALUE"#initialize'", klass); } @@ -2794,7 +2796,9 @@ rb_thread_setname(VALUE thread, VALUE name) } th->name = name; #if defined(SET_ANOTHER_THREAD_NAME) - SET_ANOTHER_THREAD_NAME(th->thread_id, s); + if (threadptr_initialized(th)) { + SET_ANOTHER_THREAD_NAME(th->thread_id, s); + } #endif return name; } diff --git a/thread_pthread.c b/thread_pthread.c index a070434afe..4aa2d620a2 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -1505,8 +1505,11 @@ native_set_thread_name(rb_thread_t *th) { #ifdef SET_CURRENT_THREAD_NAME if (!th->first_func && th->first_proc) { - VALUE loc = rb_proc_location(th->first_proc); - if (!NIL_P(loc)) { + VALUE loc; + if (!NIL_P(loc = th->name)) { + SET_CURRENT_THREAD_NAME(RSTRING_PTR(loc)); + } + else if (!NIL_P(loc = rb_proc_location(th->first_proc))) { const VALUE *ptr = RARRAY_CONST_PTR(loc); /* [ String, Fixnum ] */ char *name, *p; char buf[16]; @@ -1,10 +1,10 @@ #define RUBY_VERSION "2.3.0" -#define RUBY_RELEASE_DATE "2016-04-15" -#define RUBY_PATCHLEVEL 81 +#define RUBY_RELEASE_DATE "2016-04-16" +#define RUBY_PATCHLEVEL 82 #define RUBY_RELEASE_YEAR 2016 #define RUBY_RELEASE_MONTH 4 -#define RUBY_RELEASE_DAY 15 +#define RUBY_RELEASE_DAY 16 #include "ruby/version.h" |