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 | /* apparently < 5.8.8 */ |
|
|
8 | #ifndef SvSTASH_set |
|
|
9 | # define SvSTASH_set(x,a) SvSTASH(x) = (a) |
|
|
10 | #endif |
|
|
11 | |
|
|
12 | #ifndef PERL_MAGIC_ext |
|
|
13 | # define PERL_MAGIC_ext '~' |
|
|
14 | #endif |
6 | |
15 | |
7 | static HV *guard_stash; |
16 | static HV *guard_stash; |
8 | |
17 | |
9 | static SV * |
18 | static SV * |
10 | guard_get_cv (pTHX_ SV *cb_sv) |
19 | guard_get_cv (pTHX_ SV *cb_sv) |
… | |
… | |
65 | |
74 | |
66 | static int |
75 | static int |
67 | guard_free (pTHX_ SV *cv, MAGIC *mg) |
76 | guard_free (pTHX_ SV *cv, MAGIC *mg) |
68 | { |
77 | { |
69 | exec_guard_cb (aTHX_ mg->mg_obj); |
78 | exec_guard_cb (aTHX_ mg->mg_obj); |
|
|
79 | |
|
|
80 | return 0; |
70 | } |
81 | } |
71 | |
82 | |
72 | static MGVTBL guard_vtbl = { |
83 | static MGVTBL guard_vtbl = { |
73 | 0, 0, 0, 0, |
84 | 0, 0, 0, 0, |
74 | guard_free |
85 | guard_free |
… | |
… | |
76 | |
87 | |
77 | MODULE = Guard PACKAGE = Guard |
88 | MODULE = Guard PACKAGE = Guard |
78 | |
89 | |
79 | BOOT: |
90 | BOOT: |
80 | guard_stash = gv_stashpv ("Guard", 1); |
91 | guard_stash = gv_stashpv ("Guard", 1); |
|
|
92 | CvNODEBUG_on (get_cv ("Guard::scope_guard", 0)); /* otherwise calling scope can be the debugger */ |
81 | |
93 | |
82 | void |
94 | void |
83 | scope_guard (SV *block) |
95 | scope_guard (SV *block) |
84 | PROTOTYPE: & |
96 | PROTOTYPE: & |
85 | CODE: |
97 | CODE: |