Remove respond_to check from Class#bind_call

This commit is contained in:
John Hawthorn 2025-04-14 18:02:12 -07:00
parent c6528548d0
commit b0502e8f90
Notes: git 2025-05-12 21:10:42 +00:00
3 changed files with 5 additions and 19 deletions

View File

@ -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"
allocate_allocate: "Object.allocate"
loop_count: 100000

View File

@ -2138,17 +2138,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)
{
@ -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_singleton_class(rb_cClass), "allocate", rb_class_alloc, 0);
rb_define_method(rb_cClass, "allocate", rb_class_alloc, 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);

View File

@ -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)
}
assert_nothing_raised { allocator.bind(Rational).call }
assert_nothing_raised { allocator.bind_call(Rational) }
end
def test_nonascii_name