diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-07 07:30:31 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-07 07:30:31 +0000 |
commit | 075d98c7dc0cee294f03ed0ed26e1e8d8876b2b9 (patch) | |
tree | 9e8837ee94ededc62b66b5c4f7a97e9477ba4d0a | |
parent | 8e07edf364398a9843dc939ec7e5ec7acdf62b95 (diff) |
* error.c (rb_load_fail): should honor encoding.
* load.c (load_failed): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | error.c | 27 | ||||
-rw-r--r-- | internal.h | 2 | ||||
-rw-r--r-- | load.c | 4 | ||||
-rw-r--r-- | ruby.c | 2 | ||||
-rw-r--r-- | test/ruby/test_require.rb | 6 |
6 files changed, 30 insertions, 17 deletions
@@ -1,3 +1,9 @@ +Wed Mar 7 16:30:24 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * error.c (rb_load_fail): should honor encoding. + + * load.c (load_failed): ditto. + Wed Mar 7 12:26:25 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> * error.c (rb_load_fail): use path as a string, not char*. @@ -1740,19 +1740,26 @@ rb_raise(VALUE exc, const char *fmt, ...) rb_exc_raise(rb_exc_new3(exc, mesg)); } +NORETURN(static void raise_loaderror(VALUE path, VALUE mesg)); + +static void +raise_loaderror(VALUE path, VALUE mesg) +{ + VALUE err = rb_exc_new3(rb_eLoadError, mesg); + rb_ivar_set(err, rb_intern("@path"), path); + rb_exc_raise(err); +} + void rb_loaderror(const char *fmt, ...) { va_list args; VALUE mesg; - VALUE err; va_start(args, fmt); mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args); va_end(args); - err = rb_exc_new3(rb_eLoadError, mesg); - rb_ivar_set(err, rb_intern("@path"), Qnil); - rb_exc_raise(err); + raise_loaderror(Qnil, mesg); } void @@ -1760,14 +1767,11 @@ rb_loaderror_with_path(VALUE path, const char *fmt, ...) { va_list args; VALUE mesg; - VALUE err; va_start(args, fmt); mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args); va_end(args); - err = rb_exc_new3(rb_eLoadError, mesg); - rb_ivar_set(err, rb_intern("@path"), path); - rb_exc_raise(err); + raise_loaderror(path, mesg); } void @@ -1908,9 +1912,12 @@ rb_sys_warning(const char *fmt, ...) } void -rb_load_fail(VALUE path) +rb_load_fail(VALUE path, const char *err) { - rb_loaderror_with_path(path, "%s -- %s", strerror(errno), RSTRING_PTR(path)); + VALUE mesg = rb_str_buf_new_cstr(err); + rb_str_cat2(mesg, " -- "); + rb_str_append(mesg, path); /* should be ASCII compatible */ + raise_loaderror(path, mesg); } void diff --git a/internal.h b/internal.h index e25062bc2f..f5a463e83b 100644 --- a/internal.h +++ b/internal.h @@ -116,7 +116,7 @@ VALUE rb_iseq_clone(VALUE iseqval, VALUE newcbase); /* load.c */ VALUE rb_get_load_path(void); -NORETURN(void rb_load_fail(VALUE)); +NORETURN(void rb_load_fail(VALUE, const char*)); /* math.c */ VALUE rb_math_atan2(VALUE, VALUE); @@ -588,12 +588,10 @@ search_required(VALUE fname, volatile VALUE *path, int safe_level) return type ? 's' : 'r'; } -void rb_loaderror_with_path(VALUE path, const char *fmt, ...); - static void load_failed(VALUE fname) { - rb_loaderror_with_path(fname, "cannot load such file -- %s", RSTRING_PTR(fname)); + rb_load_fail(fname, "cannot load such file"); } static VALUE @@ -1524,7 +1524,7 @@ load_file_internal(VALUE arg) } #endif if ((fd = rb_cloexec_open(fname, mode, 0)) < 0) { - rb_load_fail(fname_v); + rb_load_fail(fname_v, strerror(errno)); } rb_update_max_fd(fd); diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb index e0e885dce6..de99fbdff4 100644 --- a/test/ruby/test_require.rb +++ b/test/ruby/test_require.rb @@ -50,8 +50,10 @@ class TestRequire < Test::Unit::TestCase def test_require_nonascii bug3758 = '[ruby-core:31915]' - e = assert_raise(LoadError, bug3758) {require "\u{221e}"} - assert_match(/\u{221e}\z/, e.message, bug3758) + ["\u{221e}", "\x82\xa0".force_encoding("cp932")].each do |path| + e = assert_raise(LoadError, bug3758) {require path} + assert_match(/#{path}\z/, e.message, bug3758) + end end def test_require_path_home_1 |