summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-14 17:32:07 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-14 17:32:07 +0000
commit0953efabbb990bf84d2436b2f140494a1c86ec3d (patch)
tree53a4a78a9b6d9d2d2f41deee4bd7c0d21213eac6
parent599076c45f26338e3ec20e545b8fad78aa6abcc9 (diff)
encoding.c: defer autoload
* encoding.c (enc_inspect): defer loading autoloaded encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41969 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--encoding.c26
2 files changed, 24 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 2c850a59bda..10b687039a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,6 @@
-Mon Jul 15 02:31:12 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Mon Jul 15 02:32:04 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * encoding.c (enc_inspect): defer loading autoloaded encoding.
* encoding.c (enc_check_encoding): use is_data_encoding() to check
type consistently.
diff --git a/encoding.c b/encoding.c
index ac92b8627c2..dc13fc924a3 100644
--- a/encoding.c
+++ b/encoding.c
@@ -135,13 +135,20 @@ enc_check_encoding(VALUE obj)
return check_encoding(RDATA(obj)->data);
}
+NORETURN(static void not_encoding(VALUE enc));
+static void
+not_encoding(VALUE enc)
+{
+ rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (expected Encoding)",
+ rb_obj_class(enc));
+}
+
static rb_encoding *
must_encoding(VALUE enc)
{
int index = enc_check_encoding(enc);
if (index < 0) {
- rb_raise(rb_eTypeError, "wrong argument type %s (expected Encoding)",
- rb_obj_classname(enc));
+ not_encoding(enc);
}
return DATA_PTR(enc);
}
@@ -1023,10 +1030,19 @@ rb_enc_tolower(int c, rb_encoding *enc)
static VALUE
enc_inspect(VALUE self)
{
+ rb_encoding *enc;
+
+ if (!is_data_encoding(self)) {
+ not_encoding(self);
+ }
+ if (!(enc = DATA_PTR(self)) || rb_enc_from_index(rb_enc_to_index(enc)) != enc) {
+ rb_raise(rb_eTypeError, "broken Encoding");
+ }
return rb_enc_sprintf(rb_usascii_encoding(),
- "#<%"PRIsVALUE":%s%s>", rb_obj_class(self),
- rb_enc_name((rb_encoding*)DATA_PTR(self)),
- (enc_dummy_p(self) ? " (dummy)" : ""));
+ "#<%"PRIsVALUE":%s%s%s>", rb_obj_class(self),
+ rb_enc_name(enc),
+ (ENC_DUMMY_P(enc) ? " (dummy)" : ""),
+ enc_autoload_p(enc) ? " (autoload)" : "");
}
/*