From 5e62997245434daff576be3107086a7e81e46408 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 23 Dec 2008 15:13:18 +0000 Subject: * string.c (rb_external_str_new_with_enc): set ASCII-8BIT if encoding is US-ASCII and string contains 8bit characters. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20952 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 715bb07e4d..c32f12d5b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -167,6 +167,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 f99277ec97..76bf51a0a3 100644 --- a/parse.y +++ b/parse.y @@ -7923,13 +7923,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 9db82d4a21..7056c1ec8e 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 v1.2.3