diff --git a/COW.xs b/COW.xs index 08f389f..6f9985e 100644 --- a/COW.xs +++ b/COW.xs @@ -7,6 +7,7 @@ * */ +#define PERL_NO_GET_CONTEXT #include #include #include @@ -21,10 +22,17 @@ /* CowREFCNT is incorrect on Perl < 5.32 */ #define myCowREFCNT(sv) ((SvLEN(sv)>0) ? CowREFCNT(sv) : 0) +#ifndef newCONSTSUB_flags +# define newCONSTSUB_flags(_hv, _nm, _len, _flg, _sv) newCONSTSUB(_hv, _nm, _sv) +#endif + MODULE = B__COW PACKAGE = B::COW PROTOTYPES: DISABLE +# Converted to newCONSTSUB_flags() +#if 0 + SV* can_cow() CODE: @@ -38,6 +46,8 @@ CODE: OUTPUT: RETVAL +#endif + SV* is_cow(sv) SV *sv; @@ -69,6 +79,10 @@ CODE: OUTPUT: RETVAL + +# Converted to newCONSTSUB_flags() +#if 0 + SV* cowrefcnt_max() CODE: @@ -81,3 +95,25 @@ CODE: } OUTPUT: RETVAL + +#endif + +BOOT: +{ + HV* stash; /* get HV* stash from this XSUB's CV*, faster than gv_stashpvs() */ + if (CvNAMED(cv)) /* EU::ParseXS's ALIAS:/XSANY overwrites C auto var cv */ + stash = CvSTASH(cv); /* but this module doesn't use the ALIAS: feature */ + else { + GV* gv = CvGV(cv); /* fn call */ + stash = GvSTASH(gv); + } +#if !B_CAN_COW + newCONSTSUB_flags( stash, "cowrefcnt_max", sizeof("cowrefcnt_max")-1, 0, + &PL_sv_undef); + newCONSTSUB_flags( stash, "can_cow", sizeof("can_cow")-1, 0, &PL_sv_no); +#else + newCONSTSUB_flags( stash, "cowrefcnt_max", sizeof("cowrefcnt_max")-1, 0, + newSViv(SV_COW_REFCNT_MAX)); + newCONSTSUB_flags( stash, "can_cow", sizeof("can_cow")-1, 0, &PL_sv_yes); +#endif +}