Don't test the core XS code yet with PERL_DEBUG_COW > 1
[p5sagit/p5-mst-13.2.git] / doio.c
diff --git a/doio.c b/doio.c
index e9effd9..79ca1fd 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -81,6 +81,7 @@ Perl_do_openn(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
              int rawmode, int rawperm, PerlIO *supplied_fp, SV **svp,
              I32 num_svs)
 {
+    dVAR;
     register IO *io = GvIOn(gv);
     PerlIO *saveifp = Nullfp;
     PerlIO *saveofp = Nullfp;
@@ -102,7 +103,7 @@ Perl_do_openn(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
     /* Collect default raw/crlf info from the op */
     if (PL_op && PL_op->op_type == OP_OPEN) {
        /* set up IO layers */
-       U8 flags = PL_op->op_private;
+       const U8 flags = PL_op->op_private;
        in_raw = (flags & OPpOPEN_IN_RAW);
        in_crlf = (flags & OPpOPEN_IN_CRLF);
        out_raw = (flags & OPpOPEN_OUT_RAW);
@@ -219,7 +220,6 @@ Perl_do_openn(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
 
        if (num_svs) {
            /* New style explicit name, type is just mode and layer info */
-           STRLEN l = 0;
 #ifdef USE_STDIO
            if (SvROK(*svp) && !strchr(name,'&')) {
                if (ckWARN(WARN_IO))
@@ -229,9 +229,7 @@ Perl_do_openn(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
                goto say_false;
            }
 #endif /* USE_STDIO */
-           name = SvOK(*svp) ? SvPV(*svp, l) : "";
-           len = (I32)l;
-           name = savepvn(name, len);
+           name = SvOK(*svp) ? savesvpv (*svp) : savepvn ("", 0);
            SAVEFREEPV(name);
        }
        else {
@@ -675,12 +673,12 @@ Perl_do_openn(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
 
                 LOCK_FDPID_MUTEX;
                 sv = *av_fetch(PL_fdpid,fd,TRUE);
-                (void)SvUPGRADE(sv, SVt_IV);
+                SvUPGRADE(sv, SVt_IV);
                 pid = SvIVX(sv);
-                SvIVX(sv) = 0;
+                SvIV_set(sv, 0);
                 sv = *av_fetch(PL_fdpid,savefd,TRUE);
-                (void)SvUPGRADE(sv, SVt_IV);
-                SvIVX(sv) = pid;
+                SvUPGRADE(sv, SVt_IV);
+                SvIV_set(sv, pid);
                 UNLOCK_FDPID_MUTEX;
             }
 #endif
@@ -824,7 +822,7 @@ Perl_nextargv(pTHX_ register GV *gv)
                        sv_catpv(sv,PL_inplace);
                    }
 #ifndef FLEXFILENAMES
-                   if ((PerlLIO_stat(SvPVX(sv),&PL_statbuf) >= 0
+                   if ((PerlLIO_stat(SvPVX_const(sv),&PL_statbuf) >= 0
                         && PL_statbuf.st_dev == filedev
                         && PL_statbuf.st_ino == fileino)
 #ifdef DJGPP
@@ -842,7 +840,7 @@ Perl_nextargv(pTHX_ register GV *gv)
 #endif
 #ifdef HAS_RENAME
 #if !defined(DOSISH) && !defined(__CYGWIN__) && !defined(EPOC)
-                   if (PerlLIO_rename(PL_oldname,SvPVX(sv)) < 0) {
+                   if (PerlLIO_rename(PL_oldname,SvPVX_const(sv)) < 0) {
                        if (ckWARN_d(WARN_INPLACE))     
                            Perl_warner(aTHX_ packWARN(WARN_INPLACE),
                              "Can't rename %s to %"SVf": %s, skipping file",
@@ -852,13 +850,13 @@ Perl_nextargv(pTHX_ register GV *gv)
                    }
 #else
                    do_close(gv,FALSE);
-                   (void)PerlLIO_unlink(SvPVX(sv));
-                   (void)PerlLIO_rename(PL_oldname,SvPVX(sv));
+                   (void)PerlLIO_unlink(SvPVX_const(sv));
+                   (void)PerlLIO_rename(PL_oldname,SvPVX_const(sv));
                    do_open(gv,SvPVX(sv),SvCUR(sv),PL_inplace!=0,O_RDONLY,0,Nullfp);
 #endif /* DOSISH */
 #else
-                   (void)UNLINK(SvPVX(sv));
-                   if (link(PL_oldname,SvPVX(sv)) < 0) {
+                   (void)UNLINK(SvPVX_const(sv));
+                   if (link(PL_oldname,SvPVX_const(sv)) < 0) {
                        if (ckWARN_d(WARN_INPLACE))     
                            Perl_warner(aTHX_ packWARN(WARN_INPLACE),
                              "Can't rename %s to %"SVf": %s, skipping file",
@@ -928,7 +926,7 @@ Perl_nextargv(pTHX_ register GV *gv)
        }
        else {
            if (ckWARN_d(WARN_INPLACE)) {
-               int eno = errno;
+               const int eno = errno;
                if (PerlLIO_stat(PL_oldname, &PL_statbuf) >= 0
                    && !S_ISREG(PL_statbuf.st_mode))    
                {
@@ -1042,14 +1040,13 @@ bool
 Perl_io_close(pTHX_ IO *io, bool not_implicit)
 {
     bool retval = FALSE;
-    int status;
 
     if (IoIFP(io)) {
        if (IoTYPE(io) == IoTYPE_PIPE) {
-           status = PerlProc_pclose(IoIFP(io));
+           const int status = PerlProc_pclose(IoIFP(io));
            if (not_implicit) {
                STATUS_NATIVE_SET(status);
-               retval = (STATUS_POSIX == 0);
+               retval = (STATUS_UNIX == 0);
            }
            else {
                retval = (status != -1);
@@ -1179,7 +1176,7 @@ Perl_mode_from_discipline(pTHX_ SV *discp)
     int mode = O_BINARY;
     if (discp) {
        STRLEN len;
-       char *s = SvPV(discp,len);
+       const char *s = SvPV_const(discp,len);
        while (*s) {
            if (*s == ':') {
                switch (s[1]) {
@@ -1212,7 +1209,7 @@ Perl_mode_from_discipline(pTHX_ SV *discp)
                --len;
            }
            else {
-               char *end;
+               const char *end;
 fail_discipline:
                end = strchr(s+1, ':');
                if (!end)
@@ -1244,9 +1241,8 @@ Perl_do_binmode(pTHX_ PerlIO *fp, int iotype, int mode)
 }
 
 #if !defined(HAS_TRUNCATE) && !defined(HAS_CHSIZE)
-I32 my_chsize(fd, length)
-I32 fd;                        /* file descriptor */
-Off_t length;          /* length to set file to */
+I32
+my_chsize(int fd, Off_t length)
 {
 #ifdef F_FREESP
        /* code courtesy of William Kucharski */
@@ -1290,12 +1286,11 @@ Off_t length;           /* length to set file to */
            return -1;
 
     }
-
     return 0;
 #else
-    dTHX;
-    DIE(aTHX_ "truncate not implemented");
+    Perl_croak_nocontext("truncate not implemented");
 #endif /* F_FREESP */
+    return -1;
 }
 #endif /* !HAS_TRUNCATE && !HAS_CHSIZE */
 
@@ -1350,7 +1345,7 @@ Perl_do_print(pTHX_ register SV *sv, PerlIO *fp)
                Perl_warner(aTHX_ packWARN(WARN_UTF8), "Wide character in print");
            }
        }
-       tmps = SvPV(sv, len);
+       tmps = SvPV_const(sv, len);
        break;
     }
     /* To detect whether the process is about to overstep its
@@ -1378,7 +1373,7 @@ Perl_my_stat(pTHX)
        io = GvIO(gv);
        if (io && IoIFP(io)) {
            PL_statgv = gv;
-           sv_setpv(PL_statname,"");
+           sv_setpvn(PL_statname,"", 0);
            PL_laststype = OP_STAT;
            return (PL_laststatval = PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache));
        }
@@ -1388,7 +1383,7 @@ Perl_my_stat(pTHX)
            if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
                report_evil_fh(gv, io, PL_op->op_type);
            PL_statgv = Nullgv;
-           sv_setpv(PL_statname,"");
+           sv_setpvn(PL_statname,"", 0);
            return (PL_laststatval = -1);
        }
     }
@@ -1397,7 +1392,7 @@ Perl_my_stat(pTHX)
     }
     else {
        SV* sv = POPs;
-       char *s;
+       const char *s;
        STRLEN len;
        PUTBACK;
        if (SvTYPE(sv) == SVt_PVGV) {
@@ -1409,10 +1404,10 @@ Perl_my_stat(pTHX)
            goto do_fstat;
        }
 
-       s = SvPV(sv, len);
+       s = SvPV_const(sv, len);
        PL_statgv = Nullgv;
        sv_setpvn(PL_statname, s, len);
-       s = SvPVX(PL_statname);         /* s now NUL-terminated */
+       s = SvPVX_const(PL_statname);           /* s now NUL-terminated */
        PL_laststype = OP_STAT;
        PL_laststatval = PerlLIO_stat(s, &PL_statcache);
        if (PL_laststatval < 0 && ckWARN(WARN_NEWLINE) && strchr(s, '\n'))
@@ -1421,14 +1416,13 @@ Perl_my_stat(pTHX)
     }
 }
 
-static char no_prev_lstat[] = "The stat preceding -l _ wasn't an lstat";
+static const char no_prev_lstat[] = "The stat preceding -l _ wasn't an lstat";
 
 I32
 Perl_my_lstat(pTHX)
 {
     dSP;
     SV *sv;
-    STRLEN n_a;
     if (PL_op->op_flags & OPf_REF) {
        EXTEND(SP,1);
        if (cGVOP_gv == PL_defgv) {
@@ -1455,9 +1449,10 @@ Perl_my_lstat(pTHX)
                GvENAME((GV*) SvRV(sv)));
        return (PL_laststatval = -1);
     }
-    sv_setpv(PL_statname,SvPV(sv, n_a));
-    PL_laststatval = PerlLIO_lstat(SvPV(sv, n_a),&PL_statcache);
-    if (PL_laststatval < 0 && ckWARN(WARN_NEWLINE) && strchr(SvPV(sv, n_a), '\n'))
+    /* XXX Do really need to be calling SvPV() all these times? */
+    sv_setpv(PL_statname,SvPV_nolen_const(sv));
+    PL_laststatval = PerlLIO_lstat(SvPV_nolen_const(sv),&PL_statcache);
+    if (PL_laststatval < 0 && ckWARN(WARN_NEWLINE) && strchr(SvPV_nolen_const(sv), '\n'))
        Perl_warner(aTHX_ packWARN(WARN_NEWLINE), PL_warn_nl, "lstat");
     return PL_laststatval;
 }
@@ -1474,25 +1469,25 @@ bool
 Perl_do_aexec5(pTHX_ SV *really, register SV **mark, register SV **sp,
               int fd, int do_report)
 {
-#ifdef MACOS_TRADITIONAL
+    dVAR;
+#if defined(MACOS_TRADITIONAL) || defined(SYMBIAN)
     Perl_croak(aTHX_ "exec? I'm not *that* kind of operating system");
 #else
     register char **a;
     const char *tmps = Nullch;
-    STRLEN n_a;
 
     if (sp > mark) {
        New(401,PL_Argv, sp - mark + 1, char*);
        a = PL_Argv;
        while (++mark <= sp) {
            if (*mark)
-               *a++ = SvPVx(*mark, n_a);
+               *a++ = (char*)SvPV_nolen_const(*mark);
            else
                *a++ = "";
        }
        *a = Nullch;
        if (really)
-           tmps = SvPV(really, n_a);
+           tmps = SvPV_nolen_const(really);
        if ((!really && *PL_Argv[0] != '/') ||
            (really && *tmps != '/'))           /* will execvp use PATH? */
            TAINT_ENV();                /* testing IFS here is overkill, probably */
@@ -1530,7 +1525,7 @@ Perl_do_execfree(pTHX)
     }
 }
 
-#if !defined(OS2) && !defined(WIN32) && !defined(DJGPP) && !defined(EPOC) && !defined(MACOS_TRADITIONAL)
+#if !defined(OS2) && !defined(WIN32) && !defined(DJGPP) && !defined(EPOC) && !defined(SYMBIAN) && !defined(MACOS_TRADITIONAL)
 
 bool
 Perl_do_exec(pTHX_ char *cmd)
@@ -1541,6 +1536,7 @@ Perl_do_exec(pTHX_ char *cmd)
 bool
 Perl_do_exec3(pTHX_ char *cmd, int fd, int do_report)
 {
+    dVAR;
     register char **a;
     register char *s;
 
@@ -1674,9 +1670,8 @@ Perl_apply(pTHX_ I32 type, register SV **mark, register SV **sp)
     register I32 val;
     register I32 tot = 0;
     const char *what;
-    char *s;
+    const char *s;
     SV **oldmark = mark;
-    STRLEN n_a;
 
 #define APPLY_TAINT_PROPER() \
     STMT_START {                                                       \
@@ -1702,7 +1697,7 @@ Perl_apply(pTHX_ I32 type, register SV **mark, register SV **sp)
            APPLY_TAINT_PROPER();
            tot = sp - mark;
            while (++mark <= sp) {
-               char *name = SvPVx(*mark, n_a);
+               const char *name = SvPV_nolen_const(*mark);
                APPLY_TAINT_PROPER();
                if (PerlLIO_chmod(name, val))
                    tot--;
@@ -1720,7 +1715,7 @@ Perl_apply(pTHX_ I32 type, register SV **mark, register SV **sp)
            APPLY_TAINT_PROPER();
            tot = sp - mark;
            while (++mark <= sp) {
-               char *name = SvPVx(*mark, n_a);
+               const char *name = SvPV_nolen_const(*mark);
                APPLY_TAINT_PROPER();
                if (PerlLIO_chown(name, val, val2))
                    tot--;
@@ -1740,7 +1735,7 @@ nothing in the core.
        APPLY_TAINT_PROPER();
        if (mark == sp)
            break;
-       s = SvPVx(*++mark, n_a);
+       s = SvPVx_nolen_const(*++mark);
        if (isALPHA(*s)) {
            if (*s == 'S' && s[1] == 'I' && s[2] == 'G')
                s += 3;
@@ -1810,7 +1805,7 @@ nothing in the core.
        APPLY_TAINT_PROPER();
        tot = sp - mark;
        while (++mark <= sp) {
-           s = SvPVx(*mark, n_a);
+           s = SvPV_nolen_const(*mark);
            APPLY_TAINT_PROPER();
            if (PL_euid || PL_unsafe) {
                if (UNLINK(s))
@@ -1833,16 +1828,17 @@ nothing in the core.
        if (sp - mark > 2) {
 #if defined(I_UTIME) || defined(VMS)
            struct utimbuf utbuf;
+           struct utimbuf *utbufp = &utbuf;
 #else
            struct {
                Time_t  actime;
                Time_t  modtime;
            } utbuf;
+           void *utbufp = &utbuf;
 #endif
 
            SV* accessed = *++mark;
            SV* modified = *++mark;
-           void * utbufp = &utbuf;
 
            /* Be like C, and if both times are undefined, let the C
             * library figure out what to do.  This usually means
@@ -1860,12 +1856,12 @@ nothing in the core.
                 utbuf.modtime = (Time_t)SvIVx(modified); /* time modified */
 #endif
             }
-            APPLY_TAINT_PROPER();
+           APPLY_TAINT_PROPER();
            tot = sp - mark;
            while (++mark <= sp) {
-               char *name = SvPVx(*mark, n_a);
+               const char *name = SvPV_nolen_const(*mark);
                APPLY_TAINT_PROPER();
-               if (PerlLIO_utime(name, utbufp))
+               if (PerlLIO_utime(name, utbufp))
                    tot--;
            }
        }
@@ -1882,8 +1878,8 @@ nothing in the core.
 /* Do the permissions allow some operation?  Assumes statcache already set. */
 #ifndef VMS /* VMS' cando is in vms.c */
 bool
-Perl_cando(pTHX_ Mode_t mode, Uid_t effective, register Stat_t *statbufp)
-/* Note: we use `effective' both for uids and gids.
+Perl_cando(pTHX_ Mode_t mode, Uid_t effective, register const Stat_t *statbufp)
+/* Note: we use "effective" both for uids and gids.
  * Here we are betting on Uid_t being equal or wider than Gid_t.  */
 {
 #ifdef DOSISH
@@ -2000,7 +1996,8 @@ Perl_do_ipcctl(pTHX_ I32 optype, SV **mark, SV **sp)
 {
     SV *astr;
     char *a;
-    I32 infosize, getinfo;
+    STRLEN infosize;
+    I32 getinfo;
     I32 ret = -1;
     const I32 id  = SvIVx(*++mark);
     const I32 n   = (optype == OP_SEMCTL) ? SvIVx(*++mark) : 0;
@@ -2238,7 +2235,7 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp)
 {
 #ifdef HAS_SHM
     SV *mstr;
-    char *mbuf, *shm;
+    char *shm;
     I32 mpos, msize;
     STRLEN len;
     struct shmid_ds shmds;
@@ -2259,6 +2256,7 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp)
     if (shm == (char *)-1)     /* I hate System V IPC, I really do */
        return -1;
     if (optype == OP_SHMREAD) {
+       const char *mbuf;
        /* suppress warning when reading into undef var (tchrist 3/Mar/00) */
        if (! SvOK(mstr))
            sv_setpvn(mstr, "", 0);
@@ -2277,7 +2275,7 @@ Perl_do_shmio(pTHX_ I32 optype, SV **mark, SV **sp)
     else {
        I32 n;
 
-       mbuf = SvPV(mstr, len);
+       const char *mbuf = SvPV(mstr, len);
        if ((n = len) > msize)
            n = msize;
        Copy(mbuf, shm + mpos, n, char);
@@ -2308,6 +2306,7 @@ Moving it away shrinks pp_hot.c; shrinking pp_hot.c helps speed perl up.
 PerlIO *
 Perl_start_glob (pTHX_ SV *tmpglob, IO *io)
 {
+    dVAR;
     SV *tmpcmd = NEWSV(55, 0);
     PerlIO *fp;
     ENTER;
@@ -2354,7 +2353,7 @@ Perl_start_glob (pTHX_ SV *tmpglob, IO *io)
        }
        if ((tmpfp = PerlIO_tmpfile()) != NULL) {
            Stat_t st;
-           if (!PerlLIO_stat(SvPVX(tmpglob),&st) && S_ISDIR(st.st_mode))
+           if (!PerlLIO_stat(SvPVX_const(tmpglob),&st) && S_ISDIR(st.st_mode))
                ok = ((wilddsc.dsc$a_pointer = tovmspath(SvPVX(tmpglob),vmsspec)) != NULL);
            else ok = ((wilddsc.dsc$a_pointer = tovmsspec(SvPVX(tmpglob),vmsspec)) != NULL);
            if (ok) wilddsc.dsc$w_length = (unsigned short int) strlen(wilddsc.dsc$a_pointer);
@@ -2441,3 +2440,13 @@ Perl_start_glob (pTHX_ SV *tmpglob, IO *io)
     LEAVE;
     return fp;
 }
+
+/*
+ * Local variables:
+ * c-indentation-style: bsd
+ * c-basic-offset: 4
+ * indent-tabs-mode: t
+ * End:
+ *
+ * ex: set ts=8 sts=4 sw=4 noet:
+ */