1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2013-07-14 17:32:07 +00:00
parent 599076c45f
commit 0953efabbb
2 changed files with 24 additions and 6 deletions

View file

@ -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 * encoding.c (enc_check_encoding): use is_data_encoding() to check
type consistently. type consistently.

View file

@ -135,13 +135,20 @@ enc_check_encoding(VALUE obj)
return check_encoding(RDATA(obj)->data); 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 * static rb_encoding *
must_encoding(VALUE enc) must_encoding(VALUE enc)
{ {
int index = enc_check_encoding(enc); int index = enc_check_encoding(enc);
if (index < 0) { if (index < 0) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Encoding)", not_encoding(enc);
rb_obj_classname(enc));
} }
return DATA_PTR(enc); return DATA_PTR(enc);
} }
@ -1023,10 +1030,19 @@ rb_enc_tolower(int c, rb_encoding *enc)
static VALUE static VALUE
enc_inspect(VALUE self) 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(), return rb_enc_sprintf(rb_usascii_encoding(),
"#<%"PRIsVALUE":%s%s>", rb_obj_class(self), "#<%"PRIsVALUE":%s%s%s>", rb_obj_class(self),
rb_enc_name((rb_encoding*)DATA_PTR(self)), rb_enc_name(enc),
(enc_dummy_p(self) ? " (dummy)" : "")); (ENC_DUMMY_P(enc) ? " (dummy)" : ""),
enc_autoload_p(enc) ? " (autoload)" : "");
} }
/* /*