diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:13:14 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:13:14 +0000 |
commit | d0233291bc8a5068e52c69c210e5979e5324b5bc (patch) | |
tree | 7d9459449c33792c63eeb7baa071e76352e0baab /trunk/eval_jump.c | |
parent | 0dc342de848a642ecce8db697b8fecd83a63e117 (diff) | |
parent | 72eaacaa15256ab95c3b52ea386f88586fb9da40 (diff) |
re-adding tag v1_9_0_4 as an alias of trunk@18848v1_9_0_4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_0_4@18849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'trunk/eval_jump.c')
-rw-r--r-- | trunk/eval_jump.c | 151 |
1 files changed, 0 insertions, 151 deletions
diff --git a/trunk/eval_jump.c b/trunk/eval_jump.c deleted file mode 100644 index f474844ba8..0000000000 --- a/trunk/eval_jump.c +++ /dev/null @@ -1,151 +0,0 @@ -/* -*-c-*- */ -/* - * from eval.c - */ - -#include "eval_intern.h" - -/* exit */ - -void -rb_call_end_proc(VALUE data) -{ - rb_proc_call(data, rb_ary_new()); -} - -/* - * call-seq: - * at_exit { block } -> proc - * - * Converts _block_ to a +Proc+ object (and therefore - * binds it at the point of call) and registers it for execution when - * the program exits. If multiple handlers are registered, they are - * executed in reverse order of registration. - * - * def do_at_exit(str1) - * at_exit { print str1 } - * end - * at_exit { puts "cruel world" } - * do_at_exit("goodbye ") - * exit - * - * <em>produces:</em> - * - * goodbye cruel world - */ - -static VALUE -rb_f_at_exit(void) -{ - VALUE proc; - - if (!rb_block_given_p()) { - rb_raise(rb_eArgError, "called without a block"); - } - proc = rb_block_proc(); - rb_set_end_proc(rb_call_end_proc, proc); - return proc; -} - -struct end_proc_data { - void (*func) (); - VALUE data; - int safe; - struct end_proc_data *next; -}; - -static struct end_proc_data *end_procs, *ephemeral_end_procs, *tmp_end_procs; - -void -rb_set_end_proc(void (*func)(VALUE), VALUE data) -{ - struct end_proc_data *link = ALLOC(struct end_proc_data); - struct end_proc_data **list; - rb_thread_t *th = GET_THREAD(); - - if (th->top_wrapper) { - list = &ephemeral_end_procs; - } - else { - list = &end_procs; - } - link->next = *list; - link->func = func; - link->data = data; - link->safe = rb_safe_level(); - *list = link; -} - -void -rb_mark_end_proc(void) -{ - struct end_proc_data *link; - - link = end_procs; - while (link) { - rb_gc_mark(link->data); - link = link->next; - } - link = ephemeral_end_procs; - while (link) { - rb_gc_mark(link->data); - link = link->next; - } - link = tmp_end_procs; - while (link) { - rb_gc_mark(link->data); - link = link->next; - } -} - -void -rb_exec_end_proc(void) -{ - struct end_proc_data *link, *tmp; - int status; - volatile int safe = rb_safe_level(); - - while (ephemeral_end_procs) { - tmp_end_procs = link = ephemeral_end_procs; - ephemeral_end_procs = 0; - while (link) { - PUSH_TAG(); - if ((status = EXEC_TAG()) == 0) { - rb_set_safe_level_force(link->safe); - (*link->func) (link->data); - } - POP_TAG(); - if (status) { - error_handle(status); - } - tmp = link; - tmp_end_procs = link = link->next; - xfree(tmp); - } - } - while (end_procs) { - tmp_end_procs = link = end_procs; - end_procs = 0; - while (link) { - PUSH_TAG(); - if ((status = EXEC_TAG()) == 0) { - rb_set_safe_level_force(link->safe); - (*link->func) (link->data); - } - POP_TAG(); - if (status) { - error_handle(status); - } - tmp = link; - tmp_end_procs = link = link->next; - xfree(tmp); - } - } - rb_set_safe_level_force(safe); -} - -void -Init_jump(void) -{ - rb_define_global_function("at_exit", rb_f_at_exit, 0); -} |