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) |
… | |
… | |
65 | |
73 | |
66 | static int |
74 | static int |
67 | guard_free (pTHX_ SV *cv, MAGIC *mg) |
75 | guard_free (pTHX_ SV *cv, MAGIC *mg) |
68 | { |
76 | { |
69 | exec_guard_cb (aTHX_ mg->mg_obj); |
77 | exec_guard_cb (aTHX_ mg->mg_obj); |
|
|
78 | |
|
|
79 | return 0; |
70 | } |
80 | } |
71 | |
81 | |
72 | static MGVTBL guard_vtbl = { |
82 | static MGVTBL guard_vtbl = { |
73 | 0, 0, 0, 0, |
83 | 0, 0, 0, 0, |
74 | guard_free |
84 | guard_free |
… | |
… | |
76 | |
86 | |
77 | MODULE = Guard PACKAGE = Guard |
87 | MODULE = Guard PACKAGE = Guard |
78 | |
88 | |
79 | BOOT: |
89 | BOOT: |
80 | guard_stash = gv_stashpv ("Guard", 1); |
90 | guard_stash = gv_stashpv ("Guard", 1); |
81 | |
91 | CvNODEBUG_on (get_cv ("Guard::scope_guard", 0)); /* otherwise calling scope can be the debugger */ |
82 | void |
|
|
83 | CLONE (...) |
|
|
84 | PROTOTYPE: @ |
|
|
85 | CODE: |
|
|
86 | guard_stash = gv_stashpv ("Guard", 1); |
|
|
87 | |
92 | |
88 | void |
93 | void |
89 | scope_guard (SV *block) |
94 | scope_guard (SV *block) |
90 | PROTOTYPE: & |
95 | PROTOTYPE: & |
91 | CODE: |
96 | CODE: |