summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-06-29 01:31:37 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-06-29 01:31:37 +0000
commit4c20725d55e0acb5675e04e6989f8b804df48389 (patch)
tree44a2205db9f0a6eaca015791499b10777ac3dd13 /gc.c
parent478ac793950e7d3e8c04ff816183b9d5bd552b30 (diff)
* eval.c (rb_eval_cmd, rb_thread_trap_eval): restore safe level.
* gc.c (define_final, run_final): preserve and restore safe level for finalizers. [ruby-core:03058] * signal.c (signal_exec, rb_trap_exit, trap): preserve and restore safe level for signal handlers. [ruby-dev:23829] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6541 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/gc.c b/gc.c
index 063e5ba4b8..68d58df479 100644
--- a/gc.c
+++ b/gc.c
@@ -1674,6 +1674,8 @@ undefine_final(os, obj)
return obj;
}
+#define NODE_FINAL NODE_LIT
+
/*
* call-seq:
* ObjectSpace.define_finalizer(obj, aProc=proc())
@@ -1702,6 +1704,8 @@ define_final(argc, argv, os)
need_call_final = 1;
FL_SET(obj, FL_FINALIZE);
+ block = (VALUE)rb_node_newnode(NODE_FINAL, block, ruby_safe_level, 0);
+
if (!finalizer_table) {
finalizer_table = st_init_numtable();
}
@@ -1732,7 +1736,7 @@ static VALUE
run_single_final(args)
VALUE *args;
{
- rb_eval_cmd(args[0], args[1], 0);
+ rb_eval_cmd(args[0], args[1], (int)args[2]);
return Qnil;
}
@@ -1742,17 +1746,20 @@ run_final(obj)
{
long i;
int status, critical_save = rb_thread_critical;
- VALUE args[2], table;
+ VALUE args[3], table;
rb_thread_critical = Qtrue;
args[1] = rb_ary_new3(1, rb_obj_id(obj)); /* make obj into id */
+ args[2] = (VALUE)ruby_safe_level;
for (i=0; i<RARRAY(finalizers)->len; i++) {
args[0] = RARRAY(finalizers)->ptr[i];
rb_protect((VALUE(*)_((VALUE)))run_single_final, (VALUE)args, &status);
}
if (finalizer_table && st_delete(finalizer_table, (st_data_t*)&obj, &table)) {
for (i=0; i<RARRAY(table)->len; i++) {
- args[0] = RARRAY(table)->ptr[i];
+ NODE *final = (NODE *)RARRAY(table)->ptr[i];
+ args[0] = final->nd_lit;
+ args[2] = final->nd_nth;
rb_protect((VALUE(*)_((VALUE)))run_single_final, (VALUE)args, &status);
}
}