This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
hek_dup can now store the HEK rather than the HE, as there is now a
[perl5.git] / pp_sys.c
index 208e0ee..4e2b412 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -321,7 +321,6 @@ PP(pp_backtick)
 {
     dSP; dTARGET;
     PerlIO *fp;
-    STRLEN n_a;
     const char *tmps = POPpconstx;
     const I32 gimme = GIMME_V;
     const char *mode = "r";
@@ -1010,7 +1009,6 @@ PP(pp_sselect)
     struct timeval *tbuf = &timebuf;
     I32 growsize;
     char *fd_sets[4];
-    STRLEN n_a;
 #if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678
        I32 masksize;
        I32 offset;
@@ -1026,9 +1024,16 @@ PP(pp_sselect)
 
     SP -= 4;
     for (i = 1; i <= 3; i++) {
-       if (!SvPOK(SP[i]))
+       SV *sv = SP[i];
+       if (SvOK(sv) && SvREADONLY(sv)) {
+           if (SvIsCOW(sv))
+               sv_force_normal_flags(sv, 0);
+           if (SvREADONLY(sv))
+               DIE(aTHX_ PL_no_modify);
+       }
+       if (!SvPOK(sv))
            continue;
-       j = SvCUR(SP[i]);
+       j = SvCUR(sv);
        if (maxlen < j)
            maxlen = j;
     }
@@ -1082,7 +1087,7 @@ PP(pp_sselect)
            continue;
        }
        else if (!SvPOK(sv))
-           SvPV_force(sv,n_a); /* force string conversion */
+           SvPV_force_nolen(sv);       /* force string conversion */
        j = SvLEN(sv);
        if (j < growsize) {
            Sv_Grow(sv, growsize);
@@ -1817,7 +1822,7 @@ PP(pp_send)
     GV *gv;
     IO *io;
     SV *bufsv;
-    char *buffer;
+    const char *buffer;
     Size_t length;
     SSize_t retval;
     STRLEN blen;
@@ -1866,7 +1871,7 @@ PP(pp_send)
            bufsv = sv_2mortal(newSVsv(bufsv));
            buffer = sv_2pvutf8(bufsv, &blen);
        } else
-           buffer = SvPV(bufsv, blen);
+           buffer = SvPV_const(bufsv, blen);
     }
     else {
         if (DO_UTF8(bufsv)) {
@@ -1874,7 +1879,7 @@ PP(pp_send)
              bufsv = sv_2mortal(newSVsv(bufsv));
              sv_utf8_downgrade(bufsv, FALSE);
         }
-        buffer = SvPV(bufsv, blen);
+        buffer = SvPV_const(bufsv, blen);
     }
 
     if (PL_op->op_type == OP_SYSWRITE) {
@@ -1896,7 +1901,7 @@ PP(pp_send)
        if (length > blen - offset)
            length = blen - offset;
        if (DO_UTF8(bufsv)) {
-           buffer = (char*)utf8_hop((U8 *)buffer, offset);
+           buffer = (const char*)utf8_hop((const U8 *)buffer, offset);
            length = utf8_hop((U8 *)buffer, length) - (U8 *)buffer;
        }
        else {
@@ -2142,8 +2147,7 @@ PP(pp_truncate)
        }
        else {
            SV *sv = POPs;
-           char *name;
-           STRLEN n_a;
+           const char *name;
 
            if (SvTYPE(sv) == SVt_PVGV) {
                tmpgv = (GV*)sv;                /* *main::FRED for example */
@@ -2158,7 +2162,7 @@ PP(pp_truncate)
                goto do_ftruncate_io;
            }
 
-           name = SvPV(sv, n_a);
+           name = SvPV_nolen_const(sv);
            TAINT_PROPER("truncate");
 #ifdef HAS_TRUNCATE
            if (truncate(name, len) < 0)
@@ -2433,7 +2437,8 @@ PP(pp_bind)
     extern void GETUSERMODE();
 #endif
     SV *addrsv = POPs;
-    char *addr;
+    /* OK, so on what platform does bind modify addr?  */
+    const char *addr;
     GV *gv = (GV*)POPs;
     register IO *io = GvIOn(gv);
     STRLEN len;
@@ -2445,7 +2450,7 @@ PP(pp_bind)
     if (!io || !IoIFP(io))
        goto nuts;
 
-    addr = SvPV(addrsv, len);
+    addr = SvPV_const(addrsv, len);
     TAINT_PROPER("bind");
 #ifdef MPE /* Deal with MPE bind() peculiarities */
     if (((struct sockaddr *)addr)->sa_family == AF_INET) {
@@ -2488,7 +2493,7 @@ PP(pp_connect)
 #ifdef HAS_SOCKET
     dSP;
     SV *addrsv = POPs;
-    char *addr;
+    const char *addr;
     GV *gv = (GV*)POPs;
     register IO *io = GvIOn(gv);
     STRLEN len;
@@ -2496,7 +2501,7 @@ PP(pp_connect)
     if (!io || !IoIFP(io))
        goto nuts;
 
-    addr = SvPV(addrsv, len);
+    addr = SvPV_const(addrsv, len);
     TAINT_PROPER("connect");
     if (PerlSock_connect(PerlIO_fileno(IoIFP(io)), (struct sockaddr *)addr, len) >= 0)
        RETPUSHYES;
@@ -2683,16 +2688,16 @@ PP(pp_ssockopt)
        PUSHs(sv);
        break;
     case OP_SSOCKOPT: {
-           char *buf;
+           const char *buf;
            int aint;
            if (SvPOKp(sv)) {
                STRLEN l;
-               buf = SvPV(sv, l);
+               buf = SvPV_const(sv, l);
                len = l;
            }
            else {
                aint = (int)SvIV(sv);
-               buf = (char*)&aint;
+               buf = (const char*)&aint;
                len = sizeof(int);
            }
            if (PerlSock_setsockopt(fd, lvl, optname, buf, len) < 0)
@@ -2756,8 +2761,8 @@ PP(pp_getpeername)
        {
            static const char nowhere[] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
            /* If the call succeeded, make sure we don't have a zeroed port/addr */
-           if (((struct sockaddr *)SvPVX(sv))->sa_family == AF_INET &&
-               !memcmp((char *)SvPVX(sv) + sizeof(u_short), nowhere,
+           if (((struct sockaddr *)SvPVX_const(sv))->sa_family == AF_INET &&
+               !memcmp((char *)SvPVX_const(sv) + sizeof(u_short), nowhere,
                        sizeof(u_short) + sizeof(struct in_addr))) {
                goto nuts2;     
            }
@@ -2801,7 +2806,6 @@ PP(pp_stat)
     GV *gv;
     I32 gimme;
     I32 max = 13;
-    STRLEN n_a;
 
     if (PL_op->op_flags & OPf_REF) {
        gv = cGVOP_gv;
@@ -2841,15 +2845,15 @@ PP(pp_stat)
                        "lstat() on filehandle %s", GvENAME(gv));
            goto do_fstat;
        }
-       sv_setpv(PL_statname, SvPV_const(sv,n_a));
+       sv_setpv(PL_statname, SvPV_nolen_const(sv));
        PL_statgv = Nullgv;
        PL_laststype = PL_op->op_type;
        if (PL_op->op_type == OP_LSTAT)
-           PL_laststatval = PerlLIO_lstat(SvPV(PL_statname, n_a), &PL_statcache);
+           PL_laststatval = PerlLIO_lstat(SvPV_nolen_const(PL_statname), &PL_statcache);
        else
-           PL_laststatval = PerlLIO_stat(SvPV(PL_statname, n_a), &PL_statcache);
+           PL_laststatval = PerlLIO_stat(SvPV_nolen_const(PL_statname), &PL_statcache);
        if (PL_laststatval < 0) {
-           if (ckWARN(WARN_NEWLINE) && strchr(SvPV(PL_statname, n_a), '\n'))
+           if (ckWARN(WARN_NEWLINE) && strchr(SvPV_nolen_const(PL_statname), '\n'))
                Perl_warner(aTHX_ packWARN(WARN_NEWLINE), PL_warn_nl, "stat");
            max = 0;
        }
@@ -2932,7 +2936,6 @@ PP(pp_ftrread)
     STACKED_FTEST_CHECK;
 #if defined(HAS_ACCESS) && defined(R_OK)
     if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
-       STRLEN n_a;
        result = access(POPpx, R_OK);
        if (result == 0)
            RETPUSHYES;
@@ -2960,7 +2963,6 @@ PP(pp_ftrwrite)
     STACKED_FTEST_CHECK;
 #if defined(HAS_ACCESS) && defined(W_OK)
     if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
-       STRLEN n_a;
        result = access(POPpx, W_OK);
        if (result == 0)
            RETPUSHYES;
@@ -2988,7 +2990,6 @@ PP(pp_ftrexec)
     STACKED_FTEST_CHECK;
 #if defined(HAS_ACCESS) && defined(X_OK)
     if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
-       STRLEN n_a;
        result = access(POPpx, X_OK);
        if (result == 0)
            RETPUSHYES;
@@ -3016,7 +3017,6 @@ PP(pp_fteread)
     STACKED_FTEST_CHECK;
 #ifdef PERL_EFF_ACCESS_R_OK
     if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
-       STRLEN n_a;
        result = PERL_EFF_ACCESS_R_OK(POPpx);
        if (result == 0)
            RETPUSHYES;
@@ -3044,7 +3044,6 @@ PP(pp_ftewrite)
     STACKED_FTEST_CHECK;
 #ifdef PERL_EFF_ACCESS_W_OK
     if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
-       STRLEN n_a;
        result = PERL_EFF_ACCESS_W_OK(POPpx);
        if (result == 0)
            RETPUSHYES;
@@ -3072,7 +3071,6 @@ PP(pp_fteexec)
     STACKED_FTEST_CHECK;
 #ifdef PERL_EFF_ACCESS_X_OK
     if ((PL_op->op_private & OPpFT_ACCESS) && SvPOK(TOPs)) {
-       STRLEN n_a;
        result = PERL_EFF_ACCESS_X_OK(POPpx);
        if (result == 0)
            RETPUSHYES;
@@ -3359,8 +3357,7 @@ PP(pp_fttty)
     if (GvIO(gv) && IoIFP(GvIOp(gv)))
        fd = PerlIO_fileno(IoIFP(GvIOp(gv)));
     else if (tmpsv && SvOK(tmpsv)) {
-       STRLEN n_a;
-       char *tmps = SvPV(tmpsv, n_a);
+       const char *tmps = SvPV_nolen_const(tmpsv);
        if (isDIGIT(*tmps))
            fd = atoi(tmps);
        else 
@@ -3392,7 +3389,6 @@ PP(pp_fttext)
     register IO *io;
     register SV *sv;
     GV *gv;
-    STRLEN n_a;
     PerlIO *fp;
 
     STACKED_FTEST_CHECK;
@@ -3461,9 +3457,10 @@ PP(pp_fttext)
       really_filename:
        PL_statgv = Nullgv;
        PL_laststype = OP_STAT;
-       sv_setpv(PL_statname, SvPV(sv, n_a));
+       sv_setpv(PL_statname, SvPV_nolen_const(sv));
        if (!(fp = PerlIO_open(SvPVX_const(PL_statname), "r"))) {
-           if (ckWARN(WARN_NEWLINE) && strchr(SvPV(PL_statname, n_a), '\n'))
+           if (ckWARN(WARN_NEWLINE) && strchr(SvPV_nolen_const(PL_statname),
+                                              '\n'))
                Perl_warner(aTHX_ packWARN(WARN_NEWLINE), PL_warn_nl, "open");
            RETPUSHUNDEF;
        }
@@ -3549,7 +3546,6 @@ PP(pp_chdir)
     dSP; dTARGET;
     const char *tmps;
     SV **svp;
-    STRLEN n_a;
 
     if( MAXARG == 1 )
         tmps = POPpconstx;
@@ -3566,7 +3562,7 @@ PP(pp_chdir)
         {
             if( MAXARG == 1 )
                 deprecate("chdir('') or chdir(undef) as chdir()");
-            tmps = SvPV_const(*svp, n_a);
+            tmps = SvPV_nolen_const(*svp);
         }
         else {
             PUSHi(0);
@@ -3603,7 +3599,6 @@ PP(pp_chroot)
 {
 #ifdef HAS_CHROOT
     dSP; dTARGET;
-    STRLEN n_a;
     char *tmps = POPpx;
     TAINT_PROPER("chroot");
     PUSHi( chroot(tmps) >= 0 );
@@ -3647,7 +3642,6 @@ PP(pp_rename)
 {
     dSP; dTARGET;
     int anum;
-    STRLEN n_a;
     const char *tmps2 = POPpconstx;
     const char *tmps = SvPV_nolen_const(TOPs);
     TAINT_PROPER("rename");
@@ -3673,7 +3667,6 @@ PP(pp_link)
 {
 #ifdef HAS_LINK
     dSP; dTARGET;
-    STRLEN n_a;
     const char *tmps2 = POPpconstx;
     const char *tmps = SvPV_nolen_const(TOPs);
     TAINT_PROPER("link");
@@ -3688,9 +3681,8 @@ PP(pp_symlink)
 {
 #ifdef HAS_SYMLINK
     dSP; dTARGET;
-    STRLEN n_a;
-    char *tmps2 = POPpx;
-    char *tmps = SvPV(TOPs, n_a);
+    const char *tmps2 = POPpconstx;
+    const char *tmps = SvPV_nolen_const(TOPs);
     TAINT_PROPER("symlink");
     SETi( symlink(tmps, tmps2) >= 0 );
     RETURN;
@@ -3707,7 +3699,6 @@ PP(pp_readlink)
     const char *tmps;
     char buf[MAXPATHLEN];
     int len;
-    STRLEN n_a;
 
 #ifndef INCOMPLETE_TAINTS
     TAINT;
@@ -3889,7 +3880,6 @@ PP(pp_open_dir)
 {
 #if defined(Direntry_t) && defined(HAS_READDIR)
     dSP;
-    STRLEN n_a;
     const char *dirname = POPpconstx;
     GV *gv = (GV*)POPs;
     register IO *io = GvIOn(gv);
@@ -4175,7 +4165,6 @@ PP(pp_system)
 {
     dSP; dMARK; dORIGMARK; dTARGET;
     I32 value;
-    STRLEN n_a;
     int result;
 
     if (PL_tainting) {
@@ -4266,7 +4255,7 @@ PP(pp_system)
        else if (SP - MARK != 1)
            value = (I32)do_aexec5(Nullsv, MARK, SP, pp[1], did_pipes);
        else {
-           value = (I32)do_exec3(SvPVx(sv_mortalcopy(*SP), n_a), pp[1], did_pipes);
+           value = (I32)do_exec3(SvPVx_nolen(sv_mortalcopy(*SP)), pp[1], did_pipes);
        }
        PerlProc__exit(-1);
     }
@@ -4289,7 +4278,7 @@ PP(pp_system)
 #  endif
     }
     else {
-       value = (I32)do_spawn(SvPVx(sv_mortalcopy(*SP), n_a));
+       value = (I32)do_spawn(SvPVx_nolen(sv_mortalcopy(*SP)));
     }
     if (PL_statusvalue == -1)  /* hint that value must be returned as is */
        result = 1;
@@ -4305,7 +4294,6 @@ PP(pp_exec)
 {
     dSP; dMARK; dORIGMARK; dTARGET;
     I32 value;
-    STRLEN n_a;
 
     if (PL_tainting) {
        TAINT_ENV();
@@ -4337,13 +4325,13 @@ PP(pp_exec)
 #endif
     else {
 #ifdef VMS
-       value = (I32)vms_do_exec(SvPVx(sv_mortalcopy(*SP), n_a));
+       value = (I32)vms_do_exec(SvPVx_nolen(sv_mortalcopy(*SP)));
 #else
 #  ifdef __OPEN_VM
-       (void) do_spawn(SvPVx(sv_mortalcopy(*SP), n_a));
+       (void) do_spawn(SvPVx_nolen(sv_mortalcopy(*SP)));
        value = 0;
 #  else
-       value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), n_a));
+       value = (I32)do_exec(SvPVx_nolen(sv_mortalcopy(*SP)));
 #  endif
 #endif
     }
@@ -4770,7 +4758,6 @@ PP(pp_ghostent)
 #endif
     struct hostent *hent;
     unsigned long len;
-    STRLEN n_a;
 
     EXTEND(SP, 10);
     if (which == OP_GHBYNAME) {
@@ -4886,7 +4873,6 @@ PP(pp_gnetent)
     struct netent *getnetent(void);
 #endif
     struct netent *nent;
-    STRLEN n_a;
 
     if (which == OP_GNBYNAME){
 #ifdef HAS_GETNETBYNAME
@@ -4987,7 +4973,6 @@ PP(pp_gprotoent)
     struct protoent *getprotoent(void);
 #endif
     struct protoent *pent;
-    STRLEN n_a;
 
     if (which == OP_GPBYNAME) {
 #ifdef HAS_GETPROTOBYNAME
@@ -5074,7 +5059,6 @@ PP(pp_gservent)
     struct servent *getservent(void);
 #endif
     struct servent *sent;
-    STRLEN n_a;
 
     if (which == OP_GSBYNAME) {
 #ifdef HAS_GETSERVBYNAME
@@ -5270,7 +5254,6 @@ PP(pp_gpwent)
     dSP;
     I32 which = PL_op->op_type;
     register SV *sv;
-    STRLEN n_a;
     struct passwd *pwent  = NULL;
     /*
      * We currently support only the SysV getsp* shadow password interface.
@@ -5549,7 +5532,6 @@ PP(pp_ggrent)
     register char **elem;
     register SV *sv;
     struct group *grent;
-    STRLEN n_a;
 
     if (which == OP_GGRNAM) {
         char* name = POPpbytex;
@@ -5661,7 +5643,6 @@ PP(pp_syscall)
     unsigned long a[20];
     register I32 i = 0;
     I32 retval = -1;
-    STRLEN n_a;
 
     if (PL_tainting) {
        while (++MARK <= SP) {
@@ -5684,7 +5665,7 @@ PP(pp_syscall)
        else if (*MARK == &PL_sv_undef)
            a[i++] = 0;
        else
-           a[i++] = (unsigned long)SvPV_force(*MARK, n_a);
+           a[i++] = (unsigned long)SvPV_force_nolen(*MARK);
        if (i > 15)
            break;
     }