From 31c163e4c8ad926076d90005ad18f4e964cc9c7e Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 11 Dec 2008 04:17:10 +0000 Subject: [PATCH] * encoding.c (rb_enc_set_default_internal): defines internal encoding as nil. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 +++++++- encoding.c | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index aa2f1806c7..8ba678d1c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -Thu Dec 11 11:51:36 2008 Nobuyoshi Nakada +Thu Dec 11 13:17:04 2008 Nobuyoshi Nakada + + * encoding.c (rb_enc_set_default_internal): defines internal + encoding as nil. * encoding.c (rb_locale_encoding): removed Encoding::LOCALE. @@ -6,6 +9,9 @@ Thu Dec 11 11:51:36 2008 Nobuyoshi Nakada * encoding.c (rb_enc_set_default_internal): ditto. + * encoding.c (rb_enc_set_default_internal): defines internal + encoding as nil. + Thu Dec 11 11:11:03 2008 Nobuyoshi Nakada * include/ruby/st.h (size_t): needs stddef.h or stdlib.h. diff --git a/encoding.c b/encoding.c index d92a925aa0..eb52f83759 100644 --- a/encoding.c +++ b/encoding.c @@ -38,6 +38,7 @@ static struct { void rb_enc_init(void); #define ENCODING_COUNT ENCINDEX_BUILTIN_MAX +#define UNSPECIFIED_ENCODING INT_MAX #define enc_autoload_p(enc) (!rb_enc_mbmaxlen(enc)) @@ -507,7 +508,12 @@ rb_enc_find_index(const char *name) if (i < 0) { i = load_encoding(name); } - else if (enc_autoload_p(enc = rb_enc_from_index(i))) { + else if (!(enc = rb_enc_from_index(i))) { + if (i != UNSPECIFIED_ENCODING) { + rb_raise(rb_eArgError, "encoding %s is not registered", name); + } + } + else if (enc_autoload_p(enc)) { if (enc_autoload(enc) < 0) { rb_warn("failed to load encoding (%s); use ASCII-8BIT instead", name); @@ -1111,6 +1117,8 @@ rb_enc_set_default_internal(VALUE encoding) if (NIL_P(encoding)) { default_internal_index = -1; default_internal = 0; + st_insert(enc_table.names, (st_data_t)strdup("internal"), + (st_data_t)UNSPECIFIED_ENCODING); return; }