ruby-changes:29917
From: nobu <ko1@a...>
Date: Mon, 15 Jul 2013 02:32:17 +0900 (JST)
Subject: [ruby-changes:29917] nobu:r41969 (trunk): encoding.c: defer autoload
nobu 2013-07-15 02:32:07 +0900 (Mon, 15 Jul 2013) New Revision: 41969 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41969 Log: encoding.c: defer autoload * encoding.c (enc_inspect): defer loading autoloaded encoding. Modified files: trunk/ChangeLog trunk/encoding.c Index: encoding.c =================================================================== --- encoding.c (revision 41968) +++ encoding.c (revision 41969) @@ -135,13 +135,20 @@ enc_check_encoding(VALUE obj) https://github.com/ruby/ruby/blob/trunk/encoding.c#L135 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) https://github.com/ruby/ruby/blob/trunk/encoding.c#L1030 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)" : ""); } /* Index: ChangeLog =================================================================== --- ChangeLog (revision 41968) +++ ChangeLog (revision 41969) @@ -1,4 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Mon Jul 15 02:31:12 2013 Nobuyoshi Nakada <nobu@r...> +Mon Jul 15 02:32:04 2013 Nobuyoshi Nakada <nobu@r...> + + * encoding.c (enc_inspect): defer loading autoloaded encoding. * encoding.c (enc_check_encoding): use is_data_encoding() to check type consistently. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/