From 9e9d8306356a134e76622fced5b063095b8d9086 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 18 Jul 2015 11:44:59 +0000 Subject: load.c: reduce EXEC_TAGs * load.c (rb_load_internal0): do not raise any exceptions but return the result tag state. * load.c (rb_load_protect): reduce nested EXEC_TAGs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- load.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'load.c') diff --git a/load.c b/load.c index 91122c73cc..8ce5a2fadb 100644 --- a/load.c +++ b/load.c @@ -573,7 +573,7 @@ rb_provide(const char *feature) NORETURN(static void load_failed(VALUE)); -static inline void +static int rb_load_internal0(rb_thread_t *th, VALUE fname, int wrap) { int state; @@ -623,42 +623,59 @@ rb_load_internal0(rb_thread_t *th, VALUE fname, int wrap) if (!loaded && !FIXNUM_P(th->errinfo)) { /* an error on loading don't include INT2FIX(TAG_FATAL) see r35625 */ - rb_exc_raise(th->errinfo); + return TAG_RAISE; } if (state) { - rb_vm_jump_tag_but_local_jump(state); + VALUE exc = rb_vm_make_jump_tag_but_local_jump(state, Qundef); + if (NIL_P(exc)) return state; + th->errinfo = exc; + return TAG_RAISE; } if (!NIL_P(th->errinfo)) { /* exception during load */ - rb_exc_raise(th->errinfo); + return TAG_RAISE; } + return state; } static void rb_load_internal(VALUE fname, int wrap) { - rb_load_internal0(GET_THREAD(), fname, wrap); + rb_thread_t *curr_th = GET_THREAD(); + int state = rb_load_internal0(curr_th, fname, wrap); + if (state) { + if (state == TAG_RAISE) rb_exc_raise(curr_th->errinfo); + JUMP_TAG(state); + } } -void -rb_load(VALUE fname, int wrap) +static VALUE +file_to_load(VALUE fname) { VALUE tmp = rb_find_file(FilePathValue(fname)); if (!tmp) load_failed(fname); - rb_load_internal(tmp, wrap); + return tmp; +} + +void +rb_load(VALUE fname, int wrap) +{ + rb_load_internal(file_to_load(fname), wrap); } void rb_load_protect(VALUE fname, int wrap, int *state) { int status; + volatile VALUE path = 0; PUSH_TAG(); if ((status = EXEC_TAG()) == 0) { - rb_load(fname, wrap); + path = file_to_load(fname); } POP_TAG(); + if (!status) status = rb_load_internal0(GET_THREAD(), path, wrap); if (state) *state = status; } -- cgit v1.2.3