summaryrefslogtreecommitdiff
path: root/regexp.h
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2017-07-07 14:13:32 +0100
committerDavid Mitchell <davem@iabyn.com>2017-07-27 11:30:21 +0100
commitdf6b4bd56551f2d39f7c0019c23f27181d8c39c4 (patch)
tree760cb0b40c0f202fe06ae67e0a239156b92597fe /regexp.h
parente8f01ee5fa8087b34dfe31b2c53eef0ba8718922 (diff)
downloadperl-df6b4bd56551f2d39f7c0019c23f27181d8c39c4.tar.gz
give REGEXP SVs the POK flag again
Commit v5.17.5-99-g8d919b0 stopped SVt_REGEXP SVs (and PVLVs acting as regexes) from having the POK and pPOK flags set. This made things like SvOK() and SvTRUE() slower, because as well as the quick single test for any I/N/P/R flags, SvOK() also has to test for (SvTYPE(sv) == SVt_REGEXP || (SvFLAGS(sv) & (SVTYPEMASK|SVp_POK|SVpgv_GP|SVf_FAKE)) == (SVt_PVLV|SVf_FAKE)) This commit fixes the issue fixed by g8d919b0 in a slightly different way, which is less invasive and allows the POK flag. Background: PVLV are basically PVMGs with a few extra fields. They are intended to be a superset of all scalar types, so any scalar value can be assigned to a PVLV SV. However, once REGEXPs were made into first-class scalar SVs, this assumption broke - there are a whole bunch of fields in a regex SV body which can't be copied to to a PVLV. So this broke: sub f { my $r = qr/abc/; # $r is reference to an SVt_REGEXP $_[0] = $$r; } f($h{foo}); # the hash access is deferred - a temporary PVLV is # passed instead The basic idea behind the g8d919b0 fix was, for an LV-acting-as-regex, to attach both a PVLV body and a regex body to the SV head. This commit keeps this basic concept; it just changes how the extra body is attached. The original fix changed SVt_REGEXP SVs so that sv.sv_u.svu_pv no longer pointed to the regexp's string representation; instead this pointer was stored in a union made out of the xpv_len field. Doing this necessitated not turning the POK flag on for any REGEXP SVs. This freed up the sv_u to point to the regex body, while the sv_any field could continue to point to the PVLV body. An ReANY() macro was introduced that returned the sv_u field rather than the sv_any field. This commit changes it so that instead, on regexp SVs (and LV-as-regexp SVs), sv_u always points to the string buffer (so they can have POK set again), but on specifically LV-as-regex SVs, the xpv_len_u union of the PVLV body points to the regexp body. This means that SVt_REGEXP SVs are now completely "normal" again, and SVt_PVLV SVs are normal except in the one case where they hold a regex, in which case rather than storing the string buffer's length, the PVLV body stores a pointer to the regex body.
Diffstat (limited to 'regexp.h')
-rw-r--r--regexp.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/regexp.h b/regexp.h
index 9a2b61a18e..2e4c3b805b 100644
--- a/regexp.h
+++ b/regexp.h
@@ -499,8 +499,9 @@ and check for NULL.
writers? Specifically, the value 1 assumes that the wrapped version always
has exactly one character at the end, a ')'. Will that always be true? */
#define RX_PRELEN(prog) (RX_WRAPLEN(prog) - ReANY(prog)->pre_prefix - 1)
-#define RX_WRAPPED(prog) ReANY(prog)->xpv_len_u.xpvlenu_pv
-#define RX_WRAPPED_const(prog) ((const char *)RX_WRAPPED(prog))
+
+#define RX_WRAPPED(prog) SvPVX(prog)
+#define RX_WRAPPED_const(prog) SvPVX_const(prog)
#define RX_WRAPLEN(prog) SvCUR(prog)
#define RX_CHECK_SUBSTR(prog) (ReANY(prog)->check_substr)
#define RX_REFCNT(prog) SvREFCNT(prog)