mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
eval.c: preserve errinfo
* eval.c (rb_ensure): preserve errinfo accross ensure proc before JUMP_TAG(). [ruby-core:52022] [Bug #7802] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
49c5a3da6f
commit
98932f5150
4 changed files with 66 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Fri Feb 8 16:09:45 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* eval.c (rb_ensure): preserve errinfo accross ensure proc before
|
||||||
|
JUMP_TAG(). [ruby-core:52022] [Bug #7802]
|
||||||
|
|
||||||
Fri Feb 8 16:08:28 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Fri Feb 8 16:08:28 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* test/ruby/envutil.rb (assert_separately): check also terminating
|
* test/ruby/envutil.rb (assert_separately): check also terminating
|
||||||
|
|
4
eval.c
4
eval.c
|
@ -805,6 +805,8 @@ rb_ensure(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*e_proc)(ANYARGS), VALUE
|
||||||
{
|
{
|
||||||
int state;
|
int state;
|
||||||
volatile VALUE result = Qnil;
|
volatile VALUE result = Qnil;
|
||||||
|
volatile VALUE errinfo;
|
||||||
|
rb_thread_t *const th = GET_THREAD();
|
||||||
|
|
||||||
PUSH_TAG();
|
PUSH_TAG();
|
||||||
if ((state = EXEC_TAG()) == 0) {
|
if ((state = EXEC_TAG()) == 0) {
|
||||||
|
@ -813,7 +815,9 @@ rb_ensure(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*e_proc)(ANYARGS), VALUE
|
||||||
POP_TAG();
|
POP_TAG();
|
||||||
/* TODO: fix me */
|
/* TODO: fix me */
|
||||||
/* retval = prot_tag ? prot_tag->retval : Qnil; */ /* save retval */
|
/* retval = prot_tag ? prot_tag->retval : Qnil; */ /* save retval */
|
||||||
|
errinfo = th->errinfo;
|
||||||
(*e_proc) (data2);
|
(*e_proc) (data2);
|
||||||
|
th->errinfo = errinfo;
|
||||||
if (state)
|
if (state)
|
||||||
JUMP_TAG(state);
|
JUMP_TAG(state);
|
||||||
return result;
|
return result;
|
||||||
|
|
25
ext/-test-/exception/ensured.c
Normal file
25
ext/-test-/exception/ensured.c
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#include <ruby.h>
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
begin(VALUE object)
|
||||||
|
{
|
||||||
|
return rb_funcall(object, rb_intern("try_method"), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
ensure(VALUE object)
|
||||||
|
{
|
||||||
|
return rb_funcall(object, rb_intern("ensured_method"), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
ensured(VALUE module, VALUE object)
|
||||||
|
{
|
||||||
|
return rb_ensure(begin, object, ensure, object);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Init_ensured(VALUE klass)
|
||||||
|
{
|
||||||
|
rb_define_module_function(klass, "ensured", ensured, 1);
|
||||||
|
}
|
32
test/-ext-/exception/test_ensured.rb
Normal file
32
test/-ext-/exception/test_ensured.rb
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
require 'test/unit'
|
||||||
|
require_relative '../../ruby/envutil'
|
||||||
|
|
||||||
|
module Bug
|
||||||
|
class Bug7802 < RuntimeError
|
||||||
|
end
|
||||||
|
|
||||||
|
class TestException < Test::Unit::TestCase
|
||||||
|
def test_ensured
|
||||||
|
assert_separately([], <<-'end;') # do
|
||||||
|
|
||||||
|
require '-test-/exception'
|
||||||
|
|
||||||
|
module Bug
|
||||||
|
class Bug7802 < RuntimeError
|
||||||
|
def try_method
|
||||||
|
raise self
|
||||||
|
end
|
||||||
|
|
||||||
|
def ensured_method
|
||||||
|
[1].detect {|i| true}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_raise(Bug::Bug7802, '[ruby-core:52022] [Bug #7802]') {
|
||||||
|
Bug::Exception.ensured(Bug::Bug7802.new)
|
||||||
|
}
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue