And pass rb_execution_context_t as an argument.
This commit is contained in:
Nobuyoshi Nakada 2019-08-12 17:44:30 +09:00
Родитель aac4d9d6c7
Коммит 0c2d81dada
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4BC7D6DF58D8DF60
10 изменённых файлов: 42 добавлений и 47 удалений

39
eval.c
Просмотреть файл

@ -25,6 +25,7 @@
#endif #endif
NORETURN(void rb_raise_jump(VALUE, VALUE)); NORETURN(void rb_raise_jump(VALUE, VALUE));
void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec);
VALUE rb_eLocalJumpError; VALUE rb_eLocalJumpError;
VALUE rb_eSysStackError; VALUE rb_eSysStackError;
@ -109,17 +110,18 @@ ruby_init(void)
void * void *
ruby_options(int argc, char **argv) ruby_options(int argc, char **argv)
{ {
rb_execution_context_t *ec = GET_EC();
enum ruby_tag_type state; enum ruby_tag_type state;
void *volatile iseq = 0; void *volatile iseq = 0;
ruby_init_stack((void *)&iseq); ruby_init_stack((void *)&iseq);
EC_PUSH_TAG(GET_EC()); EC_PUSH_TAG(ec);
if ((state = EC_EXEC_TAG()) == TAG_NONE) { if ((state = EC_EXEC_TAG()) == TAG_NONE) {
SAVE_ROOT_JMPBUF(GET_THREAD(), iseq = ruby_process_options(argc, argv)); SAVE_ROOT_JMPBUF(GET_THREAD(), iseq = ruby_process_options(argc, argv));
} }
else { else {
rb_clear_trace_func(); rb_ec_clear_current_thread_trace_func(ec);
state = error_handle(state); state = error_handle(ec, state);
iseq = (void *)INT2FIX(state); iseq = (void *)INT2FIX(state);
} }
EC_POP_TAG(); EC_POP_TAG();
@ -127,23 +129,23 @@ ruby_options(int argc, char **argv)
} }
static void static void
ruby_finalize_0(void) rb_ec_teardown(rb_execution_context_t *ec)
{ {
EC_PUSH_TAG(GET_EC()); EC_PUSH_TAG(ec);
if (EC_EXEC_TAG() == TAG_NONE) { if (EC_EXEC_TAG() == TAG_NONE) {
rb_trap_exit(); rb_vm_trap_exit(rb_ec_vm_ptr(ec));
} }
EC_POP_TAG(); EC_POP_TAG();
rb_exec_end_proc(); rb_ec_exec_end_proc(ec);
rb_clear_trace_func(); rb_ec_clear_current_thread_trace_func(ec);
} }
static void static void
ruby_finalize_1(void) rb_ec_finalize(rb_execution_context_t *ec)
{ {
ruby_sig_finalize(); ruby_sig_finalize();
GET_EC()->errinfo = Qnil; ec->errinfo = Qnil;
rb_gc_call_finalizer_at_exit(); rb_objspace_call_finalizer(rb_ec_vm_ptr(ec)->objspace);
} }
/** Runs the VM finalization processes. /** Runs the VM finalization processes.
@ -156,8 +158,9 @@ ruby_finalize_1(void)
void void
ruby_finalize(void) ruby_finalize(void)
{ {
ruby_finalize_0(); rb_execution_context_t *ec = GET_EC();
ruby_finalize_1(); rb_ec_teardown(ec);
rb_ec_finalize(ec);
} }
/** Destructs the VM. /** Destructs the VM.
@ -192,7 +195,7 @@ ruby_cleanup(volatile int ex)
rb_set_safe_level_force(0); rb_set_safe_level_force(0);
ruby_init_stack(&errs[STACK_UPPER(errs, 0, 1)]); ruby_init_stack(&errs[STACK_UPPER(errs, 0, 1)]);
SAVE_ROOT_JMPBUF(th, ruby_finalize_0()); SAVE_ROOT_JMPBUF(th, rb_ec_teardown(th->ec));
step_1: step++; step_1: step++;
/* protect from Thread#raise */ /* protect from Thread#raise */
@ -209,7 +212,7 @@ ruby_cleanup(volatile int ex)
if (ex == 0) ex = state; if (ex == 0) ex = state;
} }
th->ec->errinfo = errs[1]; th->ec->errinfo = errs[1];
sysex = error_handle(ex); sysex = error_handle(th->ec, ex);
state = 0; state = 0;
for (nerr = 0; nerr < numberof(errs); ++nerr) { for (nerr = 0; nerr < numberof(errs); ++nerr) {
@ -236,13 +239,13 @@ ruby_cleanup(volatile int ex)
mjit_finish(true); // We still need ISeqs here. mjit_finish(true); // We still need ISeqs here.
ruby_finalize_1(); rb_ec_finalize(th->ec);
/* 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(th);
EC_POP_TAG(); EC_POP_TAG();
rb_thread_stop_timer_thread(); rb_thread_stop_timer_thread();
ruby_vm_destruct(GET_VM()); ruby_vm_destruct(th->vm);
if (state) ruby_default_signal(state); if (state) ruby_default_signal(state);
return sysex; return sysex;

Просмотреть файл

@ -429,10 +429,9 @@ sysexit_status(VALUE err)
rb_bug("Unknown longjmp status %d", status) rb_bug("Unknown longjmp status %d", status)
static int static int
error_handle(int ex) error_handle(rb_execution_context_t *ec, int ex)
{ {
int status = EXIT_FAILURE; int status = EXIT_FAILURE;
rb_execution_context_t *ec = GET_EC();
if (rb_ec_set_raised(ec)) if (rb_ec_set_raised(ec))
return EXIT_FAILURE; return EXIT_FAILURE;

Просмотреть файл

@ -107,11 +107,10 @@ exec_end_procs_chain(struct end_proc_data *volatile *procs, VALUE *errp)
} }
} }
void static void
rb_exec_end_proc(void) rb_ec_exec_end_proc(rb_execution_context_t * ec)
{ {
enum ruby_tag_type state; enum ruby_tag_type state;
rb_execution_context_t * volatile ec = GET_EC();
volatile VALUE errinfo = ec->errinfo; volatile VALUE errinfo = ec->errinfo;
EC_PUSH_TAG(ec); EC_PUSH_TAG(ec);
@ -122,7 +121,7 @@ rb_exec_end_proc(void)
} }
else { else {
EC_TMPPOP_TAG(); EC_TMPPOP_TAG();
error_handle(state); error_handle(ec, state);
if (!NIL_P(ec->errinfo)) errinfo = ec->errinfo; if (!NIL_P(ec->errinfo)) errinfo = ec->errinfo;
EC_REPUSH_TAG(); EC_REPUSH_TAG();
goto again; goto again;

13
gc.c
Просмотреть файл

@ -847,7 +847,6 @@ void rb_vm_update_references(void *ptr);
void rb_gcdebug_print_obj_condition(VALUE obj); void rb_gcdebug_print_obj_condition(VALUE obj);
static void rb_objspace_call_finalizer(rb_objspace_t *objspace);
static VALUE define_final0(VALUE obj, VALUE block); static VALUE define_final0(VALUE obj, VALUE block);
static void negative_size_allocation_error(const char *); static void negative_size_allocation_error(const char *);
@ -3231,20 +3230,14 @@ force_chain_object(st_data_t key, st_data_t val, st_data_t arg)
} }
void void
rb_gc_call_finalizer_at_exit(void)
{
#if RGENGC_CHECK_MODE >= 2
gc_verify_internal_consistency(Qnil);
#endif
rb_objspace_call_finalizer(&rb_objspace);
}
static void
rb_objspace_call_finalizer(rb_objspace_t *objspace) rb_objspace_call_finalizer(rb_objspace_t *objspace)
{ {
RVALUE *p, *pend; RVALUE *p, *pend;
size_t i; size_t i;
#if RGENGC_CHECK_MODE >= 2
gc_verify_internal_consistency(Qnil);
#endif
gc_rest(objspace); gc_rest(objspace);
if (ATOMIC_EXCHANGE(finalizing, 1)) return; if (ATOMIC_EXCHANGE(finalizing, 1)) return;

Просмотреть файл

@ -36,15 +36,25 @@ DECLARE_DEPRECATED_FEATURE(2.2, rb_frame_pop);
/* eval.c */ /* eval.c */
NORETURN(ERRORFUNC(("internal function"), void rb_frozen_class_p(VALUE))); NORETURN(ERRORFUNC(("internal function"), void rb_frozen_class_p(VALUE)));
DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_exec_end_proc);
/* error.c */ /* error.c */
DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_compile_error); DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_compile_error);
DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_compile_error_with_enc); DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_compile_error_with_enc);
DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_compile_error_append); DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_compile_error_append);
/* gc.c */
DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_gc_call_finalizer_at_exit);
/* signal.c */
DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_trap_exit);
/* struct.c */ /* struct.c */
DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_struct_ptr); DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_struct_ptr);
/* thread.c */
DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_clear_trace_func);
/* variable.c */ /* variable.c */
DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_generic_ivar_table); DECLARE_DEPRECATED_INTERNAL_FEATURE(rb_generic_ivar_table);
NORETURN(ERRORFUNC(("internal function"), VALUE rb_mod_const_missing(VALUE, VALUE))); NORETURN(ERRORFUNC(("internal function"), VALUE rb_mod_const_missing(VALUE, VALUE)));

Просмотреть файл

@ -461,7 +461,6 @@ int rb_mod_method_arity(VALUE, ID);
int rb_obj_method_arity(VALUE, ID); int rb_obj_method_arity(VALUE, ID);
VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*); VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*);
void rb_set_end_proc(void (*)(VALUE), VALUE); void rb_set_end_proc(void (*)(VALUE), VALUE);
void rb_exec_end_proc(void);
void rb_thread_schedule(void); void rb_thread_schedule(void);
void rb_thread_wait_fd(int); void rb_thread_wait_fd(int);
int rb_thread_fd_writable(int); int rb_thread_fd_writable(int);
@ -520,7 +519,6 @@ VALUE rb_gc_location(VALUE);
void rb_gc_force_recycle(VALUE); void rb_gc_force_recycle(VALUE);
void rb_gc(void); void rb_gc(void);
void rb_gc_copy_finalizer(VALUE,VALUE); void rb_gc_copy_finalizer(VALUE,VALUE);
void rb_gc_call_finalizer_at_exit(void);
VALUE rb_gc_enable(void); VALUE rb_gc_enable(void);
VALUE rb_gc_disable(void); VALUE rb_gc_disable(void);
VALUE rb_gc_start(void); VALUE rb_gc_start(void);
@ -719,7 +717,6 @@ VALUE rb_f_kill(int, const VALUE*);
#define posix_signal ruby_posix_signal #define posix_signal ruby_posix_signal
RETSIGTYPE (*posix_signal(int, RETSIGTYPE (*)(int)))(int); RETSIGTYPE (*posix_signal(int, RETSIGTYPE (*)(int)))(int);
#endif #endif
void rb_trap_exit(void);
const char *ruby_signal_name(int); const char *ruby_signal_name(int);
void ruby_default_signal(int); void ruby_default_signal(int);
/* sprintf.c */ /* sprintf.c */

Просмотреть файл

@ -2204,7 +2204,6 @@ struct timeval rb_time_timeval(VALUE);
VALUE rb_obj_is_mutex(VALUE obj); VALUE rb_obj_is_mutex(VALUE obj);
VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg); VALUE rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg);
void rb_thread_execute_interrupts(VALUE th); void rb_thread_execute_interrupts(VALUE th);
void rb_clear_trace_func(void);
VALUE rb_get_coverages(void); VALUE rb_get_coverages(void);
int rb_get_coverage_mode(void); int rb_get_coverage_mode(void);
VALUE rb_default_coverage(int); VALUE rb_default_coverage(int);

Просмотреть файл

@ -1091,9 +1091,8 @@ signal_exec(VALUE cmd, int safe, int sig)
} }
void void
rb_trap_exit(void) rb_vm_trap_exit(rb_vm_t *vm)
{ {
rb_vm_t *vm = GET_VM();
VALUE trap_exit = vm->trap_list.cmd[0]; VALUE trap_exit = vm->trap_list.cmd[0];
if (trap_exit) { if (trap_exit) {

Просмотреть файл

@ -582,6 +582,7 @@ typedef struct rb_at_exit_list {
struct rb_objspace; struct rb_objspace;
struct rb_objspace *rb_objspace_alloc(void); struct rb_objspace *rb_objspace_alloc(void);
void rb_objspace_free(struct rb_objspace *); void rb_objspace_free(struct rb_objspace *);
void rb_objspace_call_finalizer(struct rb_objspace *);
typedef struct rb_hook_list_struct { typedef struct rb_hook_list_struct {
struct rb_event_hook_struct *hooks; struct rb_event_hook_struct *hooks;
@ -1918,6 +1919,8 @@ rb_exec_event_hook_script_compiled(rb_execution_context_t *ec, const rb_iseq_t *
rb_ary_new_from_args(2, eval_script, (VALUE)iseq)); rb_ary_new_from_args(2, eval_script, (VALUE)iseq));
} }
void rb_vm_trap_exit(rb_vm_t *vm);
RUBY_SYMBOL_EXPORT_BEGIN RUBY_SYMBOL_EXPORT_BEGIN
int rb_thread_check_trap_pending(void); int rb_thread_check_trap_pending(void);

Просмотреть файл

@ -269,13 +269,6 @@ rb_remove_event_hook_with_data(rb_event_hook_func_t func, VALUE data)
return remove_event_hook(GET_EC(), NULL, func, data); return remove_event_hook(GET_EC(), NULL, func, data);
} }
void
rb_clear_trace_func(void)
{
rb_execution_context_t *ec = GET_EC();
rb_threadptr_remove_event_hook(ec, MATCH_ANY_FILTER_TH, 0, Qundef);
}
void void
rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec) rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec)
{ {