introduce EC_*_TAG() instead of TH_*_TAG()

* eval_intern.h:
  introduce EC_*_TAG() macros instead of TH_*_TAG() macros.
  * TH_PUSH_TAG() -> EC_PUSH_TAG()
  * TH_POP_TAG() -> EC_POP_TAG()
  * TH_TMPPOP_TAG() -> EC_TMPPOP_TAG()
  * TH_REPUSH_TAG() -> EC_REPUSH_TAG()
  * TH_EXEC_TAG() -> EC_EXEC_TAG()
  * TH_JUMP_TAG() -> EC_JUMP_TAG()

  rb_threadptr_tag_state() , rb_ec_tag_jump() also accept `ec` instead of `th`.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2017-10-26 11:02:13 +00:00
parent 24044b2f63
commit 4552f74715
16 changed files with 124 additions and 123 deletions

4
cont.c
View File

@ -1408,7 +1408,7 @@ rb_fiber_start(void)
VM_ASSERT(th->ec == ruby_current_execution_context_ptr); VM_ASSERT(th->ec == ruby_current_execution_context_ptr);
VM_ASSERT(FIBER_RESUMED_P(fib)); VM_ASSERT(FIBER_RESUMED_P(fib));
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
rb_context_t *cont = &VAR_FROM_MEMORY(fib)->cont; rb_context_t *cont = &VAR_FROM_MEMORY(fib)->cont;
int argc; int argc;
@ -1423,7 +1423,7 @@ rb_fiber_start(void)
EXEC_EVENT_HOOK(th, RUBY_EVENT_FIBER_SWITCH, th->self, 0, 0, 0, Qnil); EXEC_EVENT_HOOK(th, RUBY_EVENT_FIBER_SWITCH, th->self, 0, 0, 0, Qnil);
cont->value = rb_vm_invoke_proc(th, proc, argc, argv, VM_BLOCK_HANDLER_NONE); cont->value = rb_vm_invoke_proc(th, proc, argc, argv, VM_BLOCK_HANDLER_NONE);
} }
TH_POP_TAG(); EC_POP_TAG();
if (state) { if (state) {
VM_ASSERT(FIBER_RESUMED_P(fib)); VM_ASSERT(FIBER_RESUMED_P(fib));

44
eval.c
View File

@ -169,7 +169,7 @@ ruby_cleanup(volatile int ex)
rb_threadptr_interrupt(th); rb_threadptr_interrupt(th);
rb_threadptr_check_signal(th); rb_threadptr_check_signal(th);
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
SAVE_ROOT_JMPBUF(th, { RUBY_VM_CHECK_INTS(th); }); SAVE_ROOT_JMPBUF(th, { RUBY_VM_CHECK_INTS(th); });
@ -224,7 +224,7 @@ ruby_cleanup(volatile int ex)
/* unlock again if finalizer took mutexes. */ /* unlock again if finalizer took mutexes. */
rb_threadptr_unlock_all_locking_mutexes(GET_THREAD()); rb_threadptr_unlock_all_locking_mutexes(GET_THREAD());
TH_POP_TAG(); EC_POP_TAG();
rb_thread_stop_timer_thread(); rb_thread_stop_timer_thread();
ruby_vm_destruct(GET_VM()); ruby_vm_destruct(GET_VM());
if (state) ruby_default_signal(state); if (state) ruby_default_signal(state);
@ -241,13 +241,13 @@ ruby_exec_internal(void *n)
if (!n) return 0; if (!n) return 0;
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
SAVE_ROOT_JMPBUF(th, { SAVE_ROOT_JMPBUF(th, {
rb_iseq_eval_main(iseq); rb_iseq_eval_main(iseq);
}); });
} }
TH_POP_TAG(); EC_POP_TAG();
return state; return state;
} }
@ -479,7 +479,7 @@ exc_setup_message(rb_thread_t *th, VALUE mesg, VALUE *cause)
if (NIL_P(mesg)) { if (NIL_P(mesg)) {
mesg = th->ec->errinfo; mesg = th->ec->errinfo;
if (INTERNAL_EXCEPTION_P(mesg)) TH_JUMP_TAG(th, TAG_FATAL); if (INTERNAL_EXCEPTION_P(mesg)) EC_JUMP_TAG(th->ec, TAG_FATAL);
nocause = 1; nocause = 1;
} }
if (NIL_P(mesg)) { if (NIL_P(mesg)) {
@ -508,7 +508,7 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
if ((file && !NIL_P(mesg)) || (cause != Qundef)) { if ((file && !NIL_P(mesg)) || (cause != Qundef)) {
volatile int state = 0; volatile int state = 0;
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if (EXEC_TAG() == TAG_NONE && !(state = rb_threadptr_set_raised(th))) { if (EXEC_TAG() == TAG_NONE && !(state = rb_threadptr_set_raised(th))) {
VALUE bt = rb_get_backtrace(mesg); VALUE bt = rb_get_backtrace(mesg);
if (!NIL_P(bt) || cause == Qundef) { if (!NIL_P(bt) || cause == Qundef) {
@ -526,7 +526,7 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
} }
rb_threadptr_reset_raised(th); rb_threadptr_reset_raised(th);
} }
TH_POP_TAG(); EC_POP_TAG();
if (state) goto fatal; if (state) goto fatal;
} }
@ -539,7 +539,7 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
enum ruby_tag_type state; enum ruby_tag_type state;
mesg = e; mesg = e;
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
th->ec->errinfo = Qnil; th->ec->errinfo = Qnil;
e = rb_obj_as_string(mesg); e = rb_obj_as_string(mesg);
@ -558,13 +558,13 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
} }
warn_print_str(e); warn_print_str(e);
} }
TH_POP_TAG(); EC_POP_TAG();
if (state == TAG_FATAL && th->ec->errinfo == exception_error) { if (state == TAG_FATAL && th->ec->errinfo == exception_error) {
th->ec->errinfo = mesg; th->ec->errinfo = mesg;
} }
else if (state) { else if (state) {
rb_threadptr_reset_raised(th); rb_threadptr_reset_raised(th);
TH_JUMP_TAG(th, state); EC_JUMP_TAG(th->ec, state);
} }
} }
@ -572,7 +572,7 @@ setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
fatal: fatal:
th->ec->errinfo = exception_error; th->ec->errinfo = exception_error;
rb_threadptr_reset_raised(th); rb_threadptr_reset_raised(th);
TH_JUMP_TAG(th, TAG_FATAL); EC_JUMP_TAG(th->ec, TAG_FATAL);
} }
if (tag != TAG_FATAL) { if (tag != TAG_FATAL) {
@ -599,7 +599,7 @@ rb_longjmp(rb_thread_t *th, int tag, volatile VALUE mesg, VALUE cause)
mesg = exc_setup_message(th, mesg, &cause); mesg = exc_setup_message(th, mesg, &cause);
setup_exception(th, tag, mesg, cause); setup_exception(th, tag, mesg, cause);
rb_thread_raised_clear(th); rb_thread_raised_clear(th);
TH_JUMP_TAG(th, tag); EC_JUMP_TAG(th->ec, tag);
} }
static VALUE make_exception(int argc, const VALUE *argv, int isstr); static VALUE make_exception(int argc, const VALUE *argv, int isstr);
@ -902,8 +902,8 @@ rb_rescue2(VALUE (* b_proc) (ANYARGS), VALUE data1,
volatile VALUE e_info = th->ec->errinfo; volatile VALUE e_info = th->ec->errinfo;
va_list args; va_list args;
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = TH_EXEC_TAG()) == TAG_NONE) { if ((state = EC_EXEC_TAG()) == TAG_NONE) {
retry_entry: retry_entry:
result = (*b_proc) (data1); result = (*b_proc) (data1);
} }
@ -942,9 +942,9 @@ rb_rescue2(VALUE (* b_proc) (ANYARGS), VALUE data1,
} }
} }
} }
TH_POP_TAG(); EC_POP_TAG();
if (state) if (state)
TH_JUMP_TAG(th, state); EC_JUMP_TAG(th->ec, state);
return result; return result;
} }
@ -1000,10 +1000,10 @@ rb_protect(VALUE (* proc) (VALUE), VALUE data, int *pstate)
protect_tag.prev = th->ec->protect_tag; protect_tag.prev = th->ec->protect_tag;
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
th->ec->protect_tag = &protect_tag; th->ec->protect_tag = &protect_tag;
MEMCPY(&org_jmpbuf, &(th)->root_jmpbuf, rb_jmpbuf_t, 1); MEMCPY(&org_jmpbuf, &(th)->root_jmpbuf, rb_jmpbuf_t, 1);
if ((state = TH_EXEC_TAG()) == TAG_NONE) { if ((state = EC_EXEC_TAG()) == TAG_NONE) {
SAVE_ROOT_JMPBUF(th, result = (*proc) (data)); SAVE_ROOT_JMPBUF(th, result = (*proc) (data));
} }
else { else {
@ -1011,7 +1011,7 @@ rb_protect(VALUE (* proc) (VALUE), VALUE data, int *pstate)
} }
MEMCPY(&(th)->root_jmpbuf, &org_jmpbuf, rb_jmpbuf_t, 1); MEMCPY(&(th)->root_jmpbuf, &org_jmpbuf, rb_jmpbuf_t, 1);
th->ec->protect_tag = protect_tag.prev; th->ec->protect_tag = protect_tag.prev;
TH_POP_TAG(); EC_POP_TAG();
if (pstate != NULL) *pstate = state; if (pstate != NULL) *pstate = state;
return result; return result;
@ -1044,11 +1044,11 @@ rb_ensure(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*e_proc)(ANYARGS), VALUE
ensure_list.entry.data2 = data2; ensure_list.entry.data2 = data2;
ensure_list.next = th->ec->ensure_list; ensure_list.next = th->ec->ensure_list;
th->ec->ensure_list = &ensure_list; th->ec->ensure_list = &ensure_list;
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
result = (*b_proc) (data1); result = (*b_proc) (data1);
} }
TH_POP_TAG(); EC_POP_TAG();
errinfo = th->ec->errinfo; errinfo = th->ec->errinfo;
if (!NIL_P(errinfo) && !RB_TYPE_P(errinfo, T_OBJECT)) { if (!NIL_P(errinfo) && !RB_TYPE_P(errinfo, T_OBJECT)) {
th->ec->errinfo = Qnil; th->ec->errinfo = Qnil;
@ -1057,7 +1057,7 @@ rb_ensure(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*e_proc)(ANYARGS), VALUE
(*ensure_list.entry.e_proc)(ensure_list.entry.data2); (*ensure_list.entry.e_proc)(ensure_list.entry.data2);
th->ec->errinfo = errinfo; th->ec->errinfo = errinfo;
if (state) if (state)
TH_JUMP_TAG(th, state); EC_JUMP_TAG(th->ec, state);
return result; return result;
} }

View File

@ -174,8 +174,8 @@ rb_threadptr_error_print(rb_thread_t *volatile th, volatile VALUE errinfo)
return; return;
rb_thread_raised_clear(th); rb_thread_raised_clear(th);
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if (TH_EXEC_TAG() == TAG_NONE) { if (EC_EXEC_TAG() == TAG_NONE) {
errat = rb_get_backtrace(errinfo); errat = rb_get_backtrace(errinfo);
} }
else if (errat == Qundef) { else if (errat == Qundef) {
@ -201,7 +201,7 @@ rb_threadptr_error_print(rb_thread_t *volatile th, volatile VALUE errinfo)
print_backtrace(eclass, errat, FALSE); print_backtrace(eclass, errat, FALSE);
} }
error: error:
TH_POP_TAG(); EC_POP_TAG();
th->ec->errinfo = errinfo; th->ec->errinfo = errinfo;
rb_thread_raised_set(th, raised_flag); rb_thread_raised_set(th, raised_flag);
} }

View File

@ -128,24 +128,24 @@ LONG WINAPI rb_w32_stack_overflow_handler(struct _EXCEPTION_POINTERS *);
rb_fiber_start(); \ rb_fiber_start(); \
} while (0) } while (0)
#define TH_PUSH_TAG(th) do { \ #define EC_PUSH_TAG(ec) do { \
rb_thread_t * const _th = (th); \ rb_execution_context_t * const _ec = (ec); \
struct rb_vm_tag _tag; \ struct rb_vm_tag _tag; \
_tag.state = TAG_NONE; \ _tag.state = TAG_NONE; \
_tag.tag = Qundef; \ _tag.tag = Qundef; \
_tag.prev = _th->ec->tag; _tag.prev = _ec->tag;
#define TH_POP_TAG() \ #define EC_POP_TAG() \
_th->ec->tag = _tag.prev; \ _ec->tag = _tag.prev; \
} while (0) } while (0)
#define TH_TMPPOP_TAG() \ #define EC_TMPPOP_TAG() \
_th->ec->tag = _tag.prev _ec->tag = _tag.prev
#define TH_REPUSH_TAG() (void)(_th->ec->tag = &_tag) #define EC_REPUSH_TAG() (void)(_ec->tag = &_tag)
#define PUSH_TAG() TH_PUSH_TAG(GET_THREAD()) #define PUSH_TAG() EC_PUSH_TAG(GET_EC())
#define POP_TAG() TH_POP_TAG() #define POP_TAG() EC_POP_TAG()
#if defined __GNUC__ && __GNUC__ == 4 && (__GNUC_MINOR__ >= 6 && __GNUC_MINOR__ <= 8) #if defined __GNUC__ && __GNUC__ == 4 && (__GNUC_MINOR__ >= 6 && __GNUC_MINOR__ <= 8)
# define VAR_FROM_MEMORY(var) __extension__(*(__typeof__(var) volatile *)&(var)) # define VAR_FROM_MEMORY(var) __extension__(*(__typeof__(var) volatile *)&(var))
@ -176,34 +176,34 @@ LONG WINAPI rb_w32_stack_overflow_handler(struct _EXCEPTION_POINTERS *);
/* clear th->ec->tag->state, and return the value */ /* clear th->ec->tag->state, and return the value */
static inline int static inline int
rb_threadptr_tag_state(rb_thread_t *th) rb_threadptr_tag_state(const rb_execution_context_t *ec)
{ {
enum ruby_tag_type state = th->ec->tag->state; enum ruby_tag_type state = ec->tag->state;
th->ec->tag->state = TAG_NONE; ec->tag->state = TAG_NONE;
return state; return state;
} }
NORETURN(static inline void rb_threadptr_tag_jump(rb_thread_t *, enum ruby_tag_type st)); NORETURN(static inline void rb_ec_tag_jump(rb_execution_context_t *ec, enum ruby_tag_type st));
static inline void static inline void
rb_threadptr_tag_jump(rb_thread_t *th, enum ruby_tag_type st) rb_ec_tag_jump(rb_execution_context_t *ec, enum ruby_tag_type st)
{ {
th->ec->tag->state = st; ec->tag->state = st;
ruby_longjmp(th->ec->tag->buf, 1); ruby_longjmp(ec->tag->buf, 1);
} }
/* /*
setjmp() in assignment expression rhs is undefined behavior setjmp() in assignment expression rhs is undefined behavior
[ISO/IEC 9899:1999] 7.13.1.1 [ISO/IEC 9899:1999] 7.13.1.1
*/ */
#define TH_EXEC_TAG() \ #define EC_EXEC_TAG() \
(ruby_setjmp(_tag.buf) ? rb_threadptr_tag_state(VAR_FROM_MEMORY(_th)) : (TH_REPUSH_TAG(), 0)) (ruby_setjmp(_tag.buf) ? rb_threadptr_tag_state(VAR_FROM_MEMORY(_ec)) : (EC_REPUSH_TAG(), 0))
#define EXEC_TAG() \ #define EXEC_TAG() \
TH_EXEC_TAG() EC_EXEC_TAG()
#define TH_JUMP_TAG(th, st) rb_threadptr_tag_jump(th, st) #define EC_JUMP_TAG(ec, st) rb_ec_tag_jump(ec, st)
#define JUMP_TAG(st) TH_JUMP_TAG(GET_THREAD(), (st)) #define JUMP_TAG(st) EC_JUMP_TAG(GET_EC(), (st))
#define INTERNAL_EXCEPTION_P(exc) FIXNUM_P(exc) #define INTERNAL_EXCEPTION_P(exc) FIXNUM_P(exc)

View File

@ -118,7 +118,7 @@ rb_exec_end_proc(void)
rb_thread_t *th = GET_THREAD(); rb_thread_t *th = GET_THREAD();
volatile VALUE errinfo = th->ec->errinfo; volatile VALUE errinfo = th->ec->errinfo;
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
again: again:
exec_end_procs_chain(&ephemeral_end_procs, &th->ec->errinfo); exec_end_procs_chain(&ephemeral_end_procs, &th->ec->errinfo);
@ -126,13 +126,13 @@ rb_exec_end_proc(void)
} }
else { else {
VAR_INITIALIZED(th); VAR_INITIALIZED(th);
TH_TMPPOP_TAG(); EC_TMPPOP_TAG();
error_handle(state); error_handle(state);
if (!NIL_P(th->ec->errinfo)) errinfo = th->ec->errinfo; if (!NIL_P(th->ec->errinfo)) errinfo = th->ec->errinfo;
TH_REPUSH_TAG(); EC_REPUSH_TAG();
goto again; goto again;
} }
TH_POP_TAG(); EC_POP_TAG();
rb_set_safe_level_force(safe); rb_set_safe_level_force(safe);
th->ec->errinfo = errinfo; th->ec->errinfo = errinfo;

8
gc.c
View File

@ -2803,8 +2803,8 @@ run_finalizer(rb_objspace_t *objspace, VALUE obj, VALUE table)
saved.cfp = th->ec->cfp; saved.cfp = th->ec->cfp;
saved.finished = 0; saved.finished = 0;
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
state = TH_EXEC_TAG(); state = EC_EXEC_TAG();
if (state != TAG_NONE) { if (state != TAG_NONE) {
++saved.finished; /* skip failed finalizer */ ++saved.finished; /* skip failed finalizer */
} }
@ -2813,7 +2813,7 @@ run_finalizer(rb_objspace_t *objspace, VALUE obj, VALUE table)
saved.finished = ++i) { saved.finished = ++i) {
run_single_final(RARRAY_AREF(table, i), saved.objid); run_single_final(RARRAY_AREF(table, i), saved.objid);
} }
TH_POP_TAG(); EC_POP_TAG();
#undef RESTORE_FINALIZER #undef RESTORE_FINALIZER
} }
@ -7720,7 +7720,7 @@ rb_memerror(void)
exc = ruby_vm_special_exception_copy(exc); exc = ruby_vm_special_exception_copy(exc);
} }
th->ec->errinfo = exc; th->ec->errinfo = exc;
TH_JUMP_TAG(th, TAG_RAISE); EC_JUMP_TAG(th->ec, TAG_RAISE);
} }
static void * static void *

10
load.c
View File

@ -599,7 +599,7 @@ rb_load_internal0(rb_thread_t *th, VALUE fname, int wrap)
rb_extend_object(th->top_self, th->top_wrapper); rb_extend_object(th->top_self, th->top_wrapper);
} }
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
state = EXEC_TAG(); state = EXEC_TAG();
if (state == TAG_NONE) { if (state == TAG_NONE) {
NODE *node; NODE *node;
@ -617,7 +617,7 @@ rb_load_internal0(rb_thread_t *th, VALUE fname, int wrap)
} }
rb_iseq_eval(iseq); rb_iseq_eval(iseq);
} }
TH_POP_TAG(); EC_POP_TAG();
#if !defined __GNUC__ #if !defined __GNUC__
th = th0; th = th0;
@ -649,7 +649,7 @@ rb_load_internal(VALUE fname, int wrap)
int state = rb_load_internal0(curr_th, fname, wrap); int state = rb_load_internal0(curr_th, fname, wrap);
if (state) { if (state) {
if (state == TAG_RAISE) rb_exc_raise(curr_th->ec->errinfo); if (state == TAG_RAISE) rb_exc_raise(curr_th->ec->errinfo);
TH_JUMP_TAG(curr_th, state); EC_JUMP_TAG(curr_th->ec, state);
} }
} }
@ -975,7 +975,7 @@ rb_require_internal(VALUE fname, int safe)
path = rb_str_encode_ospath(fname); path = rb_str_encode_ospath(fname);
RUBY_DTRACE_HOOK(REQUIRE_ENTRY, RSTRING_PTR(fname)); RUBY_DTRACE_HOOK(REQUIRE_ENTRY, RSTRING_PTR(fname));
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
saved.safe = rb_safe_level(); saved.safe = rb_safe_level();
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
long handle; long handle;
@ -1014,7 +1014,7 @@ rb_require_internal(VALUE fname, int safe)
} }
} }
} }
TH_POP_TAG(); EC_POP_TAG();
load_unlock(ftptr, !state); load_unlock(ftptr, !state);
rb_set_safe_level_force(saved.safe); rb_set_safe_level_force(saved.safe);

8
proc.c
View File

@ -2114,16 +2114,16 @@ call_method_data_safe(rb_thread_t *th, const struct METHOD *data,
VALUE result = Qnil; /* OK */ VALUE result = Qnil; /* OK */
enum ruby_tag_type state; enum ruby_tag_type state;
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = TH_EXEC_TAG()) == TAG_NONE) { if ((state = EC_EXEC_TAG()) == TAG_NONE) {
/* result is used only if state == 0, no exceptions is caught. */ /* result is used only if state == 0, no exceptions is caught. */
/* otherwise it doesn't matter even if clobbered. */ /* otherwise it doesn't matter even if clobbered. */
NO_CLOBBERED(result) = call_method_data(th, data, argc, argv, passed_procval); NO_CLOBBERED(result) = call_method_data(th, data, argc, argv, passed_procval);
} }
TH_POP_TAG(); EC_POP_TAG();
rb_set_safe_level_force(safe); rb_set_safe_level_force(safe);
if (state) if (state)
TH_JUMP_TAG(th, state); EC_JUMP_TAG(th->ec, state);
return result; return result;
} }

View File

@ -1001,18 +1001,18 @@ signal_exec(VALUE cmd, int safe, int sig)
return; return;
cur_th->interrupt_mask |= TRAP_INTERRUPT_MASK; cur_th->interrupt_mask |= TRAP_INTERRUPT_MASK;
TH_PUSH_TAG(cur_th); EC_PUSH_TAG(cur_th->ec);
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
VALUE signum = INT2NUM(sig); VALUE signum = INT2NUM(sig);
rb_eval_cmd(cmd, rb_ary_new3(1, signum), safe); rb_eval_cmd(cmd, rb_ary_new3(1, signum), safe);
} }
TH_POP_TAG(); EC_POP_TAG();
cur_th = GET_THREAD(); cur_th = GET_THREAD();
cur_th->interrupt_mask = old_interrupt_mask; cur_th->interrupt_mask = old_interrupt_mask;
if (state) { if (state) {
/* XXX: should be replaced with rb_threadptr_pending_interrupt_enque() */ /* XXX: should be replaced with rb_threadptr_pending_interrupt_enque() */
TH_JUMP_TAG(cur_th, state); EC_JUMP_TAG(cur_th->ec, state);
} }
} }

View File

@ -490,8 +490,8 @@ rb_thread_terminate_all(void)
/* unlock all locking mutexes */ /* unlock all locking mutexes */
rb_threadptr_unlock_all_locking_mutexes(th); rb_threadptr_unlock_all_locking_mutexes(th);
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if (TH_EXEC_TAG() == TAG_NONE) { if (EC_EXEC_TAG() == TAG_NONE) {
retry: retry:
thread_debug("rb_thread_terminate_all (main thread: %p)\n", (void *)th); thread_debug("rb_thread_terminate_all (main thread: %p)\n", (void *)th);
terminate_all(vm, th); terminate_all(vm, th);
@ -518,7 +518,7 @@ rb_thread_terminate_all(void)
goto retry; goto retry;
} }
} }
TH_POP_TAG(); EC_POP_TAG();
} }
static void static void
@ -625,7 +625,7 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s
thread_debug("thread start (get lock): %p\n", (void *)th); thread_debug("thread start (get lock): %p\n", (void *)th);
rb_thread_set_current(th); rb_thread_set_current(th);
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
SAVE_ROOT_JMPBUF(th, thread_do_start(th, args)); SAVE_ROOT_JMPBUF(th, thread_do_start(th, args));
} }
@ -666,7 +666,7 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s
/* treat with normal error object */ /* treat with normal error object */
rb_threadptr_raise(main_th, 1, &errinfo); rb_threadptr_raise(main_th, 1, &errinfo);
} }
TH_POP_TAG(); EC_POP_TAG();
/* locking_mutex must be Qfalse */ /* locking_mutex must be Qfalse */
if (th->locking_mutex != Qfalse) { if (th->locking_mutex != Qfalse) {
@ -1445,20 +1445,20 @@ rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd)
wfd.th = th; wfd.th = th;
list_add(&vm->waiting_fds, &wfd.wfd_node); list_add(&vm->waiting_fds, &wfd.wfd_node);
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
BLOCKING_REGION({ BLOCKING_REGION({
val = func(data1); val = func(data1);
saved_errno = errno; saved_errno = errno;
}, ubf_select, th, FALSE); }, ubf_select, th, FALSE);
} }
TH_POP_TAG(); EC_POP_TAG();
/* must be deleted before jump */ /* must be deleted before jump */
list_del(&wfd.wfd_node); list_del(&wfd.wfd_node);
if (state) { if (state) {
TH_JUMP_TAG(th, state); EC_JUMP_TAG(th->ec, state);
} }
/* TODO: check func() */ /* TODO: check func() */
RUBY_VM_CHECK_INTS_BLOCKING(th); RUBY_VM_CHECK_INTS_BLOCKING(th);
@ -1878,11 +1878,11 @@ rb_thread_s_handle_interrupt(VALUE self, VALUE mask_arg)
RUBY_VM_SET_INTERRUPT(th); RUBY_VM_SET_INTERRUPT(th);
} }
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
r = rb_yield(Qnil); r = rb_yield(Qnil);
} }
TH_POP_TAG(); EC_POP_TAG();
rb_ary_pop(th->pending_interrupt_mask_stack); rb_ary_pop(th->pending_interrupt_mask_stack);
if (!rb_threadptr_pending_interrupt_empty_p(th)) { if (!rb_threadptr_pending_interrupt_empty_p(th)) {
@ -1893,7 +1893,7 @@ rb_thread_s_handle_interrupt(VALUE self, VALUE mask_arg)
RUBY_VM_CHECK_INTS(th); RUBY_VM_CHECK_INTS(th);
if (state) { if (state) {
TH_JUMP_TAG(th, state); EC_JUMP_TAG(th->ec, state);
} }
return r; return r;
@ -2008,7 +2008,7 @@ rb_threadptr_to_kill(rb_thread_t *th)
th->status = THREAD_RUNNABLE; th->status = THREAD_RUNNABLE;
th->to_kill = 1; th->to_kill = 1;
th->ec->errinfo = INT2FIX(TAG_FATAL); th->ec->errinfo = INT2FIX(TAG_FATAL);
TH_JUMP_TAG(th, TAG_FATAL); EC_JUMP_TAG(th->ec, TAG_FATAL);
} }
static inline rb_atomic_t static inline rb_atomic_t

17
vm.c
View File

@ -1150,17 +1150,17 @@ vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self,
enum ruby_tag_type state; enum ruby_tag_type state;
volatile int stored_safe = th->ec->safe_level; volatile int stored_safe = th->ec->safe_level;
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
th->ec->safe_level = proc->safe_level; th->ec->safe_level = proc->safe_level;
val = invoke_block_from_c_proc(th, proc, self, argc, argv, passed_block_handler, proc->is_lambda); val = invoke_block_from_c_proc(th, proc, self, argc, argv, passed_block_handler, proc->is_lambda);
} }
TH_POP_TAG(); EC_POP_TAG();
th->ec->safe_level = stored_safe; th->ec->safe_level = stored_safe;
if (state) { if (state) {
TH_JUMP_TAG(th, state); EC_JUMP_TAG(th->ec, state);
} }
return val; return val;
} }
@ -1487,7 +1487,7 @@ vm_iter_break(rb_thread_t *th, VALUE val)
#endif #endif
th->ec->errinfo = (VALUE)THROW_DATA_NEW(val, target_cfp, TAG_BREAK); th->ec->errinfo = (VALUE)THROW_DATA_NEW(val, target_cfp, TAG_BREAK);
TH_JUMP_TAG(th, TAG_BREAK); EC_JUMP_TAG(th->ec, TAG_BREAK);
} }
void void
@ -1791,7 +1791,8 @@ vm_exec(rb_thread_t *th)
VALUE initial = 0; VALUE initial = 0;
struct vm_throw_data *err; struct vm_throw_data *err;
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
_tag.retval = Qnil; _tag.retval = Qnil;
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
vm_loop_start: vm_loop_start:
@ -2010,8 +2011,8 @@ vm_exec(rb_thread_t *th)
if (VM_FRAME_FINISHED_P(th->ec->cfp)) { if (VM_FRAME_FINISHED_P(th->ec->cfp)) {
rb_vm_pop_frame(th->ec); rb_vm_pop_frame(th->ec);
th->ec->errinfo = (VALUE)err; th->ec->errinfo = (VALUE)err;
TH_TMPPOP_TAG(); EC_TMPPOP_TAG();
TH_JUMP_TAG(th, state); EC_JUMP_TAG(th->ec, state);
} }
else { else {
rb_vm_pop_frame(th->ec); rb_vm_pop_frame(th->ec);
@ -2020,7 +2021,7 @@ vm_exec(rb_thread_t *th)
} }
} }
finish_vme: finish_vme:
TH_POP_TAG(); EC_POP_TAG();
return result; return result;
} }

View File

@ -1182,16 +1182,16 @@ rb_debug_inspector_open(rb_debug_inspector_func_t func, void *data)
dbg_context.backtrace_size = RARRAY_LEN(dbg_context.backtrace); dbg_context.backtrace_size = RARRAY_LEN(dbg_context.backtrace);
dbg_context.contexts = collect_caller_bindings(th); dbg_context.contexts = collect_caller_bindings(th);
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = EXEC_TAG()) == TAG_NONE) { if ((state = EXEC_TAG()) == TAG_NONE) {
result = (*func)(&dbg_context, data); result = (*func)(&dbg_context, data);
} }
TH_POP_TAG(); EC_POP_TAG();
/* invalidate bindings? */ /* invalidate bindings? */
if (state) { if (state) {
TH_JUMP_TAG(th, state); EC_JUMP_TAG(th->ec, state);
} }
return result; return result;

View File

@ -686,7 +686,7 @@ enum rb_thread_status {
typedef RUBY_JMP_BUF rb_jmpbuf_t; typedef RUBY_JMP_BUF rb_jmpbuf_t;
/* /*
the members which are written in TH_PUSH_TAG() should be placed at the members which are written in EC_PUSH_TAG() should be placed at
the beginning and the end, so that entire region is accessible. the beginning and the end, so that entire region is accessible.
*/ */
struct rb_vm_tag { struct rb_vm_tag {

View File

@ -1114,8 +1114,8 @@ rb_iterate0(VALUE (* it_proc) (VALUE), VALUE data1,
volatile VALUE retval = Qnil; volatile VALUE retval = Qnil;
rb_control_frame_t *const cfp = th->ec->cfp; rb_control_frame_t *const cfp = th->ec->cfp;
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
state = TH_EXEC_TAG(); state = EC_EXEC_TAG();
if (state == 0) { if (state == 0) {
iter_retry: iter_retry:
{ {
@ -1151,10 +1151,10 @@ rb_iterate0(VALUE (* it_proc) (VALUE), VALUE data1,
SDR(); fprintf(stderr, "%p, %p\n", cfp, escape_cfp); SDR(); fprintf(stderr, "%p, %p\n", cfp, escape_cfp);
} }
} }
TH_POP_TAG(); EC_POP_TAG();
if (state) { if (state) {
TH_JUMP_TAG(th, state); EC_JUMP_TAG(th->ec, state);
} }
return retval; return retval;
} }
@ -1349,17 +1349,17 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_
return vm_exec(th); return vm_exec(th);
} }
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = TH_EXEC_TAG()) == TAG_NONE) { if ((state = EC_EXEC_TAG()) == TAG_NONE) {
result = vm_exec(th); result = vm_exec(th);
} }
TH_POP_TAG(); EC_POP_TAG();
if (state) { if (state) {
if (state == TAG_RAISE) { if (state == TAG_RAISE) {
adjust_backtrace_in_eval(th, th->ec->errinfo); adjust_backtrace_in_eval(th, th->ec->errinfo);
} }
TH_JUMP_TAG(th, state); EC_JUMP_TAG(th->ec, state);
} }
return result; return result;
} }
@ -1505,7 +1505,7 @@ rb_eval_string_wrap(const char *str, int *pstate)
*pstate = state; *pstate = state;
} }
else if (state != TAG_NONE) { else if (state != TAG_NONE) {
TH_JUMP_TAG(th, state); EC_JUMP_TAG(th->ec, state);
} }
return val; return val;
} }
@ -1522,9 +1522,9 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level)
level = RUBY_SAFE_LEVEL_MAX; level = RUBY_SAFE_LEVEL_MAX;
} }
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
rb_set_safe_level_force(level); rb_set_safe_level_force(level);
if ((state = TH_EXEC_TAG()) == TAG_NONE) { if ((state = EC_EXEC_TAG()) == TAG_NONE) {
if (!RB_TYPE_P(cmd, T_STRING)) { if (!RB_TYPE_P(cmd, T_STRING)) {
val = rb_funcallv(cmd, idCall, RARRAY_LENINT(arg), val = rb_funcallv(cmd, idCall, RARRAY_LENINT(arg),
RARRAY_CONST_PTR(arg)); RARRAY_CONST_PTR(arg));
@ -1533,10 +1533,10 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level)
val = eval_string(rb_vm_top_self(), cmd, Qnil, 0, 0); val = eval_string(rb_vm_top_self(), cmd, Qnil, 0, 0);
} }
} }
TH_POP_TAG(); EC_POP_TAG();
rb_set_safe_level_force(safe); rb_set_safe_level_force(safe);
if (state) TH_JUMP_TAG(th, state); if (state) EC_JUMP_TAG(th->ec, state);
return val; return val;
} }
@ -1893,7 +1893,7 @@ rb_throw_obj(VALUE tag, VALUE value)
} }
th->ec->errinfo = (VALUE)THROW_DATA_NEW(tag, NULL, TAG_THROW); th->ec->errinfo = (VALUE)THROW_DATA_NEW(tag, NULL, TAG_THROW);
TH_JUMP_TAG(th, TAG_THROW); EC_JUMP_TAG(th->ec, TAG_THROW);
} }
void void
@ -1988,11 +1988,11 @@ vm_catch_protect(VALUE tag, rb_block_call_func *func, VALUE data,
VALUE val = Qnil; /* OK */ VALUE val = Qnil; /* OK */
rb_control_frame_t *volatile saved_cfp = th->ec->cfp; rb_control_frame_t *volatile saved_cfp = th->ec->cfp;
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
_tag.tag = tag; _tag.tag = tag;
if ((state = TH_EXEC_TAG()) == TAG_NONE) { if ((state = EC_EXEC_TAG()) == TAG_NONE) {
/* call with argc=1, argv = [tag], block = Qnil to insure compatibility */ /* call with argc=1, argv = [tag], block = Qnil to insure compatibility */
val = (*func)(tag, data, 1, (const VALUE *)&tag, Qnil); val = (*func)(tag, data, 1, (const VALUE *)&tag, Qnil);
} }
@ -2002,7 +2002,7 @@ vm_catch_protect(VALUE tag, rb_block_call_func *func, VALUE data,
th->ec->errinfo = Qnil; th->ec->errinfo = Qnil;
state = 0; state = 0;
} }
TH_POP_TAG(); EC_POP_TAG();
if (stateptr) if (stateptr)
*stateptr = state; *stateptr = state;
@ -2021,7 +2021,7 @@ rb_catch_obj(VALUE t, VALUE (*func)(), VALUE data)
enum ruby_tag_type state; enum ruby_tag_type state;
rb_thread_t *th = GET_THREAD(); rb_thread_t *th = GET_THREAD();
VALUE val = vm_catch_protect(t, (rb_block_call_func *)func, data, &state, th); VALUE val = vm_catch_protect(t, (rb_block_call_func *)func, data, &state, th);
if (state) TH_JUMP_TAG(th, state); if (state) EC_JUMP_TAG(th->ec, state);
return val; return val;
} }

View File

@ -43,7 +43,7 @@ threadptr_stack_overflow(rb_thread_t *th, int setup)
rb_ivar_set(mesg, idBt_locations, at); rb_ivar_set(mesg, idBt_locations, at);
} }
th->ec->errinfo = mesg; th->ec->errinfo = mesg;
TH_JUMP_TAG(th, TAG_RAISE); EC_JUMP_TAG(th->ec, TAG_RAISE);
} }
static void static void
@ -59,7 +59,7 @@ rb_threadptr_stack_overflow(rb_thread_t *th, int crit)
if (crit || rb_during_gc()) { if (crit || rb_during_gc()) {
th->ec->raised_flag = RAISED_STACKOVERFLOW; th->ec->raised_flag = RAISED_STACKOVERFLOW;
th->ec->errinfo = th->vm->special_exceptions[ruby_error_stackfatal]; th->ec->errinfo = th->vm->special_exceptions[ruby_error_stackfatal];
TH_JUMP_TAG(th, TAG_RAISE); EC_JUMP_TAG(th->ec, TAG_RAISE);
} }
#ifdef USE_SIGALTSTACK #ifdef USE_SIGALTSTACK
threadptr_stack_overflow(th, TRUE); threadptr_stack_overflow(th, TRUE);

View File

@ -285,11 +285,11 @@ exec_hooks_protected(rb_thread_t *th, rb_hook_list_t *list, const rb_trace_arg_t
/* TODO: Support !RUBY_EVENT_HOOK_FLAG_SAFE hooks */ /* TODO: Support !RUBY_EVENT_HOOK_FLAG_SAFE hooks */
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = TH_EXEC_TAG()) == TAG_NONE) { if ((state = EC_EXEC_TAG()) == TAG_NONE) {
exec_hooks_body(th, list, trace_arg); exec_hooks_body(th, list, trace_arg);
} }
TH_POP_TAG(); EC_POP_TAG();
if (raised) { if (raised) {
rb_threadptr_set_raised(th); rb_threadptr_set_raised(th);
@ -354,7 +354,7 @@ rb_threadptr_exec_event_hooks_orig(rb_trace_arg_t *trace_arg, int pop_p)
} }
rb_vm_pop_frame(th->ec); rb_vm_pop_frame(th->ec);
} }
TH_JUMP_TAG(th, state); EC_JUMP_TAG(th->ec, state);
} }
} }
} }
@ -388,11 +388,11 @@ rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg)
raised = rb_threadptr_reset_raised(th); raised = rb_threadptr_reset_raised(th);
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if ((state = TH_EXEC_TAG()) == TAG_NONE) { if ((state = EC_EXEC_TAG()) == TAG_NONE) {
result = (*func)(arg); result = (*func)(arg);
} }
TH_POP_TAG(); EC_POP_TAG();
if (raised) { if (raised) {
rb_threadptr_set_raised(th); rb_threadptr_set_raised(th);
@ -405,7 +405,7 @@ rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg)
#if defined RUBY_USE_SETJMPEX && RUBY_USE_SETJMPEX #if defined RUBY_USE_SETJMPEX && RUBY_USE_SETJMPEX
RB_GC_GUARD(result); RB_GC_GUARD(result);
#endif #endif
TH_JUMP_TAG(th, state); EC_JUMP_TAG(th->ec, state);
} }
return result; return result;
@ -1600,7 +1600,7 @@ rb_postponed_job_flush(rb_vm_t *vm)
/* mask POSTPONED_JOB dispatch */ /* mask POSTPONED_JOB dispatch */
th->interrupt_mask |= block_mask; th->interrupt_mask |= block_mask;
{ {
TH_PUSH_TAG(th); EC_PUSH_TAG(th->ec);
if (EXEC_TAG() == TAG_NONE) { if (EXEC_TAG() == TAG_NONE) {
int index; int index;
while ((index = vm->postponed_job_index) > 0) { while ((index = vm->postponed_job_index) > 0) {
@ -1610,7 +1610,7 @@ rb_postponed_job_flush(rb_vm_t *vm)
} }
} }
} }
TH_POP_TAG(); EC_POP_TAG();
} }
/* restore POSTPONED_JOB mask */ /* restore POSTPONED_JOB mask */
th->interrupt_mask &= ~(saved_mask ^ block_mask); th->interrupt_mask &= ~(saved_mask ^ block_mask);