diff options
author | Chris Seaton <chris.seaton@shopify.com> | 2020-09-16 19:59:36 +0100 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2020-09-16 13:52:24 -0700 |
commit | 8e173d8b2709f47cc0709f699640dafe850c9a8f (patch) | |
tree | 8c5421a14acb0bce87a723ae1b4a8959dc7f2326 /proc.c | |
parent | f75009c1222621836b2340bbb5f4d4274972ccb4 (diff) |
Warn on a finalizer that captures the object to be finalized
Also improve specs and documentation for finalizers and more clearly
recommend a safe code pattern to use them.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3444
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -2739,6 +2739,18 @@ rb_obj_method_arity(VALUE obj, ID id) return rb_mod_method_arity(CLASS_OF(obj), id); } +VALUE +rb_callable_receiver(VALUE callable) { + if (rb_obj_is_proc(callable)) { + VALUE binding = rb_funcall(callable, rb_intern("binding"), 0); + return rb_funcall(binding, rb_intern("receiver"), 0); + } else if (rb_obj_is_method(callable)) { + return method_receiver(callable); + } else { + return Qundef; + } +} + const rb_method_definition_t * rb_method_def(VALUE method) { |