зеркало из https://github.com/github/ruby.git
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:
Родитель
599076c45f
Коммит
0953efabbb
|
@ -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.
|
||||
|
|
26
encoding.c
26
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)" : "");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче