Skip to content
Newer
Older
100644 88 lines (77 sloc) 1.89 KB
9595725 update copyrights to 2011
Laurent Sansonetti authored Jan 15, 2011
1 /*
2 * This file is covered by the Ruby license. See COPYING for more details.
7d7d3e8 @ferrous26 Change ownership to The MacRuby Team and update copyrights
ferrous26 authored Apr 22, 2012
3 *
4 * Copyright (C) 2012, The MacRuby Team. All rights reserved.
9595725 update copyrights to 2011
Laurent Sansonetti authored Jan 15, 2011
5 * Copyright (C) 2007-2011, Apple Inc. All rights reserved.
6 * Copyright (C) 1993-2007 Yukihiro Matsumoto
7 * Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
8 * Copyright (C) 2000 Information-technology Promotion Agency, Japan
9 */
10
9c1d230 committing experimental branch content
Laurent Sansonetti authored Mar 11, 2009
11 /*
12 * from eval.c
13 */
14
15 /* exit */
16
ac3a5b4 fix for <rdar://problem/7281043> Adding frameworks after requiring a …
Laurent Sansonetti authored Oct 7, 2009
17 // TODO: move & lock me into RoxorCore
18 static VALUE at_exit_procs = Qnil;
9c1d230 committing experimental branch content
Laurent Sansonetti authored Mar 11, 2009
19
20 /*
21 * call-seq:
22 * at_exit { block } -> proc
23 *
24 * Converts _block_ to a +Proc+ object (and therefore
25 * binds it at the point of call) and registers it for execution when
26 * the program exits. If multiple handlers are registered, they are
27 * executed in reverse order of registration.
28 *
29 * def do_at_exit(str1)
30 * at_exit { print str1 }
31 * end
32 * at_exit { puts "cruel world" }
33 * do_at_exit("goodbye ")
34 * exit
35 *
36 * <em>produces:</em>
37 *
38 * goodbye cruel world
39 */
40
41 static VALUE
42 rb_f_at_exit(VALUE self, SEL sel)
43 {
44 if (!rb_block_given_p()) {
45 rb_raise(rb_eArgError, "called without a block");
46 }
ac3a5b4 fix for <rdar://problem/7281043> Adding frameworks after requiring a …
Laurent Sansonetti authored Oct 7, 2009
47 VALUE proc = rb_block_proc();
48 rb_ary_push(at_exit_procs, proc);
9c1d230 committing experimental branch content
Laurent Sansonetti authored Mar 11, 2009
49 return proc;
50 }
51
d649cff call at_exit blocks within exception handlers
Laurent Sansonetti authored Jan 18, 2010
52 static VALUE
53 rb_end_proc_call_try(VALUE proc)
54 {
55 return rb_proc_call2(proc, 0, NULL);
56 }
57
58 static VALUE
e297457 fix a bug in #at_exit when the process would abort if a block raised …
Laurent Sansonetti authored Jan 28, 2011
59 rb_end_proc_call_catch(VALUE data, VALUE exc)
d649cff call at_exit blocks within exception handlers
Laurent Sansonetti authored Jan 18, 2010
60 {
e297457 fix a bug in #at_exit when the process would abort if a block raised …
Laurent Sansonetti authored Jan 28, 2011
61 rb_vm_print_exception(exc);
d649cff call at_exit blocks within exception handlers
Laurent Sansonetti authored Jan 18, 2010
62 return Qnil;
63 }
64
9c1d230 committing experimental branch content
Laurent Sansonetti authored Mar 11, 2009
65 void
66 rb_exec_end_proc(void)
67 {
ac3a5b4 fix for <rdar://problem/7281043> Adding frameworks after requiring a …
Laurent Sansonetti authored Oct 7, 2009
68 while (true) {
69 const int count = RARRAY_LEN(at_exit_procs);
70 if (count > 0) {
71 VALUE proc = RARRAY_AT(at_exit_procs, count - 1);
72 rb_ary_delete_at(at_exit_procs, count - 1);
d649cff call at_exit blocks within exception handlers
Laurent Sansonetti authored Jan 18, 2010
73 rb_rescue(rb_end_proc_call_try, proc, rb_end_proc_call_catch, 0);
ac3a5b4 fix for <rdar://problem/7281043> Adding frameworks after requiring a …
Laurent Sansonetti authored Oct 7, 2009
74 continue;
9c1d230 committing experimental branch content
Laurent Sansonetti authored Mar 11, 2009
75 }
ac3a5b4 fix for <rdar://problem/7281043> Adding frameworks after requiring a …
Laurent Sansonetti authored Oct 7, 2009
76 break;
9c1d230 committing experimental branch content
Laurent Sansonetti authored Mar 11, 2009
77 }
78 }
79
80 void
81 Init_jump(void)
82 {
cbe906e introduce rb_objc_define_module_function() which mimics the ruby spec
Laurent Sansonetti authored Aug 26, 2009
83 rb_objc_define_module_function(rb_mKernel, "at_exit", rb_f_at_exit, 0);
ac3a5b4 fix for <rdar://problem/7281043> Adding frameworks after requiring a …
Laurent Sansonetti authored Oct 7, 2009
84
85 at_exit_procs = rb_ary_new();
86 GC_RETAIN(at_exit_procs);
9c1d230 committing experimental branch content
Laurent Sansonetti authored Mar 11, 2009
87 }
Something went wrong with that request. Please try again.