summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-16 02:11:36 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-16 02:11:36 +0000
commite9ff4a22dfbd07ea6c54179979d937ff739eead3 (patch)
tree03b87b343800f7dd25c718942366d1b0cc48b2f0
parentae5930a892da55dddc8513dde50b0dc65572ca3a (diff)
merge revision(s) 36800: [Backport #6377]
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@37209 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog11
-rw-r--r--file.c2
-rw-r--r--load.c10
-rw-r--r--ruby.c9
-rw-r--r--test/ruby/test_require.rb17
-rw-r--r--version.h2
6 files changed, 44 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 1da985f31e..a287aef04f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Tue Oct 16 10:56:55 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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.
+
Tue Oct 16 10:47:43 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* random.c (random_s_rand): ensure default PRNG is re-initialized
diff --git a/file.c b/file.c
index eead65761b..3036285541 100644
--- a/file.c
+++ b/file.c
@@ -5150,6 +5150,7 @@ rb_find_file_ext_safe(VALUE *filep, const char *const *ext, int safe_level)
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++) {
@@ -5212,6 +5213,7 @@ rb_find_file_safe(VALUE path, int safe_level)
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);
diff --git a/load.c b/load.c
index 13dbff5e96..72ca0ebc3b 100644
--- a/load.c
+++ b/load.c
@@ -498,7 +498,7 @@ search_required(VALUE fname, volatile VALUE *path, int safe_level)
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) {
@@ -511,10 +511,10 @@ search_required(VALUE fname, volatile VALUE *path, int safe_level)
}
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)) {
@@ -536,7 +536,7 @@ search_required(VALUE fname, volatile VALUE *path, int safe_level)
}
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) {
@@ -548,7 +548,7 @@ search_required(VALUE fname, volatile VALUE *path, int safe_level)
}
}
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;
diff --git a/ruby.c b/ruby.c
index 9de719a086..3ddd96c7bb 100644
--- a/ruby.c
+++ b/ruby.c
@@ -476,12 +476,15 @@ static void
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
@@ -492,6 +495,7 @@ require_libraries(VALUE *req_list)
ID require;
rb_thread_t *th = GET_THREAD();
rb_block_t *prev_base_block = th->base_block;
+ rb_encoding *extenc = rb_default_external_encoding();
int prev_parse_in_eval = th->parse_in_eval;
th->base_block = 0;
th->parse_in_eval = 0;
@@ -500,6 +504,9 @@ require_libraries(VALUE *req_list)
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;
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb
index 96b1551da2..9efd828bf2 100644
--- a/test/ruby/test_require.rb
+++ b/test/ruby/test_require.rb
@@ -339,4 +339,21 @@ class TestRequire < Test::Unit::TestCase
[], /\$LOADED_FEATURES is frozen; cannot append feature \(RuntimeError\)$/,
bug3756)
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
diff --git a/version.h b/version.h
index 58e3b12eb7..db4f2c526f 100644
--- a/version.h
+++ b/version.h
@@ -1,5 +1,5 @@
#define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 293
+#define RUBY_PATCHLEVEL 294
#define RUBY_RELEASE_DATE "2012-10-16"
#define RUBY_RELEASE_YEAR 2012