summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/gc.c b/gc.c
index d56d2d170a..2d4da31a75 100644
--- a/gc.c
+++ b/gc.c
@@ -2290,9 +2290,14 @@ define_final(int argc, VALUE *argv, VALUE os)
rb_raise(rb_eArgError, "wrong type argument %s (should be callable)",
rb_obj_classname(block));
}
- FL_SET(obj, FL_FINALIZE);
+ if (!FL_ABLE(obj)) {
+ rb_raise(rb_eArgError, "cannot define finalizer for %s",
+ rb_obj_classname(obj));
+ }
+ RBASIC(obj)->flags |= FL_FINALIZE;
block = rb_ary_new3(2, INT2FIX(rb_safe_level()), block);
+ OBJ_FREEZE(block);
if (!finalizer_table) {
finalizer_table = st_init_numtable();