This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add missing close paren in pod
[perl5.git] / doop.c
diff --git a/doop.c b/doop.c
index e31fae2..6a136d9 100644 (file)
--- a/doop.c
+++ b/doop.c
@@ -15,8 +15,8 @@
  */
 
 /* This file contains some common functions needed to carry out certain
- * ops. For example both pp_schomp() and pp_chomp() - scalar and array
- * chomp operations - call the function do_chomp() found in this file.
+ * ops. For example, both pp_sprintf() and pp_prtf() call the function
+ * do_printf() found in this file.
  */
 
 #include "EXTERN.h"
@@ -30,7 +30,6 @@
 STATIC I32
 S_do_trans_simple(pTHX_ SV * const sv)
 {
-    dVAR;
     I32 matches = 0;
     STRLEN len;
     U8 *s = (U8*)SvPV_nomg(sv,len);
@@ -99,7 +98,6 @@ S_do_trans_simple(pTHX_ SV * const sv)
 STATIC I32
 S_do_trans_count(pTHX_ SV * const sv)
 {
-    dVAR;
     STRLEN len;
     const U8 *s = (const U8*)SvPV_nomg_const(sv, len);
     const U8 * const send = s + len;
@@ -137,7 +135,6 @@ S_do_trans_count(pTHX_ SV * const sv)
 STATIC I32
 S_do_trans_complex(pTHX_ SV * const sv)
 {
-    dVAR;
     STRLEN len;
     U8 *s = (U8*)SvPV_nomg(sv, len);
     U8 * const send = s+len;
@@ -301,7 +298,6 @@ S_do_trans_complex(pTHX_ SV * const sv)
 STATIC I32
 S_do_trans_simple_utf8(pTHX_ SV * const sv)
 {
-    dVAR;
     U8 *s;
     U8 *send;
     U8 *d;
@@ -331,7 +327,7 @@ S_do_trans_simple_utf8(pTHX_ SV * const sv)
        const U8 * const e = s + len;
        while (t < e) {
            const U8 ch = *t++;
-           hibit = !NATIVE_IS_INVARIANT(ch);
+           hibit = !NATIVE_BYTE_IS_INVARIANT(ch);
            if (hibit) {
                s = bytes_to_utf8(s, &len);
                break;
@@ -361,7 +357,7 @@ S_do_trans_simple_utf8(pTHX_ SV * const sv)
        if (uv < none) {
            s += UTF8SKIP(s);
            matches++;
-           d = uvuni_to_utf8(d, uv);
+           d = uvchr_to_utf8(d, uv);
        }
        else if (uv == none) {
            const int i = UTF8SKIP(s);
@@ -372,7 +368,7 @@ S_do_trans_simple_utf8(pTHX_ SV * const sv)
        else if (uv == extra) {
            s += UTF8SKIP(s);
            matches++;
-           d = uvuni_to_utf8(d, final);
+           d = uvchr_to_utf8(d, final);
        }
        else
            s += UTF8SKIP(s);
@@ -406,7 +402,6 @@ S_do_trans_simple_utf8(pTHX_ SV * const sv)
 STATIC I32
 S_do_trans_count_utf8(pTHX_ SV * const sv)
 {
-    dVAR;
     const U8 *s;
     const U8 *start = NULL;
     const U8 *send;
@@ -432,7 +427,7 @@ S_do_trans_count_utf8(pTHX_ SV * const sv)
        const U8 * const e = s + len;
        while (t < e) {
            const U8 ch = *t++;
-           hibit = !NATIVE_IS_INVARIANT(ch);
+           hibit = !NATIVE_BYTE_IS_INVARIANT(ch);
            if (hibit) {
                start = s = bytes_to_utf8(s, &len);
                break;
@@ -456,7 +451,6 @@ S_do_trans_count_utf8(pTHX_ SV * const sv)
 STATIC I32
 S_do_trans_complex_utf8(pTHX_ SV * const sv)
 {
-    dVAR;
     U8 *start, *send;
     U8 *d;
     I32 matches = 0;
@@ -487,7 +481,7 @@ S_do_trans_complex_utf8(pTHX_ SV * const sv)
        const U8 * const e = s + len;
        while (t < e) {
            const U8 ch = *t++;
-           hibit = !NATIVE_IS_INVARIANT(ch);
+           hibit = !NATIVE_BYTE_IS_INVARIANT(ch);
            if (hibit) {
                s = bytes_to_utf8(s, &len);
                break;
@@ -532,7 +526,7 @@ S_do_trans_complex_utf8(pTHX_ SV * const sv)
                matches++;
                s += UTF8SKIP(s);
                if (uv != puv) {
-                   d = uvuni_to_utf8(d, uv);
+                   d = uvchr_to_utf8(d, uv);
                    puv = uv;
                }
                continue;
@@ -550,13 +544,13 @@ S_do_trans_complex_utf8(pTHX_ SV * const sv)
                if (havefinal) {
                    s += UTF8SKIP(s);
                    if (puv != final) {
-                       d = uvuni_to_utf8(d, final);
+                       d = uvchr_to_utf8(d, final);
                        puv = final;
                    }
                }
                else {
                    STRLEN len;
-                   uv = utf8n_to_uvuni(s, send - s, &len, UTF8_ALLOW_DEFAULT);
+                   uv = utf8n_to_uvchr(s, send - s, &len, UTF8_ALLOW_DEFAULT);
                    if (uv != puv) {
                        Move(s, d, len, U8);
                        d += len;
@@ -585,7 +579,7 @@ S_do_trans_complex_utf8(pTHX_ SV * const sv)
            if (uv < none) {
                matches++;
                s += UTF8SKIP(s);
-               d = uvuni_to_utf8(d, uv);
+               d = uvchr_to_utf8(d, uv);
                continue;
            }
            else if (uv == none) {      /* "none" is unmapped character */
@@ -598,7 +592,7 @@ S_do_trans_complex_utf8(pTHX_ SV * const sv)
            else if (uv == extra && !del) {
                matches++;
                s += UTF8SKIP(s);
-               d = uvuni_to_utf8(d, final);
+               d = uvchr_to_utf8(d, final);
                continue;
            }
            matches++;                  /* "none+1" is delete character */
@@ -624,7 +618,6 @@ S_do_trans_complex_utf8(pTHX_ SV * const sv)
 I32
 Perl_do_trans(pTHX_ SV *sv)
 {
-    dVAR;
     STRLEN len;
     const I32 hasutf = (PL_op->op_private &
                     (OPpTRANS_FROM_UTF|OPpTRANS_TO_UTF));
@@ -632,17 +625,14 @@ Perl_do_trans(pTHX_ SV *sv)
     PERL_ARGS_ASSERT_DO_TRANS;
 
     if (SvREADONLY(sv) && !(PL_op->op_private & OPpTRANS_IDENTICAL)) {
-        if (SvIsCOW(sv))
-            sv_force_normal_flags(sv, 0);
-        if (SvREADONLY(sv))
-            Perl_croak_no_modify(aTHX);
+            Perl_croak_no_modify();
     }
     (void)SvPV_const(sv, len);
     if (!len)
        return 0;
     if (!(PL_op->op_private & OPpTRANS_IDENTICAL)) {
-       if (!SvPOKp(sv))
-           (void)SvPV_force(sv, len);
+       if (!SvPOKp(sv) || SvTHINKFIRST(sv))
+           (void)SvPV_force_nomg(sv, len);
        (void)SvPOK_only_UTF8(sv);
     }
 
@@ -673,12 +663,11 @@ Perl_do_trans(pTHX_ SV *sv)
 }
 
 void
-Perl_do_join(pTHX_ register SV *sv, SV *delim, register SV **mark, register SV **sp)
+Perl_do_join(pTHX_ SV *sv, SV *delim, SV **mark, SV **sp)
 {
-    dVAR;
     SV ** const oldmark = mark;
-    register I32 items = sp - mark;
-    register STRLEN len;
+    I32 items = sp - mark;
+    STRLEN len;
     STRLEN delimlen;
 
     PERL_ARGS_ASSERT_DO_JOIN;
@@ -709,7 +698,7 @@ Perl_do_join(pTHX_ register SV *sv, SV *delim, register SV **mark, register SV *
     /* sv_setpv retains old UTF8ness [perl #24846] */
     SvUTF8_off(sv);
 
-    if (PL_tainting && SvMAGICAL(sv))
+    if (TAINTING_get && SvMAGICAL(sv))
        SvTAINTED_off(sv);
 
     if (items-- > 0) {
@@ -720,7 +709,7 @@ Perl_do_join(pTHX_ register SV *sv, SV *delim, register SV **mark, register SV *
 
     if (delimlen) {
        for (; items > 0; items--,mark++) {
-           sv_catsv(sv,delim);
+           sv_catsv_nomg(sv,delim);
            sv_catsv(sv,*mark);
        }
     }
@@ -734,7 +723,6 @@ Perl_do_join(pTHX_ register SV *sv, SV *delim, register SV **mark, register SV *
 void
 Perl_do_sprintf(pTHX_ SV *sv, I32 len, SV **sarg)
 {
-    dVAR;
     STRLEN patlen;
     const char * const pat = SvPV_const(*sarg, patlen);
     bool do_taint = FALSE;
@@ -760,13 +748,19 @@ Perl_do_sprintf(pTHX_ SV *sv, I32 len, SV **sarg)
 
 /* currently converts input to bytes if possible, but doesn't sweat failure */
 UV
-Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size)
+Perl_do_vecget(pTHX_ SV *sv, SSize_t offset, int size)
 {
-    dVAR;
     STRLEN srclen, len, uoffset, bitoffs = 0;
-    const unsigned char *s = (const unsigned char *) SvPV_const(sv, srclen);
+    const I32 svpv_flags = ((PL_op->op_flags & OPf_MOD || LVRET)
+                                          ? SV_UNDEF_RETURNS_NULL : 0);
+    unsigned char *s = (unsigned char *)
+                            SvPV_flags(sv, srclen, (svpv_flags|SV_GMAGIC));
     UV retnum = 0;
 
+    if (!s) {
+      s = (unsigned char *)"";
+    }
+    
     PERL_ARGS_ASSERT_DO_VECGET;
 
     if (offset < 0)
@@ -774,8 +768,11 @@ Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size)
     if (size < 1 || (size & (size-1))) /* size < 1 or not a power of two */
        Perl_croak(aTHX_ "Illegal number of bits in vec");
 
-    if (SvUTF8(sv))
+    if (SvUTF8(sv)) {
        (void) Perl_sv_utf8_downgrade(aTHX_ sv, TRUE);
+        /* PVX may have changed */
+        s = (unsigned char *) SvPV_flags(sv, srclen, svpv_flags);
+    }
 
     if (size < 8) {
        bitoffs = ((offset%8)*size)%8;
@@ -843,7 +840,7 @@ Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size)
                        ((UV) s[uoffset + 1] << 48) +
                        ((UV) s[uoffset + 2] << 40) +
                        ((UV) s[uoffset + 3] << 32) +
-                       (     s[uoffset + 4] << 24);
+                       ((UV) s[uoffset + 4] << 24);
                else if (uoffset + 6 >= srclen)
                    retnum =
                        ((UV) s[uoffset    ] << 56) +
@@ -860,7 +857,7 @@ Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size)
                        ((UV) s[uoffset + 3] << 32) +
                        ((UV) s[uoffset + 4] << 24) +
                        ((UV) s[uoffset + 5] << 16) +
-                       (     s[uoffset + 6] <<  8);
+                       ((UV) s[uoffset + 6] <<  8);
            }
 #endif
        }
@@ -907,11 +904,10 @@ Perl_do_vecget(pTHX_ SV *sv, I32 offset, I32 size)
 void
 Perl_do_vecset(pTHX_ SV *sv)
 {
-    dVAR;
-    register I32 offset, bitoffs = 0;
-    register I32 size;
-    register unsigned char *s;
-    register UV lval;
+    SSize_t offset, bitoffs = 0;
+    int size;
+    unsigned char *s;
+    UV lval;
     I32 mask;
     STRLEN targlen;
     STRLEN len;
@@ -921,7 +917,8 @@ Perl_do_vecset(pTHX_ SV *sv)
 
     if (!targ)
        return;
-    s = (unsigned char*)SvPV_force(targ, targlen);
+    s = (unsigned char*)SvPV_force_flags(targ, targlen,
+                                         SV_GMAGIC | SV_UNDEF_RETURNS_NULL);
     if (SvUTF8(targ)) {
        /* This is handled by the SvPOK_only below...
        if (!Perl_sv_utf8_downgrade(aTHX_ targ, TRUE))
@@ -993,18 +990,17 @@ Perl_do_vecset(pTHX_ SV *sv)
 void
 Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
 {
-    dVAR;
 #ifdef LIBERAL
-    register long *dl;
-    register long *ll;
-    register long *rl;
+    long *dl;
+    long *ll;
+    long *rl;
 #endif
-    register char *dc;
+    char *dc;
     STRLEN leftlen;
     STRLEN rightlen;
-    register const char *lc;
-    register const char *rc;
-    register STRLEN len;
+    const char *lc;
+    const char *rc;
+    STRLEN len;
     STRLEN lensave;
     const char *lsave;
     const char *rsave;
@@ -1014,7 +1010,7 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
 
     PERL_ARGS_ASSERT_DO_VOP;
 
-    if (sv != left || (optype != OP_BIT_AND && !SvOK(sv) && !SvGMAGICAL(sv)))
+    if (sv != left || (optype != OP_BIT_AND && !SvOK(sv)))
        sv_setpvs(sv, "");      /* avoid undef warning on |= and ^= */
     if (sv == left) {
        lsave = lc = SvPV_force_nomg(left, leftlen);
@@ -1124,12 +1120,12 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
            else if (lulen)
                dcsave = savepvn(lc, lulen);
            if (sv == left || sv == right)
-               (void)sv_usepvn(sv, dcorig, needlen); /* Uses Renew(). */
+               (void)sv_usepvn(sv, dcorig, needlen); /* uses Renew(); defaults to nomg */
            SvCUR_set(sv, dc - dcorig);
            if (rulen)
-               sv_catpvn(sv, dcsave, rulen);
+               sv_catpvn_nomg(sv, dcsave, rulen);
            else if (lulen)
-               sv_catpvn(sv, dcsave, lulen);
+               sv_catpvn_nomg(sv, dcsave, lulen);
            else
                *SvEND(sv) = '\0';
            Safefree(dcsave);
@@ -1207,9 +1203,9 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
          mop_up:
            len = lensave;
            if (rightlen > len)
-               sv_catpvn(sv, rsave + len, rightlen - len);
+               sv_catpvn_nomg(sv, rsave + len, rightlen - len);
            else if (leftlen > (STRLEN)len)
-               sv_catpvn(sv, lsave + len, leftlen - len);
+               sv_catpvn_nomg(sv, lsave + len, leftlen - len);
            else
                *SvEND(sv) = '\0';
            break;
@@ -1222,10 +1218,9 @@ finish:
 OP *
 Perl_do_kv(pTHX)
 {
-    dVAR;
     dSP;
     HV * const keys = MUTABLE_HV(POPs);
-    register HE *entry;
+    HE *entry;
     const I32 gimme = GIMME_V;
     const I32 dokv =     (PL_op->op_type == OP_RV2HV || PL_op->op_type == OP_PADHV);
     /* op_type is OP_RKEYS/OP_RVALUES if pp_rkeys delegated to here */
@@ -1290,8 +1285,8 @@ Perl_do_kv(pTHX)
  * Local variables:
  * c-indentation-style: bsd
  * c-basic-offset: 4
- * indent-tabs-mode: t
+ * indent-tabs-mode: nil
  * End:
  *
- * ex: set ts=8 sts=4 sw=4 noet:
+ * ex: set ts=8 sts=4 sw=4 et:
  */