--- Guard/Guard.xs 2009/01/13 23:30:38 1.8 +++ Guard/Guard.xs 2014/11/20 18:13:58 1.12 @@ -4,6 +4,23 @@ #include "perl.h" #include "XSUB.h" +#include "patchlevel.h" + +#define PERL_VERSION_ATLEAST(a,b,c) \ + (PERL_REVISION > (a) \ + || (PERL_REVISION == (a) \ + && (PERL_VERSION > (b) \ + || (PERL_VERSION == (b) && PERL_SUBVERSION >= (c))))) + +/* apparently < 5.8.8 */ +#ifndef SvSTASH_set +# define SvSTASH_set(x,a) SvSTASH(x) = (a) +#endif + +#ifndef PERL_MAGIC_ext +# define PERL_MAGIC_ext '~' +#endif + static HV *guard_stash; static SV * @@ -80,6 +97,7 @@ BOOT: guard_stash = gv_stashpv ("Guard", 1); + CvNODEBUG_on (get_cv ("Guard::scope_guard", 0)); /* otherwise calling scope can be the debugger */ void scope_guard (SV *block) @@ -94,13 +112,15 @@ PROTOTYPE: & CODE: { - SV *cv = guard_get_cv (aTHX_ block); + SV *cv = guard_get_cv (aTHX_ block); SV *guard = NEWSV (0, 0); SvUPGRADE (guard, SVt_PVMG); sv_magicext (guard, cv, PERL_MAGIC_ext, &guard_vtbl, 0, 0); RETVAL = newRV_noinc (guard); SvOBJECT_on (guard); +#if !PERL_VERSION_ATLEAST(5,18,0) ++PL_sv_objcount; +#endif SvSTASH_set (guard, (HV*)SvREFCNT_inc ((SV *)guard_stash)); } OUTPUT: