ruby-changes:24749
From: nobu <ko1@a...>
Date: Thu, 23 Aug 2012 16:46:24 +0900 (JST)
Subject: [ruby-changes:24749] nobu:r36800 (trunk): load.c: keep encoding of feature name
nobu 2012-08-23 16:46:12 +0900 (Thu, 23 Aug 2012) New Revision: 36800 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36800 Log: load.c: keep encoding of feature name * file.c (rb_find_file_ext_safe, rb_find_file_safe): default to US-ASCII for encdb and transdb. * load.c (search_required): keep encoding of feature name. set loading path to filesystem encoding. [Bug #6377][ruby-core:44750] * ruby.c (add_modules, require_libraries): assume default external encoding as well as ARGV. Modified files: trunk/ChangeLog trunk/file.c trunk/load.c trunk/ruby.c trunk/test/ruby/test_require.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 36799) +++ ChangeLog (revision 36800) @@ -1,3 +1,14 @@ +Thu Aug 23 16:46:10 2012 Nobuyoshi Nakada <nobu@r...> + + * file.c (rb_find_file_ext_safe, rb_find_file_safe): default to + US-ASCII for encdb and transdb. + + * load.c (search_required): keep encoding of feature name. set + loading path to filesystem encoding. [Bug #6377][ruby-core:44750] + + * ruby.c (add_modules, require_libraries): assume default external + encoding as well as ARGV. + Thu Aug 23 16:20:04 2012 Koichi Sasada <ko1@a...> * include/ruby/ruby.h: introduce flonum technique for Index: load.c =================================================================== --- load.c (revision 36799) +++ load.c (revision 36800) @@ -516,7 +516,7 @@ if (ext && !strchr(ext, '/')) { if (IS_RBEXT(ext)) { if (rb_feature_p(ftptr, ext, TRUE, FALSE, &loading)) { - if (loading) *path = rb_str_new2(loading); + if (loading) *path = rb_filesystem_str_new_cstr(loading); return 'r'; } if ((tmp = rb_find_file_safe(fname, safe_level)) != 0) { @@ -529,10 +529,10 @@ } else if (IS_SOEXT(ext)) { if (rb_feature_p(ftptr, ext, FALSE, FALSE, &loading)) { - if (loading) *path = rb_str_new2(loading); + if (loading) *path = rb_filesystem_str_new_cstr(loading); return 's'; } - tmp = rb_str_new(RSTRING_PTR(fname), ext - RSTRING_PTR(fname)); + tmp = rb_str_subseq(fname, 0, ext - RSTRING_PTR(fname)); #ifdef DLEXT2 OBJ_FREEZE(tmp); if (rb_find_file_ext_safe(&tmp, loadable_ext + 1, safe_level)) { @@ -554,7 +554,7 @@ } else if (IS_DLEXT(ext)) { if (rb_feature_p(ftptr, ext, FALSE, FALSE, &loading)) { - if (loading) *path = rb_str_new2(loading); + if (loading) *path = rb_filesystem_str_new_cstr(loading); return 's'; } if ((tmp = rb_find_file_safe(fname, safe_level)) != 0) { @@ -566,7 +566,7 @@ } } else if ((ft = rb_feature_p(ftptr, 0, FALSE, FALSE, &loading)) == 'r') { - if (loading) *path = rb_str_new2(loading); + if (loading) *path = rb_filesystem_str_new_cstr(loading); return 'r'; } tmp = fname; Index: ruby.c =================================================================== --- ruby.c (revision 36799) +++ ruby.c (revision 36800) @@ -465,12 +465,15 @@ add_modules(VALUE *req_list, const char *mod) { VALUE list = *req_list; + VALUE feature; if (!list) { *req_list = list = rb_ary_new(); RBASIC(list)->klass = 0; } - rb_ary_push(list, rb_obj_freeze(rb_str_new2(mod))); + feature = rb_str_new2(mod); + RBASIC(feature)->klass = 0; + rb_ary_push(list, feature); } static void @@ -480,6 +483,7 @@ VALUE self = rb_vm_top_self(); ID require; rb_thread_t *th = GET_THREAD(); + rb_encoding *extenc = rb_default_external_encoding(); int prev_parse_in_eval = th->parse_in_eval; th->parse_in_eval = 0; @@ -487,6 +491,9 @@ CONST_ID(require, "require"); while (list && RARRAY_LEN(list) > 0) { VALUE feature = rb_ary_shift(list); + rb_enc_associate(feature, extenc); + RBASIC(feature)->klass = rb_cString; + OBJ_FREEZE(feature); rb_funcall2(self, require, 1, &feature); } *req_list = 0; Index: test/ruby/test_require.rb =================================================================== --- test/ruby/test_require.rb (revision 36799) +++ test/ruby/test_require.rb (revision 36800) @@ -418,4 +418,21 @@ $".delete(path) tmp.close(true) if tmp end + + def test_loaded_features_encoding + bug6377 = '[ruby-core:44750]' + loadpath = $:.dup + features = $".dup + $".clear + $:.clear + Dir.mktmpdir {|tmp| + $: << tmp + open(File.join(tmp, "foo.rb"), "w") {} + require "foo" + assert_equal(tmp.encoding, $"[0].encoding, bug6377) + } + ensure + $:.replace(loadpath) + $".replace(features) + end end Index: file.c =================================================================== --- file.c (revision 36799) +++ file.c (revision 36800) @@ -5243,6 +5243,7 @@ RBASIC(fname)->klass = 0; fnlen = RSTRING_LEN(fname); tmp = rb_str_tmp_new(MAXPATHLEN + 2); + rb_enc_associate_index(tmp, rb_usascii_encindex()); for (j=0; ext[j]; j++) { rb_str_cat2(fname, ext[j]); for (i = 0; i < RARRAY_LEN(load_path); i++) { @@ -5305,6 +5306,7 @@ long i; tmp = rb_str_tmp_new(MAXPATHLEN + 2); + rb_enc_associate_index(tmp, rb_usascii_encindex()); for (i = 0; i < RARRAY_LEN(load_path); i++) { VALUE str = RARRAY_PTR(load_path)[i]; RB_GC_GUARD(str) = rb_get_path_check(str, safe_level); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/