Skip to content

Commit bd90fa4

Browse files
leonerddemerphq
authored andcommitted
sv.h - encode the misc SV_* flags using bitshifts
Using decimal integers is confusing, so we show the hex and decimal values as a comment. Note: Yves edited the commit message and added the commented values.
1 parent 02bb7ca commit bd90fa4

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

sv.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,31 +2055,33 @@ Returns the hash for C<sv> created by C<L</newSVpvn_share>>.
20552055
=cut
20562056
*/
20572057

2058-
#define SV_IMMEDIATE_UNREF 1
2059-
#define SV_GMAGIC 2
2060-
#define SV_COW_DROP_PV 4
2061-
#define SV_NOSTEAL 16
2062-
#define SV_CONST_RETURN 32
2063-
#define SV_MUTABLE_RETURN 64
2064-
#define SV_SMAGIC 128
2065-
#define SV_HAS_TRAILING_NUL 256
2066-
#define SV_COW_SHARED_HASH_KEYS 512
2058+
/* Flags used as `U32 flags` arguments to various functions */
2059+
#define SV_IMMEDIATE_UNREF (1 << 0) /* 0x0001 - 1 */
2060+
#define SV_GMAGIC (1 << 1) /* 0x0002 - 2 */
2061+
#define SV_COW_DROP_PV (1 << 2) /* 0x0004 - 4 */
2062+
#define SV_FLAG_BIT3_UNUSED (1 << 3) /* 0x0008 - 8 */
2063+
#define SV_NOSTEAL (1 << 4) /* 0x0010 - 16 */
2064+
#define SV_CONST_RETURN (1 << 5) /* 0x0020 - 32 */
2065+
#define SV_MUTABLE_RETURN (1 << 6) /* 0x0040 - 64 */
2066+
#define SV_SMAGIC (1 << 7) /* 0x0080 - 128 */
2067+
#define SV_HAS_TRAILING_NUL (1 << 8) /* 0x0100 - 256 */
2068+
#define SV_COW_SHARED_HASH_KEYS (1 << 9) /* 0x0200 - 512 */
20672069
/* This one is only enabled for PERL_OLD_COPY_ON_WRITE */
20682070
/* XXX This flag actually enabled for any COW. But it appears not to do
20692071
anything. Can we just remove it? Or will it serve some future
20702072
purpose. */
2071-
#define SV_COW_OTHER_PVS 1024
2073+
#define SV_COW_OTHER_PVS (1 << 10) /* 0x0400 - 1024 */
20722074
/* Make sv_2pv_flags return NULL if something is undefined. */
2073-
#define SV_UNDEF_RETURNS_NULL 2048
2075+
#define SV_UNDEF_RETURNS_NULL (1 << 11) /* 0x0800 - 2048 */
20742076
/* Tell sv_utf8_upgrade() to not check to see if an upgrade is really needed.
20752077
* This is used when the caller has already determined it is, and avoids
20762078
* redundant work */
2077-
#define SV_FORCE_UTF8_UPGRADE 4096
2079+
#define SV_FORCE_UTF8_UPGRADE (1 << 12) /* 0x1000 - 4096 */
20782080
/* if (after resolving magic etc), the SV is found to be overloaded,
20792081
* don't call the overload magic, just return as-is */
2080-
#define SV_SKIP_OVERLOAD 8192
2081-
#define SV_CATBYTES 16384
2082-
#define SV_CATUTF8 32768
2082+
#define SV_SKIP_OVERLOAD (1 << 13) /* 0x2000 - 8192 */
2083+
#define SV_CATBYTES (1 << 14) /* 0x4000 - 16384 */
2084+
#define SV_CATUTF8 (1 << 15) /* 0x8000 - 32768 */
20832085

20842086
/* The core is safe for this COW optimisation. XS code on CPAN may not be.
20852087
So only default to doing the COW setup if we're in the core.

0 commit comments

Comments
 (0)