aboutsummaryrefslogtreecommitdiffstats
path: root/proc.c
diff options
context:
space:
mode:
authorChris Seaton <chris.seaton@shopify.com>2020-09-16 19:59:36 +0100
committerAaron Patterson <aaron.patterson@gmail.com>2020-09-16 13:52:24 -0700
commit8e173d8b2709f47cc0709f699640dafe850c9a8f (patch)
tree8c5421a14acb0bce87a723ae1b4a8959dc7f2326 /proc.c
parentf75009c1222621836b2340bbb5f4d4274972ccb4 (diff)
downloadruby-8e173d8b2709f47cc0709f699640dafe850c9a8f.tar.gz
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.
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c12
1 files changed, 12 insertions, 0 deletions
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)
{