From 938910492c8c8b96361e03c84ee13c89732d23ac Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 13 Apr 2015 07:54:39 +0000 Subject: variable.c: ensure * variable.c (rb_autoload_load): prefer rb_ensure than rb_protect for rollback. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50286 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- variable.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'variable.c') diff --git a/variable.c b/variable.c index c78803a55c..a95a3d25ba 100644 --- a/variable.c +++ b/variable.c @@ -1804,13 +1804,22 @@ autoload_require(VALUE arg) return rb_require_safe(ele->feature, ele->safe_level); } +static VALUE +autoload_reset(VALUE arg) +{ + struct autoload_data_i *ele = (struct autoload_data_i *)arg; + if (ele->thread == rb_thread_current()) { + ele->thread = Qnil; + } + return 0; /* ignored */ +} + VALUE rb_autoload_load(VALUE mod, ID id) { VALUE load, result; const char *loading = 0, *src; struct autoload_data_i *ele; - int state = 0; if (!autoload_defined_p(mod, id)) return Qfalse; load = check_autoload_required(mod, id, &loading); @@ -1826,11 +1835,7 @@ rb_autoload_load(VALUE mod, ID id) ele->thread = rb_thread_current(); } /* autoload_data_i can be deleted by another thread while require */ - result = rb_protect(autoload_require, (VALUE)ele, &state); - if (ele->thread == rb_thread_current()) { - ele->thread = Qnil; - } - if (state) rb_jump_tag(state); + result = rb_ensure(autoload_require, (VALUE)ele, autoload_reset, (VALUE)ele); if (RTEST(result)) { /* At the last, move a value defined in autoload to constant table */ -- cgit v1.2.3