From 8e173d8b2709f47cc0709f699640dafe850c9a8f Mon Sep 17 00:00:00 2001 From: Chris Seaton Date: Wed, 16 Sep 2020 19:59:36 +0100 Subject: 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. --- proc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'proc.c') diff --git a/proc.c b/proc.c index 3f92ceb365..96c84d20a8 100644 --- a/proc.c +++ b/proc.c @@ -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) { -- cgit v1.2.1