ruby-changes:22895
From: nobu <ko1@a...>
Date: Wed, 7 Mar 2012 16:30:44 +0900 (JST)
Subject: [ruby-changes:22895] nobu:r34944 (trunk): * error.c (rb_load_fail): should honor encoding.
nobu 2012-03-07 16:30:31 +0900 (Wed, 07 Mar 2012) New Revision: 34944 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34944 Log: * error.c (rb_load_fail): should honor encoding. * load.c (load_failed): ditto. Modified files: trunk/ChangeLog trunk/error.c trunk/internal.h trunk/load.c trunk/ruby.c trunk/test/ruby/test_require.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 34943) +++ ChangeLog (revision 34944) @@ -1,3 +1,9 @@ +Wed Mar 7 16:30:24 2012 Nobuyoshi Nakada <nobu@r...> + + * error.c (rb_load_fail): should honor encoding. + + * load.c (load_failed): ditto. + Wed Mar 7 12:26:25 2012 Nobuyoshi Nakada <nobu@r...> * error.c (rb_load_fail): use path as a string, not char*. Index: load.c =================================================================== --- load.c (revision 34943) +++ load.c (revision 34944) @@ -588,12 +588,10 @@ 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 Index: error.c =================================================================== --- error.c (revision 34943) +++ error.c (revision 34944) @@ -1740,19 +1740,26 @@ 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 @@ { 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 @@ } 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 Index: internal.h =================================================================== --- internal.h (revision 34943) +++ internal.h (revision 34944) @@ -116,7 +116,7 @@ /* 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); Index: ruby.c =================================================================== --- ruby.c (revision 34943) +++ ruby.c (revision 34944) @@ -1524,7 +1524,7 @@ } #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); Index: test/ruby/test_require.rb =================================================================== --- test/ruby/test_require.rb (revision 34943) +++ test/ruby/test_require.rb (revision 34944) @@ -50,8 +50,10 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/