Skip to content

Commit

Permalink
load.c: reduce EXEC_TAGs
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nobu committed Jul 18, 2015
1 parent e9e08a5 commit 1998039
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Sat Jul 18 20:44:56 2015 Nobuyoshi Nakada <[email protected]>

* 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.

Sat Jul 18 19:52:17 2015 Nobuyoshi Nakada <[email protected]>

* gc.c (run_finalizer): set and restore safe level here to reduce
Expand Down
35 changes: 26 additions & 9 deletions load.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 1998039

Please sign in to comment.