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

Comparing Guard/Guard.xs (file contents):
Revision 1.5 by root, Sat Dec 13 21:47:07 2008 UTC vs.
Revision 1.12 by root, Thu Nov 20 18:13:58 2014 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#include "patchlevel.h"
8
9#define PERL_VERSION_ATLEAST(a,b,c) \
10 (PERL_REVISION > (a) \
11 || (PERL_REVISION == (a) \
12 && (PERL_VERSION > (b) \
13 || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c)))))
14
15/* apparently < 5.8.8 */
16#ifndef SvSTASH_set
17# define SvSTASH_set(x,a) SvSTASH(x) = (a)
18#endif
19
20#ifndef PERL_MAGIC_ext
21# define PERL_MAGIC_ext '~'
22#endif
6 23
7static HV *guard_stash; 24static HV *guard_stash;
8 25
9static SV * 26static SV *
10guard_get_cv (pTHX_ SV *cb_sv) 27guard_get_cv (pTHX_ SV *cb_sv)
31 PUSHSTACKi (PERLSI_DESTROY); 48 PUSHSTACKi (PERLSI_DESTROY);
32 49
33 PUSHMARK (SP); 50 PUSHMARK (SP);
34 PUTBACK; 51 PUTBACK;
35 call_sv (cb, G_VOID | G_DISCARD | G_EVAL); 52 call_sv (cb, G_VOID | G_DISCARD | G_EVAL);
36 SPAGAIN;
37 53
38 if (SvTRUE (ERRSV)) 54 if (SvTRUE (ERRSV))
39 { 55 {
56 SPAGAIN;
57
40 PUSHMARK (SP); 58 PUSHMARK (SP);
41 PUTBACK; 59 PUTBACK;
42 call_sv (get_sv ("Guard::DIED", 1), G_VOID | G_DISCARD | G_EVAL | G_KEEPERR); 60 call_sv (get_sv ("Guard::DIED", 1), G_VOID | G_DISCARD | G_EVAL | G_KEEPERR);
43 SPAGAIN;
44 61
45 sv_setpvn (ERRSV, "", 0); 62 sv_setpvn (ERRSV, "", 0);
46 } 63 }
47 64
48 if (saveerr) 65 if (saveerr)
65 82
66static int 83static int
67guard_free (pTHX_ SV *cv, MAGIC *mg) 84guard_free (pTHX_ SV *cv, MAGIC *mg)
68{ 85{
69 exec_guard_cb (aTHX_ mg->mg_obj); 86 exec_guard_cb (aTHX_ mg->mg_obj);
87
88 return 0;
70} 89}
71 90
72static MGVTBL guard_vtbl = { 91static MGVTBL guard_vtbl = {
73 0, 0, 0, 0, 92 0, 0, 0, 0,
74 guard_free 93 guard_free
76 95
77MODULE = Guard PACKAGE = Guard 96MODULE = Guard PACKAGE = Guard
78 97
79BOOT: 98BOOT:
80 guard_stash = gv_stashpv ("Guard", 1); 99 guard_stash = gv_stashpv ("Guard", 1);
81 100 CvNODEBUG_on (get_cv ("Guard::scope_guard", 0)); /* otherwise calling scope can be the debugger */
82void
83CLONE (...)
84 PROTOTYPE: @
85 CODE:
86 guard_stash = gv_stashpv ("Guard", 1);
87 101
88void 102void
89scope_guard (SV *block) 103scope_guard (SV *block)
90 PROTOTYPE: & 104 PROTOTYPE: &
91 CODE: 105 CODE:
96SV * 110SV *
97guard (SV *block) 111guard (SV *block)
98 PROTOTYPE: & 112 PROTOTYPE: &
99 CODE: 113 CODE:
100{ 114{
101 SV *cv = guard_get_cv (aTHX_ block); 115 SV *cv = guard_get_cv (aTHX_ block);
102 SV *guard = NEWSV (0, 0); 116 SV *guard = NEWSV (0, 0);
103 SvUPGRADE (guard, SVt_PVMG); 117 SvUPGRADE (guard, SVt_PVMG);
104 sv_magicext (guard, cv, PERL_MAGIC_ext, &guard_vtbl, 0, 0); 118 sv_magicext (guard, cv, PERL_MAGIC_ext, &guard_vtbl, 0, 0);
105 RETVAL = newRV_noinc (guard); 119 RETVAL = newRV_noinc (guard);
106 SvOBJECT_on (guard); 120 SvOBJECT_on (guard);
121#if !PERL_VERSION_ATLEAST(5,18,0)
107 ++PL_sv_objcount; 122 ++PL_sv_objcount;
123#endif
108 SvSTASH_set (guard, (HV*)SvREFCNT_inc ((SV *)guard_stash)); 124 SvSTASH_set (guard, (HV*)SvREFCNT_inc ((SV *)guard_stash));
109} 125}
110 OUTPUT: 126 OUTPUT:
111 RETVAL 127 RETVAL
112 128

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines