diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-17 07:06:50 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-17 07:06:50 +0000 |
commit | 147107ce36eb1231fb79af066ab172d5003d3a1a (patch) | |
tree | f8d45d8ea908b88943daea139b9dc479e51c7f03 /thread.c | |
parent | 97c77bacfb24994cc0f5c33731a88f59ad0b6e79 (diff) |
merge revision(s) 57968,57969,57970: [Backport #13313]
thread.c: thread_do_start
* thread.c (thread_do_start): extract from a macro in
thread_start_func_2 for debugger.
thread.c: Thread.start with Symbol
* thread.c (thread_do_start): fix segfault at start with Symbol.
proc created by Symbol#to_proc does not have environment unless
using refinements. [ruby-core:80147] [Bug #13313]
Fiber also has same issue. [Bug #13313]
* thread.c (rb_vm_proc_local_ep): added.
* cont.c (rb_fiber_start): use rb_vm_proc_local_ep().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@58003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 53 |
1 files changed, 35 insertions, 18 deletions
@@ -550,12 +550,45 @@ ruby_thread_init_stack(rb_thread_t *th) native_thread_init_stack(th); } +const VALUE * +rb_vm_proc_local_ep(VALUE proc) +{ + const VALUE *ep = vm_proc_ep(proc); + + if (ep) { + return rb_vm_ep_local_ep(ep); + } + else { + return NULL; + } +} + +static void +thread_do_start(rb_thread_t *th, VALUE args) +{ + native_set_thread_name(th); + if (!th->first_func) { + rb_proc_t *proc; + GetProcPtr(th->first_proc, proc); + th->errinfo = Qnil; + th->root_lep = rb_vm_proc_local_ep(th->first_proc); + th->root_svar = Qfalse; + EXEC_EVENT_HOOK(th, RUBY_EVENT_THREAD_BEGIN, th->self, 0, 0, 0, Qundef); + th->value = rb_vm_invoke_proc(th, proc, + (int)RARRAY_LEN(args), RARRAY_CONST_PTR(args), + VM_BLOCK_HANDLER_NONE); + EXEC_EVENT_HOOK(th, RUBY_EVENT_THREAD_END, th->self, 0, 0, 0, Qundef); + } + else { + th->value = (*th->first_func)((void *)args); + } +} + static int thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_start) { int state; VALUE args = th->first_args; - rb_proc_t *proc; rb_thread_list_t *join_list; rb_thread_t *main_th; VALUE errinfo = Qnil; @@ -583,23 +616,7 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s TH_PUSH_TAG(th); if ((state = EXEC_TAG()) == 0) { - SAVE_ROOT_JMPBUF(th, { - native_set_thread_name(th); - if (!th->first_func) { - GetProcPtr(th->first_proc, proc); - th->errinfo = Qnil; - th->root_lep = rb_vm_ep_local_ep(vm_proc_ep(th->first_proc)); - th->root_svar = Qfalse; - EXEC_EVENT_HOOK(th, RUBY_EVENT_THREAD_BEGIN, th->self, 0, 0, 0, Qundef); - th->value = rb_vm_invoke_proc(th, proc, - (int)RARRAY_LEN(args), RARRAY_CONST_PTR(args), - VM_BLOCK_HANDLER_NONE); - EXEC_EVENT_HOOK(th, RUBY_EVENT_THREAD_END, th->self, 0, 0, 0, Qundef); - } - else { - th->value = (*th->first_func)((void *)args); - } - }); + SAVE_ROOT_JMPBUF(th, thread_do_start(th, args)); } else { errinfo = th->errinfo; |