summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-13 07:54:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-13 07:54:39 +0000
commit938910492c8c8b96361e03c84ee13c89732d23ac (patch)
tree7f9ada6c6c151dd3f718d8e2708c9ba0f0ad0954
parent41d87e0a91d890bea7c25361ba068db8b8ba2fd5 (diff)
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
-rw-r--r--variable.c17
1 files changed, 11 insertions, 6 deletions
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 */