X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pp_sys.c;h=7473ba56bcf4d115633a5b0027c92d4ad1119173;hb=ed79a026b5aec9cc3f786c2971aa15a4b21f396c;hp=e3c0784d4c54c4d10c58d00a347e900e9b9a30cf;hpb=bc37a18f04c6e2feea5bb9e2e546e59c37c7c04a;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pp_sys.c b/pp_sys.c index e3c0784..7473ba5 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -29,7 +29,7 @@ * --jhi */ # ifdef __hpux__ /* There is a MAXINT coming from <- <- - * and another MAXINT from "perl.h" <- . */ + * and another MAXINT from "perl.h" <- . */ # undef MAXINT # endif # include @@ -40,8 +40,8 @@ # include #endif -#ifdef HAS_SYSCALL -#ifdef __cplusplus +#ifdef HAS_SYSCALL +#ifdef __cplusplus extern "C" int syscall(unsigned long,...); #endif #endif @@ -58,7 +58,7 @@ extern "C" int syscall(unsigned long,...); # include # if defined(USE_SOCKS) && defined(I_SOCKS) # include -# endif +# endif # ifdef I_NETDB # include # endif @@ -508,7 +508,7 @@ PP(pp_open) djSP; dTARGET; GV *gv; SV *sv; - SV *name; + SV *name = Nullsv; I32 have_name = 0; char *tmps; STRLEN len; @@ -612,8 +612,8 @@ PP(pp_pipe_op) IoIFP(rstio) = PerlIO_fdopen(fd[0], "r"); IoOFP(wstio) = PerlIO_fdopen(fd[1], "w"); IoIFP(wstio) = IoOFP(wstio); - IoTYPE(rstio) = '<'; - IoTYPE(wstio) = '>'; + IoTYPE(rstio) = IoTYPE_RDONLY; + IoTYPE(wstio) = IoTYPE_WRONLY; if (!IoIFP(rstio) || !IoOFP(wstio)) { if (IoIFP(rstio)) PerlIO_close(IoIFP(rstio)); @@ -703,7 +703,7 @@ PP(pp_binmode) if (MAXARG > 1) discp = POPs; - gv = (GV*)POPs; + gv = (GV*)POPs; if (gv && (mg = SvTIED_mg((SV*)gv, 'q'))) { PUSHMARK(SP); @@ -722,7 +722,7 @@ PP(pp_binmode) if (!(io = GvIO(gv)) || !(fp = IoIFP(io))) RETPUSHUNDEF; - if (do_binmode(fp,IoTYPE(io),mode_from_discipline(discp))) + if (do_binmode(fp,IoTYPE(io),mode_from_discipline(discp))) RETPUSHYES; else RETPUSHUNDEF; @@ -769,7 +769,7 @@ PP(pp_tie) PUSHs(*MARK++); PUTBACK; call_method(methname, G_SCALAR); - } + } else { /* Not clear why we don't call call_method here too. * perhaps to get different error message ? @@ -777,7 +777,7 @@ PP(pp_tie) stash = gv_stashsv(*MARK, FALSE); if (!stash || !(gv = gv_fetchmethod(stash, methname))) { DIE(aTHX_ "Can't locate object method \"%s\" via package \"%s\"", - methname, SvPV(*MARK,n_a)); + methname, SvPV(*MARK,n_a)); } ENTER; PUSHSTACKi(PERLSI_MAGIC); @@ -808,16 +808,29 @@ PP(pp_untie) SV *sv = POPs; char how = (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV) ? 'P' : 'q'; - if (ckWARN(WARN_UNTIE)) { MAGIC * mg ; if ((mg = SvTIED_mg(sv, how))) { - if (mg && SvREFCNT(SvRV(mg->mg_obj)) > 1) + SV *obj = SvRV(mg->mg_obj); + GV *gv; + CV *cv = NULL; + if ((gv = gv_fetchmethod_autoload(SvSTASH(obj), "UNTIE", FALSE)) && + isGV(gv) && (cv = GvCV(gv))) { + PUSHMARK(SP); + XPUSHs(SvTIED_obj((SV*)gv, mg)); + XPUSHs(sv_2mortal(newSViv(SvREFCNT(obj)-1))); + PUTBACK; + ENTER; + call_sv((SV *)cv, G_VOID); + LEAVE; + SPAGAIN; + } + else if (ckWARN(WARN_UNTIE)) { + if (mg && SvREFCNT(obj) > 1) Perl_warner(aTHX_ WARN_UNTIE, "untie attempted while %"UVuf" inner references still exist", - (UV)SvREFCNT(SvRV(mg->mg_obj)) - 1 ) ; + (UV)SvREFCNT(obj) - 1 ) ; } } - sv_unmagic(sv, how); RETPUSHYES; } @@ -889,7 +902,7 @@ PP(pp_dbmopen) } if (sv_isobject(TOPs)) { - sv_unmagic((SV *) hv, 'P'); + sv_unmagic((SV *) hv, 'P'); sv_magic((SV*)hv, TOPs, 'P', Nullch, 0); } LEAVE; @@ -1070,7 +1083,7 @@ PP(pp_select) else { GV **gvp = (GV**)hv_fetch(hv, GvNAME(egv), GvNAMELEN(egv), FALSE); if (gvp && *gvp == egv) { - gv_efullname4(TARG, PL_defoutgv, Nullch, FALSE); + gv_efullname4(TARG, PL_defoutgv, Nullch, TRUE); XPUSHTARG; } else { @@ -1174,11 +1187,14 @@ PP(pp_enterwrite) cv = GvFORM(fgv); if (!cv) { + char *name = NULL; if (fgv) { SV *tmpsv = sv_newmortal(); gv_efullname4(tmpsv, fgv, Nullch, FALSE); - DIE(aTHX_ "Undefined format \"%s\" called",SvPVX(tmpsv)); + name = SvPV_nolen(tmpsv); } + if (name && *name) + DIE(aTHX_ "Undefined format \"%s\" called", name); DIE(aTHX_ "Not a format reference"); } if (CvCLONE(cv)) @@ -1255,10 +1271,19 @@ PP(pp_leavewrite) if (!fgv) DIE(aTHX_ "bad top format reference"); cv = GvFORM(fgv); - if (!cv) { - SV *tmpsv = sv_newmortal(); - gv_efullname4(tmpsv, fgv, Nullch, FALSE); - DIE(aTHX_ "Undefined top format \"%s\" called",SvPVX(tmpsv)); + { + char *name = NULL; + if (!cv) { + SV *sv = sv_newmortal(); + gv_efullname4(sv, fgv, Nullch, FALSE); + name = SvPV_nolen(sv); + } + if (name && *name) + DIE(aTHX_ "Undefined top format \"%s\" called",name); + /* why no: + else + DIE(aTHX_ "Undefined top format called"); + ?*/ } if (CvCLONE(cv)) cv = (CV*)sv_2mortal((SV*)cv_clone(cv)); @@ -1274,11 +1299,19 @@ PP(pp_leavewrite) if (!fp) { if (ckWARN2(WARN_CLOSED,WARN_IO)) { if (IoIFP(io)) { - SV* sv = sv_newmortal(); - gv_efullname4(sv, gv, Nullch, FALSE); - Perl_warner(aTHX_ WARN_IO, - "Filehandle %s opened only for input", - SvPV_nolen(sv)); + /* integrate with report_evil_fh()? */ + char *name = NULL; + if (isGV(gv)) { + SV* sv = sv_newmortal(); + gv_efullname4(sv, gv, Nullch, FALSE); + name = SvPV_nolen(sv); + } + if (name && *name) + Perl_warner(aTHX_ WARN_IO, + "Filehandle %s opened only for input", name); + else + Perl_warner(aTHX_ WARN_IO, + "Filehandle opened only for input"); } else if (ckWARN(WARN_CLOSED)) report_evil_fh(gv, io, PL_op->op_type); @@ -1344,21 +1377,27 @@ PP(pp_prtf) sv = NEWSV(0,0); if (!(io = GvIO(gv))) { - if (ckWARN(WARN_UNOPENED)) { - gv_efullname4(sv, gv, Nullch, FALSE); - Perl_warner(aTHX_ WARN_UNOPENED, - "Filehandle %s never opened", SvPV(sv,n_a)); - } + dTHR; + if (ckWARN2(WARN_UNOPENED,WARN_CLOSED)) + report_evil_fh(gv, io, PL_op->op_type); SETERRNO(EBADF,RMS$_IFI); goto just_say_no; } else if (!(fp = IoOFP(io))) { if (ckWARN2(WARN_CLOSED,WARN_IO)) { + /* integrate with report_evil_fh()? */ if (IoIFP(io)) { - gv_efullname4(sv, gv, Nullch, FALSE); - Perl_warner(aTHX_ WARN_IO, - "Filehandle %s opened only for input", - SvPV(sv,n_a)); + char *name = NULL; + if (isGV(gv)) { + gv_efullname4(sv, gv, Nullch, FALSE); + name = SvPV_nolen(sv); + } + if (name && *name) + Perl_warner(aTHX_ WARN_IO, + "Filehandle %s opened only for input", name); + else + Perl_warner(aTHX_ WARN_IO, + "Filehandle opened only for input"); } else if (ckWARN(WARN_CLOSED)) report_evil_fh(gv, io, PL_op->op_type); @@ -1515,7 +1554,7 @@ PP(pp_sysread) } if (PL_op->op_type == OP_SYSREAD) { #ifdef PERL_SOCK_SYSREAD_IS_RECV - if (IoTYPE(io) == 's') { + if (IoTYPE(io) == IoTYPE_SOCKET) { length = PerlSock_recv(PerlIO_fileno(IoIFP(io)), buffer+offset, length, 0); } @@ -1528,7 +1567,7 @@ PP(pp_sysread) } else #ifdef HAS_SOCKET__bad_code_maybe - if (IoTYPE(io) == 's') { + if (IoTYPE(io) == IoTYPE_SOCKET) { char namebuf[MAXPATHLEN]; #if defined(VMS_DO_SOCKETS) && defined(DECCRTL_SOCKETS) bufsize = sizeof (struct sockaddr_in); @@ -1547,13 +1586,22 @@ PP(pp_sysread) length = -1; } if (length < 0) { - if ((IoTYPE(io) == '>' || IoIFP(io) == PerlIO_stdout() + if ((IoTYPE(io) == IoTYPE_WRONLY || IoIFP(io) == PerlIO_stdout() || IoIFP(io) == PerlIO_stderr()) && ckWARN(WARN_IO)) { - SV* sv = sv_newmortal(); - gv_efullname4(sv, gv, Nullch, FALSE); - Perl_warner(aTHX_ WARN_IO, "Filehandle %s opened only for output", - SvPV_nolen(sv)); + /* integrate with report_evil_fh()? */ + char *name = NULL; + if (isGV(gv)) { + SV* sv = sv_newmortal(); + gv_efullname4(sv, gv, Nullch, FALSE); + name = SvPV_nolen(sv); + } + if (name && *name) + Perl_warner(aTHX_ WARN_IO, + "Filehandle %s opened only for output", name); + else + Perl_warner(aTHX_ WARN_IO, + "Filehandle opened only for output"); } goto say_undef; } @@ -1647,7 +1695,7 @@ PP(pp_send) if (length > blen - offset) length = blen - offset; #ifdef PERL_SOCK_SYSWRITE_IS_SEND - if (IoTYPE(io) == 's') { + if (IoTYPE(io) == IoTYPE_SOCKET) { retval = PerlSock_send(PerlIO_fileno(IoIFP(io)), buffer+offset, length, 0); } @@ -1741,7 +1789,7 @@ PP(pp_eof) PP(pp_tell) { djSP; dTARGET; - GV *gv; + GV *gv; MAGIC *mg; if (MAXARG == 0) @@ -1843,7 +1891,7 @@ PP(pp_truncate) 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. */ + * might not be signed: if it is not, clever compilers will moan. */ /* XXX Configure probe for the signedness of the length type of *truncate() needed? XXX */ SETERRNO(0,0); #if defined(HAS_TRUNCATE) || defined(HAS_CHSIZE) || defined(F_FREESP) @@ -1857,7 +1905,7 @@ PP(pp_truncate) PerlIO_flush(IoIFP(GvIOp(tmpgv))); #ifdef HAS_TRUNCATE if (ftruncate(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), len) < 0) -#else +#else if (my_chsize(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), len) < 0) #endif result = 0; @@ -1958,7 +2006,7 @@ PP(pp_ioctl) retval = fcntl(PerlIO_fileno(IoIFP(io)), func, (int)s); #else retval = fcntl(PerlIO_fileno(IoIFP(io)), func, s); -#endif +#endif #else DIE(aTHX_ "fcntl is not implemented"); #endif @@ -2050,7 +2098,7 @@ PP(pp_socket) RETPUSHUNDEF; IoIFP(io) = PerlIO_fdopen(fd, "r"); /* stdio gets confused about sockets */ IoOFP(io) = PerlIO_fdopen(fd, "w"); - IoTYPE(io) = 's'; + IoTYPE(io) = IoTYPE_SOCKET; if (!IoIFP(io) || !IoOFP(io)) { if (IoIFP(io)) PerlIO_close(IoIFP(io)); if (IoOFP(io)) PerlIO_close(IoOFP(io)); @@ -2097,10 +2145,10 @@ PP(pp_sockpair) RETPUSHUNDEF; IoIFP(io1) = PerlIO_fdopen(fd[0], "r"); IoOFP(io1) = PerlIO_fdopen(fd[0], "w"); - IoTYPE(io1) = 's'; + IoTYPE(io1) = IoTYPE_SOCKET; IoIFP(io2) = PerlIO_fdopen(fd[1], "r"); IoOFP(io2) = PerlIO_fdopen(fd[1], "w"); - IoTYPE(io2) = 's'; + IoTYPE(io2) = IoTYPE_SOCKET; if (!IoIFP(io1) || !IoOFP(io1) || !IoIFP(io2) || !IoOFP(io2)) { if (IoIFP(io1)) PerlIO_close(IoIFP(io1)); if (IoOFP(io1)) PerlIO_close(IoOFP(io1)); @@ -2269,7 +2317,7 @@ PP(pp_accept) goto badexit; IoIFP(nstio) = PerlIO_fdopen(fd, "r"); IoOFP(nstio) = PerlIO_fdopen(fd, "w"); - IoTYPE(nstio) = 's'; + IoTYPE(nstio) = IoTYPE_SOCKET; if (!IoIFP(nstio) || !IoOFP(nstio)) { if (IoIFP(nstio)) PerlIO_close(IoIFP(nstio)); if (IoOFP(nstio)) PerlIO_close(IoOFP(nstio)); @@ -2280,6 +2328,10 @@ PP(pp_accept) fcntl(fd, F_SETFD, fd > PL_maxsysfd); /* ensure close-on-exec */ #endif +#ifdef EPOC + len = sizeof saddr; /* EPOC somehow truncates info */ +#endif + PUSHp((char *)&saddr, len); RETURN; @@ -2445,7 +2497,7 @@ PP(pp_getpeername) if (((struct sockaddr *)SvPVX(sv))->sa_family == AF_INET && !memcmp((char *)SvPVX(sv) + sizeof(u_short), nowhere, sizeof(u_short) + sizeof(struct in_addr))) { - goto nuts2; + goto nuts2; } } #endif @@ -2484,39 +2536,39 @@ PP(pp_lstat) PP(pp_stat) { djSP; - GV *tmpgv; + GV *gv; I32 gimme; I32 max = 13; STRLEN n_a; if (PL_op->op_flags & OPf_REF) { - tmpgv = cGVOP_gv; + gv = cGVOP_gv; if (PL_op->op_type == OP_LSTAT && ckWARN(WARN_IO)) Perl_warner(aTHX_ WARN_IO, - "lstat() on filehandle %s", GvENAME(tmpgv)); + "lstat() on filehandle %s", GvENAME(gv)); do_fstat: - if (tmpgv != PL_defgv) { + if (gv != PL_defgv) { PL_laststype = OP_STAT; - PL_statgv = tmpgv; + PL_statgv = gv; sv_setpv(PL_statname, ""); - PL_laststatval = (GvIO(tmpgv) && IoIFP(GvIOp(tmpgv)) - ? PerlLIO_fstat(PerlIO_fileno(IoIFP(GvIOn(tmpgv))), &PL_statcache) : -1); + PL_laststatval = (GvIO(gv) && IoIFP(GvIOp(gv)) + ? PerlLIO_fstat(PerlIO_fileno(IoIFP(GvIOn(gv))), &PL_statcache) : -1); } if (PL_laststatval < 0) { - if (ckWARN(WARN_UNOPENED)) - Perl_warner(aTHX_ WARN_UNOPENED, "%s() on unopened filehandle %s", - PL_op_desc[PL_op->op_type], GvENAME(tmpgv)); + dTHR; + if (ckWARN2(WARN_UNOPENED,WARN_CLOSED)) + report_evil_fh(gv, GvIO(gv), PL_op->op_type); max = 0; } } else { SV* sv = POPs; if (SvTYPE(sv) == SVt_PVGV) { - tmpgv = (GV*)sv; + gv = (GV*)sv; goto do_fstat; } else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVGV) { - tmpgv = (GV*)SvRV(sv); + gv = (GV*)SvRV(sv); goto do_fstat; } sv_setpv(PL_statname, SvPV(sv,n_a)); @@ -2557,7 +2609,7 @@ PP(pp_stat) PUSHs(sv_2mortal(newSVuv(PL_statcache.st_uid))); # endif #endif -#if Gid_t_size > IVSIZE +#if Gid_t_size > IVSIZE PUSHs(sv_2mortal(newSVnv(PL_statcache.st_gid))); #else # if Gid_t_sign <= 0 @@ -3058,10 +3110,10 @@ PP(pp_fttext) len = 512; } else { - if (ckWARN(WARN_UNOPENED)) { + dTHR; + if (ckWARN2(WARN_UNOPENED,WARN_CLOSED)) { gv = cGVOP_gv; - Perl_warner(aTHX_ WARN_UNOPENED, "%s on unopened filehandle %s", - PL_op_desc[PL_op->op_type], GvENAME(gv)); + report_evil_fh(gv, GvIO(gv), PL_op->op_type); } SETERRNO(EBADF,RMS$_IFI); RETPUSHUNDEF; @@ -3109,7 +3161,7 @@ PP(pp_fttext) break; } #ifdef EBCDIC - else if (!(isPRINT(*s) || isSPACE(*s))) + else if (!(isPRINT(*s) || isSPACE(*s))) odd++; #else else if (*s & 128) { @@ -3697,13 +3749,18 @@ PP(pp_fork) PP(pp_wait) { -#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(MACOS_TRADITIONAL) +#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(MACOS_TRADITIONAL) djSP; dTARGET; Pid_t childpid; int argflags; childpid = wait4pid(-1, &argflags, 0); +# if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS) + /* 0 and -1 are both error returns (the former applies to WNOHANG case) */ + STATUS_NATIVE_SET((childpid && childpid != -1) ? argflags : -1); +# else STATUS_NATIVE_SET((childpid > 0) ? argflags : -1); +# endif XPUSHi(childpid); RETURN; #else @@ -3713,7 +3770,7 @@ PP(pp_wait) PP(pp_waitpid) { -#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(MACOS_TRADITIONAL) +#if (!defined(DOSISH) || defined(OS2) || defined(WIN32)) && !defined(MACOS_TRADITIONAL) djSP; dTARGET; Pid_t childpid; int optype; @@ -3722,7 +3779,12 @@ PP(pp_waitpid) optype = POPi; childpid = TOPi; childpid = wait4pid(childpid, &argflags, optype); +# if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS) + /* 0 and -1 are both error returns (the former applies to WNOHANG case) */ + STATUS_NATIVE_SET((childpid && childpid != -1) ? argflags : -1); +# else STATUS_NATIVE_SET((childpid > 0) ? argflags : -1); +# endif SETi(childpid); RETURN; #else @@ -3823,6 +3885,8 @@ PP(pp_system) } PerlProc__exit(-1); #else /* ! FORK or VMS or OS/2 */ + PL_statusvalue = 0; + result = 0; if (PL_op->op_flags & OPf_STACKED) { SV *really = *++MARK; value = (I32)do_aspawn(really, (void **)MARK, (void **)SP); @@ -3832,10 +3896,12 @@ PP(pp_system) else { value = (I32)do_spawn(SvPVx(sv_mortalcopy(*SP), n_a)); } + if (PL_statusvalue == -1) /* hint that value must be returned as is */ + result = 1; STATUS_NATIVE_SET(value); do_execfree(); SP = ORIGMARK; - PUSHi(STATUS_CURRENT); + PUSHi(result ? value : STATUS_CURRENT); #endif /* !FORK or VMS */ RETURN; } @@ -4498,7 +4564,7 @@ PP(pp_gprotoent) #if defined(HAS_GETPROTOBYNAME) || defined(HAS_GETPROTOBYNUMBER) || defined(HAS_GETPROTOENT) I32 which = PL_op->op_type; register char **elem; - register SV *sv; + register SV *sv; #ifndef HAS_GETPROTO_PROTOS /* XXX Do we need individual probes? */ struct protoent *PerlSock_getprotobyname(Netdb_name_t); struct protoent *PerlSock_getprotobynumber(int); @@ -4783,7 +4849,7 @@ PP(pp_gpwent) register SV *sv; STRLEN n_a; struct passwd *pwent = NULL; - /* + /* * We currently support only the SysV getsp* shadow password interface. * The interface is declared in and often one needs to link * with -lsecurity or some such. @@ -4824,7 +4890,7 @@ PP(pp_gpwent) * * Note that is already probed for, but currently * it is only included in special cases. - * + * * In Digital UNIX/Tru64 if using the getespw*() (which seems to be * be preferred interface, even though also the getprpw*() interface * is available) one needs to link with -lsecurity -ldb -laud -lm. @@ -5155,7 +5221,7 @@ PP(pp_syscall) a[i++] = SvIV(*MARK); else if (*MARK == &PL_sv_undef) a[i++] = 0; - else + else a[i++] = (unsigned long)SvPV_force(*MARK, n_a); if (i > 15) break; @@ -5223,7 +5289,7 @@ PP(pp_syscall) } #ifdef FCNTL_EMULATE_FLOCK - + /* XXX Emulate flock() with fcntl(). What's really needed is a good file locking module. */ @@ -5232,7 +5298,7 @@ static int fcntl_emulate_flock(int fd, int operation) { struct flock flock; - + switch (operation & ~LOCK_NB) { case LOCK_SH: flock.l_type = F_RDLCK; @@ -5249,7 +5315,7 @@ fcntl_emulate_flock(int fd, int operation) } flock.l_whence = SEEK_SET; flock.l_start = flock.l_len = (Off_t)0; - + return fcntl(fd, (operation & LOCK_NB) ? F_SETLK : F_SETLKW, &flock); }