X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pp_sys.c;h=4d22a8244efde78ee3d59bc1ded568a13e2b7568;hb=8861ecc69a87dc6907b3e9c79689edb5df16413e;hp=b31bc349afdeed084382490849adbffbfa6d3b4c;hpb=64a1bc8eebbac673a02fa9f636a26efc18961e48;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pp_sys.c b/pp_sys.c index b31bc34..4d22a82 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -330,10 +330,7 @@ PP(pp_backtick) mode = "rt"; fp = PerlProc_popen(tmps, mode); if (fp) { - const char *type = NULL; - if (PL_curcop->cop_io) { - type = SvPV_nolen_const(PL_curcop->cop_io); - } + const char * const type = PL_curcop->cop_io ? SvPV_nolen_const(PL_curcop->cop_io) : NULL; if (type && *type) PerlIO_apply_layers(aTHX_ fp,mode,type); @@ -430,12 +427,16 @@ PP(pp_warn) SV *tmpsv; const char *tmps; STRLEN len; - if (SP - MARK != 1) { + if (SP - MARK > 1) { dTARGET; do_join(TARG, &PL_sv_no, MARK, SP); tmpsv = TARG; SP = MARK + 1; } + else if (SP == MARK) { + tmpsv = &PL_sv_no; + EXTEND(SP, 1); + } else { tmpsv = TOPs; } @@ -484,11 +485,11 @@ PP(pp_die) if (!multiarg) SvSetSV(error,tmpsv); else if (sv_isobject(error)) { - HV *stash = SvSTASH(SvRV(error)); - GV *gv = gv_fetchmethod(stash, "PROPAGATE"); + HV * const stash = SvSTASH(SvRV(error)); + GV * const gv = gv_fetchmethod(stash, "PROPAGATE"); if (gv) { - SV *file = sv_2mortal(newSVpv(CopFILE(PL_curcop),0)); - SV *line = sv_2mortal(newSVuv(CopLINE(PL_curcop))); + SV * const file = sv_2mortal(newSVpv(CopFILE(PL_curcop),0)); + SV * const line = sv_2mortal(newSVuv(CopLINE(PL_curcop))); EXTEND(SP, 3); PUSHMARK(SP); PUSHs(error); @@ -876,7 +877,7 @@ PP(pp_untie) if ((mg = SvTIED_mg(sv, how))) { SV * const obj = SvRV(SvTIED_obj(sv, mg)); - CV *cv = NULL; + CV *cv; if (obj) { GV * const gv = gv_fetchmethod_autoload(SvSTASH(obj), "UNTIE", FALSE); if (gv && isGV(gv) && (cv = GvCV(gv))) { @@ -1154,12 +1155,10 @@ Perl_setdefout(pTHX_ GV *gv) PP(pp_select) { dSP; dTARGET; - GV *egv; HV *hv; - GV * const newdefout = (PL_op->op_private > 0) ? ((GV *) POPs) : (GV *) NULL; + GV * egv = GvEGV(PL_defoutgv); - egv = GvEGV(PL_defoutgv); if (!egv) egv = PL_defoutgv; hv = GvSTASH(egv); @@ -1771,7 +1770,6 @@ PP(pp_sysread) PP(pp_send) { dVAR; dSP; dMARK; dORIGMARK; dTARGET; - GV *gv; IO *io; SV *bufsv; const char *buffer; @@ -1781,7 +1779,7 @@ PP(pp_send) MAGIC *mg; const int op_type = PL_op->op_type; - gv = (GV*)*++MARK; + GV *const gv = (GV*)*++MARK; if (PL_op->op_type == OP_SYSWRITE && gv && (io = GvIO(gv)) && (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar))) @@ -2005,17 +2003,16 @@ PP(pp_tell) PP(pp_sysseek) { dVAR; dSP; - GV *gv; IO *io; const int whence = POPi; #if LSEEKSIZE > IVSIZE - Off_t offset = (Off_t)SvNVx(POPs); + const Off_t offset = (Off_t)SvNVx(POPs); #else - Off_t offset = (Off_t)SvIVx(POPs); + const Off_t offset = (Off_t)SvIVx(POPs); #endif MAGIC *mg; - gv = PL_last_in_gv = (GV*)POPs; + GV * const gv = PL_last_in_gv = (GV*)POPs; if (gv && (io = GvIO(gv)) && (mg = SvTIED_mg((SV*)io, PERL_MAGIC_tiedscalar))) @@ -2043,7 +2040,7 @@ PP(pp_sysseek) if (sought < 0) PUSHs(&PL_sv_undef); else { - SV* sv = sought ? + SV* const sv = sought ? #if LSEEKSIZE > IVSIZE newSVnv((NV)sought) #else @@ -2064,12 +2061,11 @@ PP(pp_truncate) * general one would think that when using large files, off_t is * at least as wide as size_t, so using an off_t should be okay. */ /* XXX Configure probe for the length type of *truncate() needed XXX */ - Off_t len; #if Off_t_size > IVSIZE - len = (Off_t)POPn; + const Off_t len = (Off_t)POPn; #else - len = (Off_t)POPi; + const Off_t len = (Off_t)POPi; #endif /* Checking for length < 0 is problematic as the type might or * might not be signed: if it is not, clever compilers will moan. */ @@ -2106,7 +2102,7 @@ PP(pp_truncate) } } else { - SV *sv = POPs; + SV * const sv = POPs; const char *name; if (SvTYPE(sv) == SVt_PVGV) { @@ -2129,9 +2125,9 @@ PP(pp_truncate) result = 0; #else { - int tmpfd; + const int tmpfd = PerlLIO_open(name, O_RDWR); - if ((tmpfd = PerlLIO_open(name, O_RDWR)) < 0) + if (tmpfd < 0) result = 0; else { if (my_chsize(tmpfd, len) < 0) @@ -2153,13 +2149,13 @@ PP(pp_truncate) PP(pp_ioctl) { dSP; dTARGET; - SV *argsv = POPs; + SV * const argsv = POPs; const unsigned int func = POPu; const int optype = PL_op->op_type; + GV * const gv = (GV*)POPs; + IO * const io = gv ? GvIOn(gv) : Null(IO*); char *s; IV retval; - GV *gv = (GV*)POPs; - IO *io = gv ? GvIOn(gv) : 0; if (!io || !argsv || !IoIFP(io)) { if (ckWARN2(WARN_UNOPENED,WARN_CLOSED)) @@ -2230,16 +2226,11 @@ PP(pp_flock) #ifdef FLOCK dSP; dTARGET; I32 value; - int argtype; - GV *gv; IO *io = NULL; PerlIO *fp; + const int argtype = POPi; + GV * const gv = (MAXARG == 0) ? PL_last_in_gv : (GV*)POPs; - argtype = POPi; - if (MAXARG == 0) - gv = PL_last_in_gv; - else - gv = (GV*)POPs; if (gv && (io = GvIO(gv))) fp = IoIFP(io); else { @@ -2269,16 +2260,13 @@ PP(pp_socket) { #ifdef HAS_SOCKET dSP; - GV *gv; - register IO *io; - int protocol = POPi; - int type = POPi; - int domain = POPi; + const int protocol = POPi; + const int type = POPi; + const int domain = POPi; + GV * const gv = (GV*)POPs; + register IO * const io = gv ? GvIOn(gv) : NULL; int fd; - gv = (GV*)POPs; - io = gv ? GvIOn(gv) : NULL; - if (!gv || !io) { if (ckWARN2(WARN_UNOPENED,WARN_CLOSED)) report_evil_fh(gv, io, PL_op->op_type); @@ -2322,19 +2310,15 @@ PP(pp_sockpair) { #if defined (HAS_SOCKETPAIR) || (defined (HAS_SOCKET) && defined(SOCK_DGRAM) && defined(AF_INET) && defined(PF_INET)) dSP; - GV *gv1; - GV *gv2; - register IO *io1; - register IO *io2; - int protocol = POPi; - int type = POPi; - int domain = POPi; + const int protocol = POPi; + const int type = POPi; + const int domain = POPi; + GV * const gv2 = (GV*)POPs; + GV * const gv1 = (GV*)POPs; + register IO * const io1 = gv1 ? GvIOn(gv1) : NULL; + register IO * const io2 = gv2 ? GvIOn(gv2) : NULL; int fd[2]; - gv2 = (GV*)POPs; - gv1 = (GV*)POPs; - io1 = gv1 ? GvIOn(gv1) : NULL; - io2 = gv2 ? GvIOn(gv2) : NULL; if (!gv1 || !gv2 || !io1 || !io2) { if (ckWARN2(WARN_UNOPENED,WARN_CLOSED)) { if (!gv1 || !io1) @@ -2391,11 +2375,11 @@ PP(pp_bind) extern void GETPRIVMODE(); extern void GETUSERMODE(); #endif - SV *addrsv = POPs; + SV * const addrsv = POPs; /* OK, so on what platform does bind modify addr? */ const char *addr; - GV *gv = (GV*)POPs; - register IO *io = GvIOn(gv); + GV * const gv = (GV*)POPs; + register IO * const io = GvIOn(gv); STRLEN len; int bind_ok = 0; #ifdef MPE @@ -2447,10 +2431,10 @@ PP(pp_connect) { #ifdef HAS_SOCKET dSP; - SV *addrsv = POPs; + SV * const addrsv = POPs; + GV * const gv = (GV*)POPs; + register IO * const io = GvIOn(gv); const char *addr; - GV *gv = (GV*)POPs; - register IO *io = GvIOn(gv); STRLEN len; if (!io || !IoIFP(io)) @@ -2477,9 +2461,9 @@ PP(pp_listen) { #ifdef HAS_SOCKET dSP; - int backlog = POPi; - GV *gv = (GV*)POPs; - register IO *io = gv ? GvIOn(gv) : NULL; + const int backlog = POPi; + GV * const gv = (GV*)POPs; + register IO * const io = gv ? GvIOn(gv) : NULL; if (!gv || !io || !IoIFP(io)) goto nuts; @@ -2503,8 +2487,6 @@ PP(pp_accept) { #ifdef HAS_SOCKET dSP; dTARGET; - GV *ngv; - GV *ggv; register IO *nstio; register IO *gstio; char namebuf[MAXPATHLEN]; @@ -2513,11 +2495,10 @@ PP(pp_accept) #else Sock_size_t len = sizeof namebuf; #endif + GV * const ggv = (GV*)POPs; + GV * const ngv = (GV*)POPs; int fd; - ggv = (GV*)POPs; - ngv = (GV*)POPs; - if (!ngv) goto badexit; if (!ggv) @@ -2574,9 +2555,9 @@ PP(pp_shutdown) { #ifdef HAS_SOCKET dSP; dTARGET; - int how = POPi; - GV *gv = (GV*)POPs; - register IO *io = GvIOn(gv); + const int how = POPi; + GV * const gv = (GV*)POPs; + register IO * const io = GvIOn(gv); if (!io || !IoIFP(io)) goto nuts; @@ -2598,24 +2579,15 @@ PP(pp_ssockopt) { #ifdef HAS_SOCKET dSP; - int optype = PL_op->op_type; - SV *sv; + const int optype = PL_op->op_type; + SV * const sv = (optype == OP_GSOCKOPT) ? sv_2mortal(NEWSV(22, 257)) : POPs; + const unsigned int optname = (unsigned int) POPi; + const unsigned int lvl = (unsigned int) POPi; + GV * const gv = (GV*)POPs; + register IO * const io = GvIOn(gv); int fd; - unsigned int optname; - unsigned int lvl; - GV *gv; - register IO *io; Sock_size_t len; - if (optype == OP_GSOCKOPT) - sv = sv_2mortal(NEWSV(22, 257)); - else - sv = POPs; - optname = (unsigned int) POPi; - lvl = (unsigned int) POPi; - - gv = (GV*)POPs; - io = GvIOn(gv); if (!io || !IoIFP(io)) goto nuts; @@ -2684,12 +2656,12 @@ PP(pp_getpeername) { #ifdef HAS_SOCKET dSP; - int optype = PL_op->op_type; + const int optype = PL_op->op_type; + GV * const gv = (GV*)POPs; + register IO * const io = GvIOn(gv); + Sock_size_t len; SV *sv; int fd; - GV *gv = (GV*)POPs; - register IO *io = GvIOn(gv); - Sock_size_t len; if (!io || !IoIFP(io)) goto nuts; @@ -2780,7 +2752,7 @@ PP(pp_stat) } } else { - SV* sv = POPs; + SV* const sv = POPs; if (SvTYPE(sv) == SVt_PVGV) { gv = (GV*)sv; goto do_fstat; @@ -3402,7 +3374,7 @@ PP(pp_chown) const I32 value = (I32)apply(PL_op->op_type, MARK, SP); SP = MARK; - PUSHi(value); + XPUSHi(value); RETURN; } @@ -3410,7 +3382,7 @@ PP(pp_chroot) { #ifdef HAS_CHROOT dSP; dTARGET; - char *tmps = POPpx; + char * const tmps = POPpx; TAINT_PROPER("chroot"); PUSHi( chroot(tmps) >= 0 ); RETURN; @@ -3423,8 +3395,8 @@ PP(pp_rename) { dSP; dTARGET; int anum; - const char *tmps2 = POPpconstx; - const char *tmps = SvPV_nolen_const(TOPs); + const char * const tmps2 = POPpconstx; + const char * const tmps = SvPV_nolen_const(TOPs); TAINT_PROPER("rename"); #ifdef HAS_RENAME anum = PerlLIO_rename(tmps, tmps2); @@ -3461,8 +3433,8 @@ PP(pp_link) # endif { - const char *tmps2 = POPpconstx; - const char *tmps = SvPV_nolen_const(TOPs); + const char * const tmps2 = POPpconstx; + const char * const tmps = SvPV_nolen_const(TOPs); TAINT_PROPER(PL_op_desc[op_type]); result = # if defined(HAS_LINK) @@ -3628,18 +3600,13 @@ S_dooneliner(pTHX_ const char *cmd, const char *filename) PP(pp_mkdir) { dSP; dTARGET; - int mode; #ifndef HAS_MKDIR int oldumask; #endif STRLEN len; const char *tmps; bool copy = FALSE; - - if (MAXARG > 1) - mode = POPi; - else - mode = 0777; + const int mode = (MAXARG > 1) ? POPi : 0777; TRIMSLASHES(tmps,len,copy); @@ -3682,9 +3649,9 @@ PP(pp_open_dir) { #if defined(Direntry_t) && defined(HAS_READDIR) dSP; - const char *dirname = POPpconstx; - GV *gv = (GV*)POPs; - register IO *io = GvIOn(gv); + const char * const dirname = POPpconstx; + GV * const gv = (GV*)POPs; + register IO * const io = GvIOn(gv); if (!io) goto nope; @@ -3716,9 +3683,9 @@ PP(pp_readdir) SV *sv; const I32 gimme = GIMME; - GV *gv = (GV *)POPs; - register Direntry_t *dp; - register IO *io = GvIOn(gv); + GV * const gv = (GV *)POPs; + register const Direntry_t *dp; + register IO * const io = GvIOn(gv); if (!io || !IoDIRP(io)) goto nope; @@ -3766,8 +3733,8 @@ PP(pp_telldir) # if !defined(HAS_TELLDIR_PROTO) || defined(NEED_TELLDIR_PROTO) long telldir (DIR *); # endif - GV *gv = (GV*)POPs; - register IO *io = GvIOn(gv); + GV * const gv = (GV*)POPs; + register IO * const io = GvIOn(gv); if (!io || !IoDIRP(io)) goto nope; @@ -3787,9 +3754,9 @@ PP(pp_seekdir) { #if defined(HAS_SEEKDIR) || defined(seekdir) dSP; - long along = POPl; - GV *gv = (GV*)POPs; - register IO *io = GvIOn(gv); + const long along = POPl; + GV * const gv = (GV*)POPs; + register IO * const io = GvIOn(gv); if (!io || !IoDIRP(io)) goto nope; @@ -3810,8 +3777,8 @@ PP(pp_rewinddir) { #if defined(HAS_REWINDDIR) || defined(rewinddir) dSP; - GV *gv = (GV*)POPs; - register IO *io = GvIOn(gv); + GV * const gv = (GV*)POPs; + register IO * const io = GvIOn(gv); if (!io || !IoDIRP(io)) goto nope; @@ -3831,8 +3798,8 @@ PP(pp_closedir) { #if defined(Direntry_t) && defined(HAS_READDIR) dSP; - GV *gv = (GV*)POPs; - register IO *io = GvIOn(gv); + GV * const gv = (GV*)POPs; + register IO * const io = GvIOn(gv); if (!io || !IoDIRP(io)) goto nope; @@ -3864,7 +3831,6 @@ PP(pp_fork) #ifdef HAS_FORK dSP; dTARGET; Pid_t childpid; - GV *tmpgv; EXTEND(SP, 1); PERL_FLUSHALL_FOR_CHILD; @@ -3872,7 +3838,8 @@ PP(pp_fork) if (childpid < 0) RETSETUNDEF; if (!childpid) { - if ((tmpgv = gv_fetchpv("$", TRUE, SVt_PV))) { + GV * const tmpgv = gv_fetchpv("$", TRUE, SVt_PV); + if (tmpgv) { SvREADONLY_off(GvSV(tmpgv)); sv_setiv(GvSV(tmpgv), (IV)PerlProc_getpid()); SvREADONLY_on(GvSV(tmpgv)); @@ -3993,7 +3960,7 @@ PP(pp_system) if (errno != EAGAIN) { value = -1; SP = ORIGMARK; - PUSHi(value); + XPUSHi(value); if (did_pipes) { PerlLIO_close(pp[0]); PerlLIO_close(pp[1]); @@ -4042,7 +4009,7 @@ PP(pp_system) STATUS_NATIVE_CHILD_SET(-1); } } - PUSHi(STATUS_CURRENT); + XPUSHi(STATUS_CURRENT); RETURN; } if (did_pipes) { @@ -4088,7 +4055,7 @@ PP(pp_system) STATUS_NATIVE_CHILD_SET(value); do_execfree(); SP = ORIGMARK; - PUSHi(result ? value : STATUS_CURRENT); + XPUSHi(result ? value : STATUS_CURRENT); #endif /* !FORK or VMS */ RETURN; } @@ -4140,7 +4107,7 @@ PP(pp_exec) } SP = ORIGMARK; - PUSHi(value); + XPUSHi(value); RETURN; } @@ -4451,6 +4418,9 @@ PP(pp_shmwrite) case OP_MSGRCV: value = (I32)(do_msgrcv(MARK, SP) >= 0); break; + case OP_SEMOP: + value = (I32)(do_semop(MARK, SP) >= 0); + break; default: value = (I32)(do_shmio(op_type, MARK, SP) >= 0); break; @@ -4501,19 +4471,6 @@ PP(pp_semctl) #endif } -PP(pp_semop) -{ -#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM) - dSP; dMARK; dTARGET; - I32 value = (I32)(do_semop(MARK, SP) >= 0); - SP = MARK; - PUSHi(value); - RETURN; -#else - return pp_semget(); -#endif -} - /* Get system info. */ PP(pp_ghostent)