-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCOW.xs
83 lines (74 loc) · 1.1 KB
/
COW.xs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
*
* Copyright (c) 2018, Nicolas R.
*
* This is free software; you can redistribute it and/or modify it under the
* same terms as Perl itself.
*
*/
#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>
#include <embed.h>
#if defined(SV_COW_REFCNT_MAX)
# define B_CAN_COW 1
#else
# define B_CAN_COW 0
#endif
/* CowREFCNT is incorrect on Perl < 5.32 */
#define myCowREFCNT(sv) ((SvLEN(sv)>0) ? CowREFCNT(sv) : 0)
MODULE = B__COW PACKAGE = B::COW
PROTOTYPES: DISABLE
SV*
can_cow()
CODE:
{
#if B_CAN_COW
XSRETURN_YES;
#else
XSRETURN_NO;
#endif
}
OUTPUT:
RETVAL
SV*
is_cow(sv)
SV *sv;
CODE:
{
/* not exactly accurate but let's start there */
#if !B_CAN_COW
XSRETURN_UNDEF;
#else
if ( SvPOK(sv) && SvIsCOW(sv) ) XSRETURN_YES;
#endif
XSRETURN_NO;
}
OUTPUT:
RETVAL
SV*
cowrefcnt(sv)
SV *sv;
CODE:
{
#if !B_CAN_COW
XSRETURN_UNDEF;
#else
if ( SvIsCOW(sv) ) XSRETURN_IV( myCowREFCNT(sv) );
#endif
XSRETURN_UNDEF;
}
OUTPUT:
RETVAL
SV*
cowrefcnt_max()
CODE:
{
#if !B_CAN_COW
XSRETURN_UNDEF;
#else
XSRETURN_IV(SV_COW_REFCNT_MAX);
#endif
}
OUTPUT:
RETVAL