This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove remaining assignments to SvCUR and SvLEN in core
authorDagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Thu, 19 Oct 2017 09:48:49 +0000 (10:48 +0100)
committerDagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Tue, 28 May 2019 12:43:53 +0000 (13:43 +0100)
Also make the macros non-lvalues under PERL_CORE

doop.c
ext/XS-APItest/APItest.pm
ext/XS-APItest/APItest.xs
gv.c
pp.c
sv.h
t/porting/customized.dat
toke.c
vutil.c

diff --git a/doop.c b/doop.c
index 54e35f1..772c158 100644 (file)
--- a/doop.c
+++ b/doop.c
@@ -1200,13 +1200,13 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
         len = lensave;
         if (rightlen > len) {
             if (dc == rc)
-                SvCUR(sv) = rightlen;
+                SvCUR_set(sv, rightlen);
             else
                 sv_catpvn_nomg(sv, rsave + len, rightlen - len);
         }
         else if (leftlen > len) {
             if (dc == lc)
-                SvCUR(sv) = leftlen;
+                SvCUR_set(sv, leftlen);
             else
                 sv_catpvn_nomg(sv, lsave + len, leftlen - len);
         }
index ba76d8f..a4573b9 100644 (file)
@@ -5,7 +5,7 @@ use strict;
 use warnings;
 use Carp;
 
-our $VERSION = '1.00';
+our $VERSION = '1.01';
 
 require XSLoader;
 
index e77ff44..904462e 100644 (file)
@@ -1339,7 +1339,7 @@ my_ck_rv2cv(pTHX_ OP *o)
     {
        SvGROW(ref, SvCUR(ref)+2);
        *SvEND(ref) = '_';
-       SvCUR(ref)++;
+       SvCUR(ref)++; /* Not _set, so we don't accidentally break non-PERL_CORE */
        *SvEND(ref) = '\0';
     }
     return old_ck_rv2cv(aTHX_ o);
diff --git a/gv.c b/gv.c
index 3b8759e..46a32dc 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -1266,7 +1266,7 @@ Perl_gv_autoload_pvn(pTHX_ HV *stash, const char *name, STRLEN len, U32 flags)
            if (SvUTF8(cv))
                sv_utf8_upgrade_flags_grow(tmpsv, 0, CvPROTOLEN(cv) + 2);
            ulen = SvCUR(tmpsv);
-           SvCUR(tmpsv)++; /* include null in string */
+           SvCUR_set(tmpsv, SvCUR(tmpsv) + 1); /* include null in string */
            sv_catpvn_flags(
                tmpsv, proto, CvPROTOLEN(cv), SV_CATBYTES*!SvUTF8(cv)
            );
@@ -1275,7 +1275,7 @@ Perl_gv_autoload_pvn(pTHX_ HV *stash, const char *name, STRLEN len, U32 flags)
            SvTEMP_off(tmpsv);
            SvREFCNT_dec_NN(tmpsv);
            SvLEN_set(cv, SvCUR(cv) + 1);
-           SvCUR(cv) = ulen;
+           SvCUR_set(cv, ulen);
        }
        else {
          sv_setpvn((SV *)cv, name, len);
diff --git a/pp.c b/pp.c
index 62a548b..26c682d 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -2543,7 +2543,7 @@ S_scomplement(pTHX_ SV *targ, SV *sv)
             if (len && ! utf8_to_bytes(tmps, &len)) {
                 Perl_croak(aTHX_ FATAL_ABOVE_FF_MSG, PL_op_desc[PL_op->op_type]);
             }
-            SvCUR(TARG) = len;
+            SvCUR_set(TARG, len);
             SvUTF8_off(TARG);
         }
 
diff --git a/sv.h b/sv.h
index 3a648e4..637cd14 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -1170,7 +1170,11 @@ object type. Exposed to perl code via Internals::SvREADONLY().
 #  define SvMAGIC(sv)  (0 + *(assert_(SvTYPE(sv) >= SVt_PVMG) &((XPVMG*)  SvANY(sv))->xmg_u.xmg_magic))
 #  define SvSTASH(sv)  (0 + *(assert_(SvTYPE(sv) >= SVt_PVMG) &((XPVMG*)  SvANY(sv))->xmg_stash))
 #else
+# ifdef PERL_CORE
+#  define SvLEN(sv) (0 + ((XPV*) SvANY(sv))->xpv_len)
+# else
 #  define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
+# endif
 #  define SvEND(sv) ((sv)->sv_u.svu_pv + ((XPV*)SvANY(sv))->xpv_cur)
 
 #  if defined (DEBUGGING) && defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
@@ -1183,6 +1187,16 @@ object type. Exposed to perl code via Internals::SvREADONLY().
                     && !(IoFLAGS(_svpvx) & IOf_FAKE_DIRP)));           \
            &((_svpvx)->sv_u.svu_pv);                                   \
         }))
+#   ifdef PERL_CORE
+#    define SvCUR(sv)                                                  \
+       ({ const SV *const _svcur = (const SV *)(sv);                   \
+           assert(PL_valid_types_PVX[SvTYPE(_svcur) & SVt_MASK]);      \
+           assert(!isGV_with_GP(_svcur));                              \
+           assert(!(SvTYPE(_svcur) == SVt_PVIO                         \
+                    && !(IoFLAGS(_svcur) & IOf_FAKE_DIRP)));           \
+           (((XPV*) MUTABLE_PTR(SvANY(_svcur)))->xpv_cur);             \
+        })
+#   else
 #    define SvCUR(sv)                                                  \
        (*({ const SV *const _svcur = (const SV *)(sv);                 \
            assert(PL_valid_types_PVX[SvTYPE(_svcur) & SVt_MASK]);      \
@@ -1191,6 +1205,7 @@ object type. Exposed to perl code via Internals::SvREADONLY().
                     && !(IoFLAGS(_svcur) & IOf_FAKE_DIRP)));           \
            &(((XPV*) MUTABLE_PTR(SvANY(_svcur)))->xpv_cur);            \
         }))
+#   endif
 #    define SvIVX(sv)                                                  \
        (*({ const SV *const _svivx = (const SV *)(sv);                 \
            assert(PL_valid_types_IVX[SvTYPE(_svivx) & SVt_MASK]);      \
index dd41c3d..f710639 100644 (file)
@@ -26,4 +26,4 @@ autodie cpan/autodie/t/mkdir.t 9e70d2282a3cc7d76a78bf8144fccba20fb37dac
 autodie cpan/autodie/t/recv.t 63bea2daa330e44b67714527ddf701c1bf3a6954
 experimental cpan/experimental/t/basic.t cb9da8dd05b854375809872a05dd32637508d5da
 version cpan/version/lib/version.pm 7ef9219d1d5f1d71f08a79f3b0577df138b21b12
-version vutil.c 105543ef1824fbc2429a7d5ebd19189c8081fede
+version vutil.c 317c25a807f9503282d58917a4a53b667232a6c5
diff --git a/toke.c b/toke.c
index 03c4f2b..b0fa2c3 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -1334,7 +1334,7 @@ Perl_lex_next_chunk(pTHX_ U32 flags)
            PL_parser->last_lop = NULL;
        last_uni_pos = last_lop_pos = 0;
        *buf = 0;
-       SvCUR(linestr) = 0;
+       SvCUR_set(linestr, 0);
     } else {
        old_bufend_pos = PL_parser->bufend - buf;
        bufptr_pos = PL_parser->bufptr - buf;
diff --git a/vutil.c b/vutil.c
index 2367489..4314fb9 100644 (file)
--- a/vutil.c
+++ b/vutil.c
@@ -533,7 +533,7 @@ Perl_new_version(pTHX_ SV *ver)
            under = ninstr(raw, raw+len, underscore, underscore + 1);
            if (under) {
                Move(under + 1, under, raw + len - under - 1, char);
-               SvCUR(rv)--;
+               SvCUR_set(rv, SvCUR(rv) - 1);
                *SvEND(rv) = '\0';
            }
            /* this is for consistency with the pure Perl class */