ruby-changes:3618
From: ko1@a...
Date: Fri, 18 Jan 2008 12:25:42 +0900 (JST)
Subject: [ruby-changes:3618] nobu - Ruby:r15107 (trunk): * encoding.c (load_encoding): check if successfully loaded.
nobu 2008-01-18 12:25:15 +0900 (Fri, 18 Jan 2008)
New Revision: 15107
Modified files:
trunk/ChangeLog
trunk/encoding.c
Log:
* encoding.c (load_encoding): check if successfully loaded.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15107&r2=15106&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/encoding.c?r1=15107&r2=15106&diff_format=u
Index: encoding.c
===================================================================
--- encoding.c (revision 15106)
+++ encoding.c (revision 15107)
@@ -457,7 +457,10 @@
VALUE enclib = rb_sprintf("enc/%s", name);
VALUE verbose = ruby_verbose;
VALUE debug = ruby_debug;
+ VALUE loaded;
char *s = RSTRING_PTR(enclib) + 4, *e = RSTRING_END(enclib);
+ int idx;
+
while (s < e) {
if (!ISALNUM(*s)) *s = '_';
else if (ISUPPER(*s)) *s = TOLOWER(*s);
@@ -466,11 +469,14 @@
OBJ_FREEZE(enclib);
ruby_verbose = Qfalse;
ruby_debug = Qfalse;
- rb_protect(require_enc, enclib, 0);
+ loaded = rb_protect(require_enc, enclib, 0);
ruby_verbose = verbose;
ruby_debug = debug;
rb_set_errinfo(Qnil);
- return rb_enc_registered(name);
+ if (NIL_P(loaded)) return -1;
+ if ((idx = rb_enc_registered(name)) < 0) return -1;
+ if (enc_autoload_p(enc_table.list[idx].enc)) return -1;
+ return idx;
}
int
@@ -487,20 +493,14 @@
if (enc_initialized_p(enc) &&
(base = enc_base_encoding(ENC_FROM_ENCODING(enc)), !NIL_P(base))) {
if ((b = enc_check_encoding(base)) < 0) {
-#if 0
- st_data_t key, val;
- key = (st_data_t)name;
- if (st_delete(enc_table.names, &key, &val)) {
- if (enc->name != (char *)key) xfree((char *)key);
- }
-#endif
- return -1;
+ goto failed;
}
enc_register_at(i, rb_enc_name(enc), rb_enc_from_index(b));
}
else {
i = load_encoding(rb_enc_name(enc));
- if (enc_autoload_p(rb_enc_from_index(i))) {
+ if (i < 0) {
+ failed:
rb_warn("failed to load encoding (%s); use ASCII-8BIT instead",
name);
return 0;
Index: ChangeLog
===================================================================
--- ChangeLog (revision 15106)
+++ ChangeLog (revision 15107)
@@ -1,5 +1,7 @@
-Fri Jan 18 11:39:10 2008 Nobuyoshi Nakada <nobu@r...>
+Fri Jan 18 12:25:13 2008 Nobuyoshi Nakada <nobu@r...>
+ * encoding.c (load_encoding): check if successfully loaded.
+
* encoding.c (rb_enc_find_index): use original encoding name to
replicate loaded encoding instead alias.
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/