1 | #define PERL_NO_GET_CONTEXT |
1 | #define PERL_NO_GET_CONTEXT |
2 | |
2 | |
3 | #include "EXTERN.h" |
3 | #include "EXTERN.h" |
4 | #include "perl.h" |
4 | #include "perl.h" |
5 | #include "XSUB.h" |
5 | #include "XSUB.h" |
|
|
6 | |
|
|
7 | #ifndef SvSTASH_set |
|
|
8 | # define SvSTASH_set(x,a) SvSTASH(x) = (a) |
|
|
9 | #endif |
|
|
10 | |
|
|
11 | #ifndef PERL_MAGIC_ext |
|
|
12 | # define PERL_MAGIC_ext '~' |
|
|
13 | #endif |
6 | |
14 | |
7 | static HV *guard_stash; |
15 | static HV *guard_stash; |
8 | |
16 | |
9 | static SV * |
17 | static SV * |
10 | guard_get_cv (pTHX_ SV *cb_sv) |
18 | guard_get_cv (pTHX_ SV *cb_sv) |
… | |
… | |
31 | PUSHSTACKi (PERLSI_DESTROY); |
39 | PUSHSTACKi (PERLSI_DESTROY); |
32 | |
40 | |
33 | PUSHMARK (SP); |
41 | PUSHMARK (SP); |
34 | PUTBACK; |
42 | PUTBACK; |
35 | call_sv (cb, G_VOID | G_DISCARD | G_EVAL); |
43 | call_sv (cb, G_VOID | G_DISCARD | G_EVAL); |
36 | SPAGAIN; |
|
|
37 | |
44 | |
38 | if (SvTRUE (ERRSV)) |
45 | if (SvTRUE (ERRSV)) |
39 | { |
46 | { |
|
|
47 | SPAGAIN; |
|
|
48 | |
40 | PUSHMARK (SP); |
49 | PUSHMARK (SP); |
41 | PUTBACK; |
50 | PUTBACK; |
42 | call_sv (get_sv ("Guard::DIED", 1), G_VOID | G_DISCARD | G_EVAL | G_KEEPERR); |
51 | call_sv (get_sv ("Guard::DIED", 1), G_VOID | G_DISCARD | G_EVAL | G_KEEPERR); |
43 | SPAGAIN; |
|
|
44 | |
52 | |
45 | sv_setpvn (ERRSV, "", 0); |
53 | sv_setpvn (ERRSV, "", 0); |
46 | } |
54 | } |
47 | |
55 | |
48 | if (saveerr) |
56 | if (saveerr) |
… | |
… | |
53 | PL_diehook = savedie; |
61 | PL_diehook = savedie; |
54 | SvREFCNT_dec (oldhook); |
62 | SvREFCNT_dec (oldhook); |
55 | } |
63 | } |
56 | |
64 | |
57 | POPSTACK; |
65 | POPSTACK; |
58 | PUTBACK; |
|
|
59 | } |
66 | } |
60 | |
67 | |
61 | static void |
68 | static void |
62 | scope_guard_cb (pTHX_ void *cv) |
69 | scope_guard_cb (pTHX_ void *cv) |
63 | { |
70 | { |
… | |
… | |
66 | |
73 | |
67 | static int |
74 | static int |
68 | guard_free (pTHX_ SV *cv, MAGIC *mg) |
75 | guard_free (pTHX_ SV *cv, MAGIC *mg) |
69 | { |
76 | { |
70 | exec_guard_cb (aTHX_ mg->mg_obj); |
77 | exec_guard_cb (aTHX_ mg->mg_obj); |
|
|
78 | |
|
|
79 | return 0; |
71 | } |
80 | } |
72 | |
81 | |
73 | static MGVTBL guard_vtbl = { |
82 | static MGVTBL guard_vtbl = { |
74 | 0, 0, 0, 0, |
83 | 0, 0, 0, 0, |
75 | guard_free |
84 | guard_free |
… | |
… | |
77 | |
86 | |
78 | MODULE = Guard PACKAGE = Guard |
87 | MODULE = Guard PACKAGE = Guard |
79 | |
88 | |
80 | BOOT: |
89 | BOOT: |
81 | guard_stash = gv_stashpv ("Guard", 1); |
90 | guard_stash = gv_stashpv ("Guard", 1); |
82 | |
91 | CvNODEBUG_on (get_cv ("Guard::scope_guard", 0)); /* otherwise calling scope can be the debugger */ |
83 | void |
|
|
84 | CLONE (...) |
|
|
85 | PROTOTYPE: @ |
|
|
86 | CODE: |
|
|
87 | guard_stash = gv_stashpv ("Guard", 1); |
|
|
88 | |
92 | |
89 | void |
93 | void |
90 | scope_guard (SV *block) |
94 | scope_guard (SV *block) |
91 | PROTOTYPE: & |
95 | PROTOTYPE: & |
92 | CODE: |
96 | CODE: |