From 5b68a0c6e155827d23ec55b41fbea9219883750d Mon Sep 17 00:00:00 2001 From: yugui Date: Fri, 26 Dec 2008 11:16:35 +0000 Subject: merges r20952 from trunk into ruby_1_9_1. * string.c (rb_external_str_new_with_enc): set ASCII-8BIT if encoding is US-ASCII and string contains 8bit characters. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@21072 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ parse.y | 9 ++------- string.c | 5 +++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index b78f25a57..b65b5b590 100644 --- a/ChangeLog +++ b/ChangeLog @@ -340,6 +340,11 @@ Mon Dec 22 18:00:36 2008 Hidetoshi NAGAI * ext/tk/tcltklib.c: fix wrong flag value. +Mon Dec 22 14:35:59 2008 Yukihiro Matsumoto + + * string.c (rb_external_str_new_with_enc): set ASCII-8BIT if + encoding is US-ASCII and string contains 8bit characters. + Mon Dec 22 12:26:18 2008 Nobuyoshi Nakada * cygwin/GNUmakefile.in (rubydll.def), win32/mkexports.rb diff --git a/parse.y b/parse.y index 843f14fda..29b60c953 100644 --- a/parse.y +++ b/parse.y @@ -7931,13 +7931,8 @@ gettable_gen(struct parser_params *parser, ID id) return NEW_FALSE(); } else if (id == keyword__FILE__) { - VALUE str = rb_external_str_new_with_enc(ruby_sourcefile, strlen(ruby_sourcefile), - rb_filesystem_encoding()); - if (rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT && - ENCODING_GET(str) == rb_usascii_encindex()) { - rb_enc_associate(str, rb_ascii8bit_encoding()); - } - return NEW_STR(str); + return NEW_STR(rb_external_str_new_with_enc(ruby_sourcefile, strlen(ruby_sourcefile), + rb_filesystem_encoding())); } else if (id == keyword__LINE__) { return NEW_LIT(INT2FIX(ruby_sourceline)); diff --git a/string.c b/string.c index c1f14a852..236980e25 100644 --- a/string.c +++ b/string.c @@ -538,6 +538,11 @@ rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *eenc) VALUE str; str = rb_tainted_str_new(ptr, len); + if (rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT && + eenc == rb_usascii_encoding()) { + rb_enc_associate(str, rb_ascii8bit_encoding()); + return str; + } rb_enc_associate(str, eenc); return rb_str_conv_enc(str, eenc, rb_default_internal_encoding()); } -- cgit