ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Guard/Guard.xs
(Generate patch)

Comparing Guard/Guard.xs (file contents):
Revision 1.4 by root, Sat Dec 13 19:43:27 2008 UTC vs.
Revision 1.11 by root, Sun Jul 19 04:59:54 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines