1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2015-04-13 07:54:39 +00:00
parent 41d87e0a91
commit 938910492c

View file

@ -1804,13 +1804,22 @@ autoload_require(VALUE arg)
return rb_require_safe(ele->feature, ele->safe_level); 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 VALUE
rb_autoload_load(VALUE mod, ID id) rb_autoload_load(VALUE mod, ID id)
{ {
VALUE load, result; VALUE load, result;
const char *loading = 0, *src; const char *loading = 0, *src;
struct autoload_data_i *ele; struct autoload_data_i *ele;
int state = 0;
if (!autoload_defined_p(mod, id)) return Qfalse; if (!autoload_defined_p(mod, id)) return Qfalse;
load = check_autoload_required(mod, id, &loading); load = check_autoload_required(mod, id, &loading);
@ -1826,11 +1835,7 @@ rb_autoload_load(VALUE mod, ID id)
ele->thread = rb_thread_current(); ele->thread = rb_thread_current();
} }
/* autoload_data_i can be deleted by another thread while require */ /* autoload_data_i can be deleted by another thread while require */
result = rb_protect(autoload_require, (VALUE)ele, &state); result = rb_ensure(autoload_require, (VALUE)ele, autoload_reset, (VALUE)ele);
if (ele->thread == rb_thread_current()) {
ele->thread = Qnil;
}
if (state) rb_jump_tag(state);
if (RTEST(result)) { if (RTEST(result)) {
/* At the last, move a value defined in autoload to constant table */ /* At the last, move a value defined in autoload to constant table */