Project

General

Profile

Actions

Feature #2470

closed

Encoding#new doesn't undef_method-ed

Added by naruse (Yui NARUSE) over 14 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-dev:39862]

Description

=begin
Fixnum や Encoding のような、rb_undef_alloc_func されているクラスでは、
Hoge.new がエラーになりますが、
Fixnum などでは Fixnum.new が undef されているのに、
Encoding ではなされていないため、呼んだ際の挙動が異なります。

irb(main):001:0> Fixnum.new
NoMethodError: undefined method new' for Fixnum:Class from (irb):1 from /usr/local/bin/irb_1_9_1:12:in '
irb(main):002:0> Encoding.new
TypeError: allocator undefined for Encoding
from (irb):2:in new' from (irb):2 from /usr/local/bin/irb_1_9_1:12:in '

以下がパッチです。

diff --git a/encoding.c b/encoding.c
index 38d81b8..f9d2f20 100644
--- a/encoding.c
+++ b/encoding.c
@@ -1484,6 +1484,7 @@ Init_Encoding(void)

  rb_cEncoding = rb_define_class("Encoding", rb_cObject);
  rb_undef_alloc_func(rb_cEncoding);
  • rb_undef_method(CLASS_OF(rb_cEncoding), "new");
    rb_define_method(rb_cEncoding, "to_s", enc_name, 0);
    rb_define_method(rb_cEncoding, "inspect", enc_inspect, 0);
    rb_define_method(rb_cEncoding, "name", enc_name, 0);
    diff --git a/object.c b/object.c
    index 10eb983..704cb2a 100644
    --- a/object.c
    +++ b/object.c
    @@ -2680,6 +2680,7 @@ Init_Object(void)

    rb_cData = rb_define_class("Data", rb_cObject);
    rb_undef_alloc_func(rb_cData);

  • rb_undef_method(CLASS_OF(rb_cData), "new");

    rb_cTrueClass = rb_define_class("TrueClass", rb_cObject);
    rb_define_method(rb_cTrueClass, "to_s", true_to_s, 0);
    diff --git a/vm.c b/vm.c
    index fa028fd..e522c9f 100644
    --- a/vm.c
    +++ b/vm.c
    @@ -1944,6 +1944,7 @@ Init_VM(void)
    /* ::VM */
    rb_cRubyVM = rb_define_class("RubyVM", rb_cObject);
    rb_undef_alloc_func(rb_cRubyVM);

  • rb_undef_method(CLASS_OF(rb_cRubyVM), "new");

    /* ::VM::FrozenCore /
    fcore = rb_class_new(rb_cBasicObject);
    @@ -1962,6 +1963,7 @@ Init_VM(void)
    /
    ::VM::Env */
    rb_cEnv = rb_define_class_under(rb_cRubyVM, "Env", rb_cObject);
    rb_undef_alloc_func(rb_cEnv);

  • rb_undef_method(CLASS_OF(rb_cEnv), "new");

    /* ::Thread */
    rb_cThread = rb_define_class("Thread", rb_cObject);
    =end

Actions #1

Updated by naruse (Yui NARUSE) over 14 years ago

=begin
おっと、Data.newは消してはダメですね。
これについては取り下げます。
=end

Actions #2

Updated by naruse (Yui NARUSE) over 14 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r26145.
Yui, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0