Remove respond_to check from Class#bind_call #13116
Open
+16
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://bugs.ruby-lang.org/issues/21267
Class#allocate
has an additionalrb_obj_respond_to(klass, rb_intern("allocate"))
check to forbid allocate being called on a class where it has been made private or undefined, even if used via ex.bind_call
.However I don't think this provides any additional protection from users accessing an uninitialized object, as the user can redefine allocate to anything to bypass the check:
Or even override
respond_to_missing?
So I think we should remove this check. For classes that we need to forbid allocation we should use
rb_undef_alloc_func
.The classes I see this used for are:
My main motivation is that this check makes
Class#allocate
slow. There are ways we could improve that, but I don't think the check as-is is useful. If there's an alternative check we'd like to do instead of simply removing this I'd be happy to implement it.This makes
allocate
~75% faster.