Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions COW.xs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
*/

#define PERL_NO_GET_CONTEXT
#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>
Expand All @@ -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:
Expand All @@ -38,6 +46,8 @@ CODE:
OUTPUT:
RETVAL

#endif

SV*
is_cow(sv)
SV *sv;
Expand Down Expand Up @@ -69,6 +79,10 @@ CODE:
OUTPUT:
RETVAL


# Converted to newCONSTSUB_flags()
#if 0

SV*
cowrefcnt_max()
CODE:
Expand All @@ -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
}