diff options
author | John Hawthorn <[email protected]> | 2025-04-14 18:02:12 -0700 |
---|---|---|
committer | John Hawthorn <[email protected]> | 2025-05-12 14:10:29 -0700 |
commit | b0502e8f904f155ac077014077431ed5e54b9996 () | |
tree | 53803afedec1d3503a048565ef8ec89d2bd852a1 | |
parent | c6528548d04cb918f424885111a2d6ae9516518d (diff) |
Remove respond_to check from Class#bind_call
Notes: Merged: https://.com/ruby/ruby/pull/13116
-rw-r--r-- | benchmark/object_allocate.yml | 1 | ||||
-rw-r--r-- | object.c | 15 | ||||
-rw-r--r-- | test/ruby/test_class.rb | 8 |
3 files changed, 5 insertions, 19 deletions
@@ -45,4 +45,5 @@ benchmark: allocate_kwarg_params: "KWArg.new(a: 1, b: 2, c: 3, d: 4)" allocate_mixed_params: "Mixed.new(1, 2, c: 3, d: 4)" allocate_no_params: "Object.new" loop_count: 100000 @@ -2139,17 +2139,6 @@ static VALUE class_call_alloc_func(rb_alloc_func_t allocator, VALUE klass); */ static VALUE -rb_class_alloc_m(VALUE klass) -{ - rb_alloc_func_t allocator = class_get_alloc_func(klass); - if (!rb_obj_respond_to(klass, rb_intern("allocate"), 1)) { - rb_raise(rb_eTypeError, "calling %"PRIsVALUE".allocate is prohibited", - klass); - } - return class_call_alloc_func(allocator, klass); -} - -static VALUE rb_class_alloc(VALUE klass) { rb_alloc_func_t allocator = class_get_alloc_func(klass); @@ -4603,8 +4592,8 @@ InitVM_Object(void) rb_define_method(rb_cModule, "deprecate_constant", rb_mod_deprecate_constant, -1); /* in variable.c */ rb_define_method(rb_cModule, "singleton_class?", rb_mod_singleton_p, 0); - rb_define_method(rb_singleton_class(rb_cClass), "allocate", rb_class_alloc_m, 0); - rb_define_method(rb_cClass, "allocate", rb_class_alloc_m, 0); rb_define_method(rb_cClass, "new", rb_class_new_instance_pass_kw, -1); rb_define_method(rb_cClass, "initialize", rb_class_initialize, -1); rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0); @@ -283,12 +283,8 @@ class TestClass < Test::Unit::TestCase assert_raise(TypeError, bug6863) { Class.new(Class.allocate) } allocator = Class.instance_method(:allocate) - assert_raise_with_message(TypeError, /prohibited/) { - allocator.bind(Rational).call - } - assert_raise_with_message(TypeError, /prohibited/) { - allocator.bind_call(Rational) - } end def test_nonascii_name |