X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=perlio.c;h=288159c188c2ff7de17afd7a0a6e864c99d12470;hb=5f2d99664d8a6923d24892ffc0569f4e03e22edd;hp=0cb4922f68432a14cf6d7ae748da467a189aafef;hpb=334e202ef11738e690e868e859b7602254641974;p=p5sagit%2Fp5-mst-13.2.git diff --git a/perlio.c b/perlio.c index 0cb4922..288159c 100644 --- a/perlio.c +++ b/perlio.c @@ -30,7 +30,11 @@ #ifdef PERL_MICRO # include "uconfig.h" #else -# include "config.h" +# ifndef USE_CROSS_COMPILE +# include "config.h" +# else +# include "xconfig.h" +# endif #endif #define PERLIO_NOT_STDIO 0 @@ -475,7 +479,11 @@ PerlIO_debug(const char *fmt, ...) /* Use fixed buffer as sv_catpvf etc. needs SVs */ char buffer[1024]; const STRLEN len = my_sprintf(buffer, "%.40s:%" IVdf " ", s ? s : "(none)", (IV) CopLINE(PL_curcop)); +# ifdef USE_VSNPRINTF + const STRLEN len2 = vsnprintf(buffer+len, sizeof(buffer) - len, fmt, ap); +# else const STRLEN len2 = vsprintf(buffer+len, fmt, ap); +# endif /* USE_VSNPRINTF */ PerlLIO_write(PL_perlio_debug_fd, buffer, len + len2); #else const char *s = CopFILE(PL_curcop); @@ -614,7 +622,7 @@ PerlIO_list_push(pTHX_ PerlIO_list_t *list, PerlIO_funcs *funcs, SV *arg) p = &(list->array[list->cur++]); p->funcs = funcs; if ((p->arg = arg)) { - SvREFCNT_inc_void_NN(arg); + SvREFCNT_inc_simple_void_NN(arg); } } @@ -645,7 +653,7 @@ PerlIO_clone(pTHX_ PerlInterpreter *proto, CLONE_PARAMS *param) PL_known_layers = PerlIO_clone_list(aTHX_ proto->Iknown_layers, param); PL_def_layerlist = PerlIO_clone_list(aTHX_ proto->Idef_layerlist, param); PerlIO_allocate(aTHX); /* root slot is never used */ - PerlIO_debug("Clone %p from %p\n",aTHX,proto); + PerlIO_debug("Clone %p from %p\n",(void*)aTHX,(void*)proto); while ((f = *table)) { int i; table = (PerlIO **) (f++); @@ -657,6 +665,7 @@ PerlIO_clone(pTHX_ PerlInterpreter *proto, CLONE_PARAMS *param) } } #else + PERL_UNUSED_CONTEXT; PERL_UNUSED_ARG(proto); PERL_UNUSED_ARG(param); #endif @@ -669,7 +678,7 @@ PerlIO_destruct(pTHX) PerlIO **table = &PL_perlio; PerlIO *f; #ifdef USE_ITHREADS - PerlIO_debug("Destruct %p\n",aTHX); + PerlIO_debug("Destruct %p\n",(void*)aTHX); #endif while ((f = *table)) { int i; @@ -1182,19 +1191,26 @@ PerlIO_push(pTHX_ PerlIO *f, PERLIO_FUNCS_DECL(*tab), const char *mode, SV *arg) goto mismatch; } /* Real layer with a data area */ - Newxc(l,tab->size,char,PerlIOl); - if (l && f) { - Zero(l, tab->size, char); - l->next = *f; - l->tab = (PerlIO_funcs*) tab; - *f = l; - PerlIO_debug("PerlIO_push f=%p %s %s %p\n", (void*)f, tab->name, - (mode) ? mode : "(Null)", (void*)arg); - if (*l->tab->Pushed && - (*l->tab->Pushed) (aTHX_ f, mode, arg, (PerlIO_funcs*) tab) != 0) { - PerlIO_pop(aTHX_ f); - return NULL; + if (f) { + char *temp; + Newxz(temp, tab->size, char); + l = (PerlIOl*)temp; + if (l) { + l->next = *f; + l->tab = (PerlIO_funcs*) tab; + *f = l; + PerlIO_debug("PerlIO_push f=%p %s %s %p\n", + (void*)f, tab->name, + (mode) ? mode : "(Null)", (void*)arg); + if (*l->tab->Pushed && + (*l->tab->Pushed) + (aTHX_ f, mode, arg, (PerlIO_funcs*) tab) != 0) { + PerlIO_pop(aTHX_ f); + return NULL; + } } + else + return NULL; } } else if (f) { @@ -2097,7 +2113,7 @@ PerlIOBase_read(pTHX_ PerlIO *f, void *vbuf, Size_t count) SSize_t avail = PerlIO_get_cnt(f); SSize_t take = 0; if (avail > 0) - take = ((SSize_t)count < avail) ? count : avail; + take = ((SSize_t)count < avail) ? (SSize_t)count : avail; if (take > 0) { STDCHAR *ptr = PerlIO_get_ptr(f); Copy(ptr, buf, take, STDCHAR); @@ -2260,6 +2276,7 @@ perl_mutex PerlIO_mutex; /* Must be called with PerlIO_mutex locked. */ static void S_more_refcounted_fds(pTHX_ const int new_fd) { + dVAR; const int old_max = PL_perlio_fd_refcnt_size; const int new_max = 16 + (new_fd & ~15); int *new_array; @@ -2289,7 +2306,9 @@ S_more_refcounted_fds(pTHX_ const int new_fd) { PL_perlio_fd_refcnt_size = new_max; PL_perlio_fd_refcnt = new_array; - PerlIO_debug("Zeroing %p, %d\n", new_array + old_max, new_max - old_max); + PerlIO_debug("Zeroing %p, %d\n", + (void*)(new_array + old_max), + new_max - old_max); Zero(new_array + old_max, new_max - old_max, int); } @@ -2358,7 +2377,7 @@ PerlIO_cleanup(pTHX) dVAR; int i; #ifdef USE_ITHREADS - PerlIO_debug("Cleanup layers for %p\n",aTHX); + PerlIO_debug("Cleanup layers for %p\n",(void*)aTHX); #else PerlIO_debug("Cleanup layers\n"); #endif @@ -2559,7 +2578,7 @@ PerlIOUnix_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, } else { if (f) { - /*EMPTY*/; + NOOP; /* * FIXME: pop layers ??? */ @@ -2864,7 +2883,6 @@ PerlIOStdio_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, #endif stdio = PerlSIO_fopen(path, mode); if (stdio) { - PerlIOStdio *s; if (!f) { f = PerlIO_allocate(aTHX); } @@ -2872,9 +2890,10 @@ PerlIOStdio_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, mode = PerlIOStdio_mode(mode, tmode); f = PerlIO_push(aTHX_ f, self, mode, PerlIOArg); if (f) { - s = PerlIOSelf(f, PerlIOStdio); - s->stdio = stdio; - PerlIOUnix_refcnt_inc(fileno(s->stdio)); + PerlIOSelf(f, PerlIOStdio)->stdio = stdio; + PerlIOUnix_refcnt_inc(fileno(stdio)); + } else { + PerlSIO_fclose(stdio); } return f; } @@ -2912,9 +2931,8 @@ PerlIOStdio_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, f = PerlIO_allocate(aTHX); } if ((f = PerlIO_push(aTHX_ f, self, mode, PerlIOArg))) { - PerlIOStdio * const s = PerlIOSelf(f, PerlIOStdio); - s->stdio = stdio; - PerlIOUnix_refcnt_inc(fileno(s->stdio)); + PerlIOSelf(f, PerlIOStdio)->stdio = stdio; + PerlIOUnix_refcnt_inc(fileno(stdio)); } return f; } @@ -2940,7 +2958,7 @@ PerlIOStdio_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags) goto set_this; } else { - /*EMPTY*/; + NOOP; /* FIXME: To avoid messy error recovery if dup fails re-use the existing stdio as though flag was not set */ @@ -2973,31 +2991,7 @@ PerlIOStdio_invalidate_fileno(pTHX_ FILE *f) f->_fileno = -1; return 1; # elif defined(__sun__) -# if defined(_LP64) - /* On solaris, if _LP64 is defined, the FILE structure is this: - * - * struct FILE { - * long __pad[16]; - * }; - * - * It turns out that the fd is stored in the top 32 bits of - * file->__pad[4]. The lower 32 bits contain flags. file->pad[5] appears - * to contain a pointer or offset into another structure. All the - * remaining fields are zero. - * - * We set the top bits to -1 (0xFFFFFFFF). - */ - f->__pad[4] |= 0xffffffff00000000L; - assert(fileno(f) == 0xffffffff); -# else /* !defined(_LP64) */ - /* _file is just a unsigned char :-( - Not clear why we dup() rather than using -1 - even if that would be treated as 0xFF - so will - a dup fail ... - */ - f->_file = PerlLIO_dup(fileno(f)); -# endif /* defined(_LP64) */ - return 1; + return 0; # elif defined(__hpux) f->__fileH = 0xff; f->__fileL = 0xff; @@ -3068,7 +3062,6 @@ PerlIOStdio_close(pTHX_ PerlIO *f) } else { const int fd = fileno(stdio); - int socksfd = 0; int invalidate = 0; IV result = 0; int saveerr = 0; @@ -3080,36 +3073,26 @@ PerlIOStdio_close(pTHX_ PerlIO *f) */ int optval; Sock_size_t optlen = sizeof(int); - if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *) &optval, &optlen) == 0) { - socksfd = 1; + if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *) &optval, &optlen) == 0) invalidate = 1; - } #endif - if (PerlIOUnix_refcnt_dec(fd) > 0) { - /* File descriptor still in use */ + if (PerlIOUnix_refcnt_dec(fd) > 0) /* File descriptor still in use */ invalidate = 1; - socksfd = 0; - } if (invalidate) { - /* For STD* handles don't close the stdio at all - this is because we have shared the FILE * too - */ - if (stdio == stdin) { - /* Some stdios are buggy fflush-ing inputs */ - return 0; - } - else if (stdio == stdout || stdio == stderr) { - return PerlIO_flush(f); - } + /* For STD* handles, don't close stdio, since we shared the FILE *, too. */ + if (stdio == stdin) /* Some stdios are buggy fflush-ing inputs */ + return 0; + if (stdio == stdout || stdio == stderr) + return PerlIO_flush(f); /* Tricky - must fclose(stdio) to free memory but not close(fd) Use Sarathy's trick from maint-5.6 to invalidate the fileno slot of the FILE * */ result = PerlIO_flush(f); saveerr = errno; - if (!(invalidate = PerlIOStdio_invalidate_fileno(aTHX_ stdio))) { - dupfd = PerlLIO_dup(fd); - } + invalidate = PerlIOStdio_invalidate_fileno(aTHX_ stdio); + if (!invalidate) + dupfd = PerlLIO_dup(fd); } result = PerlSIO_fclose(stdio); /* We treat error from stdio as success if we invalidated @@ -3119,10 +3102,10 @@ PerlIOStdio_close(pTHX_ PerlIO *f) errno = saveerr; result = 0; } - if (socksfd) { - /* in SOCKS case let close() determine return value */ - result = close(fd); - } +#ifdef SOCKS5_VERSION_NAME + /* in SOCKS' case, let close() determine return value */ + result = close(fd); +#endif if (dupfd) { PerlLIO_dup2(dupfd,fd); PerlLIO_close(dupfd); @@ -3264,7 +3247,7 @@ PerlIOStdio_flush(pTHX_ PerlIO *f) return PerlSIO_fflush(stdio); } else { - /*EMPTY*/; + NOOP; #if 0 /* * FIXME: This discards ungetc() and pre-read stuff which is not @@ -3744,6 +3727,8 @@ PerlIOBuf_fill(pTHX_ PerlIO *f) if (!b->buf) PerlIO_get_base(f); /* allocate via vtable */ + assert(b->buf); /* The b->buf does get allocated via the vtable system. */ + b->ptr = b->end = b->buf; if (!PerlIOValid(n)) { @@ -4404,7 +4389,7 @@ PerlIOCrlf_set_ptrcnt(pTHX_ PerlIO *f, STDCHAR * ptr, SSize_t cnt) ptr -= cnt; } else { - /*EMPTY*/; + NOOP; #if 0 /* * Test code - delete when it works ... @@ -5162,7 +5147,11 @@ int PerlIO_vsprintf(char *s, int n, const char *fmt, va_list ap) { dVAR; +#ifdef USE_VSNPRINTF + const int val = vsnprintf(s, n > 0 ? n : 0, fmt, ap); +#else const int val = vsprintf(s, fmt, ap); +#endif /* #ifdef USE_VSNPRINTF */ if (n >= 0) { if (strlen(s) >= (STRLEN) n) { dTHX;