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

Comparing Guard/Guard.xs (file contents):
Revision 1.8 by root, Tue Jan 13 23:30:38 2009 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)
78 95
79MODULE = Guard PACKAGE = Guard 96MODULE = Guard PACKAGE = Guard
80 97
81BOOT: 98BOOT:
82 guard_stash = gv_stashpv ("Guard", 1); 99 guard_stash = gv_stashpv ("Guard", 1);
100 CvNODEBUG_on (get_cv ("Guard::scope_guard", 0)); /* otherwise calling scope can be the debugger */
83 101
84void 102void
85scope_guard (SV *block) 103scope_guard (SV *block)
86 PROTOTYPE: & 104 PROTOTYPE: &
87 CODE: 105 CODE:
92SV * 110SV *
93guard (SV *block) 111guard (SV *block)
94 PROTOTYPE: & 112 PROTOTYPE: &
95 CODE: 113 CODE:
96{ 114{
97 SV *cv = guard_get_cv (aTHX_ block); 115 SV *cv = guard_get_cv (aTHX_ block);
98 SV *guard = NEWSV (0, 0); 116 SV *guard = NEWSV (0, 0);
99 SvUPGRADE (guard, SVt_PVMG); 117 SvUPGRADE (guard, SVt_PVMG);
100 sv_magicext (guard, cv, PERL_MAGIC_ext, &guard_vtbl, 0, 0); 118 sv_magicext (guard, cv, PERL_MAGIC_ext, &guard_vtbl, 0, 0);
101 RETVAL = newRV_noinc (guard); 119 RETVAL = newRV_noinc (guard);
102 SvOBJECT_on (guard); 120 SvOBJECT_on (guard);
121#if !PERL_VERSION_ATLEAST(5,18,0)
103 ++PL_sv_objcount; 122 ++PL_sv_objcount;
123#endif
104 SvSTASH_set (guard, (HV*)SvREFCNT_inc ((SV *)guard_stash)); 124 SvSTASH_set (guard, (HV*)SvREFCNT_inc ((SV *)guard_stash));
105} 125}
106 OUTPUT: 126 OUTPUT:
107 RETVAL 127 RETVAL
108 128

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines