diff --git a/ChangeLog b/ChangeLog index a5abd3d37f..1e01c93fa7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Fri Jan 18 09:22:07 2008 Yukihiro Matsumoto + + * parse.y (parser_initialize): explicitly call rb_ascii8bit_encoding(). + + * parse.y (parser_prepare): lex_input may not be have encoding (e.g. IO). + + * parse.y (rb_parser_compile_string): set encoding from input string. + + * encoding.c (rb_enc_find_index): use ASCII-8BIT if loading known + encoding failed. + Fri Jan 18 07:06:25 2008 Yukihiro Matsumoto * io.c (Init_IO): stdin/stdout may not be duplex. diff --git a/encoding.c b/encoding.c index 1453b267b2..38d2cf2c90 100644 --- a/encoding.c +++ b/encoding.c @@ -498,6 +498,12 @@ rb_enc_find_index(const char *name) } else { i = load_encoding(name); + enc = rb_enc_from_index(i); + if (!enc->precise_mbc_enc_len) { + rb_warn("failed to load encoding (%s); use ASCII-8BIT instead", + name); + return 0; + } } } return i; diff --git a/parse.y b/parse.y index cf522789dd..ca7cb6b13f 100644 --- a/parse.y +++ b/parse.y @@ -4764,6 +4764,7 @@ rb_parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int lin lex_gets = lex_get_str; lex_gets_ptr = 0; lex_input = s; + parser->enc = rb_enc_get(s); lex_pbeg = lex_p = lex_pend = 0; compile_for_eval = rb_parse_in_eval(); @@ -5956,7 +5957,6 @@ parser_prepare(struct parser_params *parser) return; } pushback(c); - parser->enc = rb_enc_get(lex_input); } #define IS_ARG() (lex_state == EXPR_ARG || lex_state == EXPR_CMDARG) @@ -9192,7 +9192,7 @@ parser_initialize(struct parser_params *parser) #ifdef YYMALLOC parser->heap = NULL; #endif - parser->enc = rb_enc_from_index(0); + parser->enc = rb_ascii8bit_encoding(); } extern void rb_mark_source_filename(char *);