aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--encoding.c4
-rw-r--r--test/ruby/test_encoding.rb9
3 files changed, 17 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 4f45a6e0ca..e04fb1c11d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Oct 21 23:57:53 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * encoding.c (load_encoding): should preserve outer errinfo, so that
+ expected exception may not be lost. [ruby-core:57949] [Bug #9038]
+
Sun Oct 20 15:41:22 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (rb_io_reopen): create a new, temporary FD via rb_sysopen and
diff --git a/encoding.c b/encoding.c
index 4793e67375..b073311c8d 100644
--- a/encoding.c
+++ b/encoding.c
@@ -623,6 +623,7 @@ load_encoding(const char *name)
VALUE enclib = rb_sprintf("enc/%s.so", name);
VALUE verbose = ruby_verbose;
VALUE debug = ruby_debug;
+ VALUE errinfo;
VALUE loaded;
char *s = RSTRING_PTR(enclib) + 4, *e = RSTRING_END(enclib) - 3;
int idx;
@@ -636,10 +637,11 @@ load_encoding(const char *name)
OBJ_FREEZE(enclib);
ruby_verbose = Qfalse;
ruby_debug = Qfalse;
+ errinfo = rb_errinfo();
loaded = rb_protect(require_enc, enclib, 0);
ruby_verbose = verbose;
ruby_debug = debug;
- rb_set_errinfo(Qnil);
+ rb_set_errinfo(errinfo);
if (NIL_P(loaded)) return -1;
if ((idx = rb_enc_registered(name)) < 0) return -1;
if (enc_autoload_p(enc_table.list[idx].enc)) return -1;
diff --git a/test/ruby/test_encoding.rb b/test/ruby/test_encoding.rb
index c1ded6c741..0a5a9ce197 100644
--- a/test/ruby/test_encoding.rb
+++ b/test/ruby/test_encoding.rb
@@ -108,4 +108,13 @@ class TestEncoding < Test::Unit::TestCase
asc = "b".force_encoding(Encoding::US_ASCII)
assert_equal(Encoding::ASCII_8BIT, Encoding.compatible?(bin, asc))
end
+
+ def test_errinfo_after_autoload
+ bug9038 = '[ruby-core:57949] [Bug #9038]'
+ assert_separately(%w[--disable=gems], <<-"end;")
+ assert_raise_with_message(SyntaxError, /unknown regexp option - Q/, #{bug9038.dump}) {
+ eval("/regexp/sQ")
+ }
+ end;
+ end
end