X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/c0888ace5ec8d378714cd95caba0b35057e6c3f1..1cabb3b3b727154db4b25ac10caffab317ab68c3:/perlio.c diff --git a/perlio.c b/perlio.c index a89bf8b..79c6fdf 100644 --- a/perlio.c +++ b/perlio.c @@ -155,23 +155,6 @@ perlsio_binmode(FILE *fp, int iotype, int mode) #else if (PerlLIO_setmode(fileno(fp), mode) != -1) { #endif -# if defined(WIN32) && defined(__BORLANDC__) - /* - * The translation mode of the stream is maintained independent -of - * the translation mode of the fd in the Borland RTL (heavy - * digging through their runtime sources reveal). User has to -set - * the mode explicitly for the stream (though they don't -document - * this anywhere). GSAR 97-5-24 - */ - fseek(fp, 0L, 0); - if (mode & O_BINARY) - fp->flags |= _F_BIN; - else - fp->flags &= ~_F_BIN; -# endif return 1; } else @@ -468,13 +451,6 @@ PerlIO_findFILE(PerlIO *pio) #include "perliol.h" -/* - * We _MUST_ have if we are using lseek() and may have large - * files - */ -#ifdef I_UNISTD -#include -#endif #ifdef HAS_MMAP #include #endif @@ -1267,17 +1243,17 @@ PerlIO_push(pTHX_ PerlIO *f, PERLIO_FUNCS_DECL(*tab), const char *mode, SV *arg) VERIFY_HEAD(f); if (tab->fsize != sizeof(PerlIO_funcs)) { Perl_croak( aTHX_ - "%s (%d) does not match %s (%d)", - "PerlIO layer function table size", tab->fsize, - "size expected by this perl", sizeof(PerlIO_funcs) ); + "%s (%"UVuf") does not match %s (%"UVuf")", + "PerlIO layer function table size", (UV)tab->fsize, + "size expected by this perl", (UV)sizeof(PerlIO_funcs) ); } if (tab->size) { PerlIOl *l; if (tab->size < sizeof(PerlIOl)) { Perl_croak( aTHX_ - "%s (%d) smaller than %s (%d)", - "PerlIO layer instance size", tab->size, - "size expected by this perl", sizeof(PerlIOl) ); + "%s (%"UVuf") smaller than %s (%"UVuf")", + "PerlIO layer instance size", (UV)tab->size, + "size expected by this perl", (UV)sizeof(PerlIOl) ); } /* Real layer with a data area */ if (f) { @@ -1323,7 +1299,7 @@ PerlIOBase_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, PerlIO_funcs * const tab = PerlIO_layer_fetch(aTHX_ layers, n - 1, PerlIO_default_layer(aTHX_ 0)); if (tab && tab->Open) { PerlIO* ret = (*tab->Open)(aTHX_ tab, layers, n - 1, mode, fd, imode, perm, old, narg, args); - if (ret && PerlIO_push(aTHX_ ret, self, mode, PerlIOArg) == -1) { + if (ret && PerlIO_push(aTHX_ ret, self, mode, PerlIOArg) == NULL) { PerlIO_close(ret); return NULL; } @@ -1963,7 +1939,7 @@ PERLIO_FUNCS_DECL(PerlIO_utf8) = { sizeof(PerlIO_funcs), "utf8", 0, - PERLIO_K_DUMMY | PERLIO_K_UTF8, + PERLIO_K_DUMMY | PERLIO_K_UTF8 | PERLIO_K_MULTIARG, PerlIOUtf8_pushed, NULL, PerlIOBase_open, @@ -1994,7 +1970,7 @@ PERLIO_FUNCS_DECL(PerlIO_byte) = { sizeof(PerlIO_funcs), "bytes", 0, - PERLIO_K_DUMMY, + PERLIO_K_DUMMY | PERLIO_K_MULTIARG, PerlIOUtf8_pushed, NULL, PerlIOBase_open, @@ -2021,20 +1997,6 @@ PERLIO_FUNCS_DECL(PerlIO_byte) = { NULL, /* set_ptrcnt */ }; -PerlIO * -PerlIORaw_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers, - IV n, const char *mode, int fd, int imode, int perm, - PerlIO *old, int narg, SV **args) -{ - PerlIO_funcs * const tab = PerlIO_default_btm(); - PERL_UNUSED_ARG(self); - if (tab && tab->Open) - return (*tab->Open) (aTHX_ tab, layers, n - 1, mode, fd, imode, perm, - old, narg, args); - SETERRNO(EINVAL, LIB_INVARG); - return NULL; -} - PERLIO_FUNCS_DECL(PerlIO_raw) = { sizeof(PerlIO_funcs), "raw", @@ -2042,7 +2004,7 @@ PERLIO_FUNCS_DECL(PerlIO_raw) = { PERLIO_K_DUMMY, PerlIORaw_pushed, PerlIOBase_popped, - PerlIORaw_open, + PerlIOBase_open, NULL, NULL, NULL, @@ -2426,6 +2388,7 @@ PerlIOUnix_refcnt_inc(int fd) PL_perlio_fd_refcnt[fd]++; if (PL_perlio_fd_refcnt[fd] <= 0) { + /* diag_listed_as: refcnt_inc: fd %d%s */ Perl_croak(aTHX_ "refcnt_inc: fd %d: %d <= 0\n", fd, PL_perlio_fd_refcnt[fd]); } @@ -2436,6 +2399,7 @@ PerlIOUnix_refcnt_inc(int fd) MUTEX_UNLOCK(&PL_perlio_mutex); #endif } else { + /* diag_listed_as: refcnt_inc: fd %d%s */ Perl_croak(aTHX_ "refcnt_inc: fd %d < 0\n", fd); } } @@ -2451,10 +2415,12 @@ PerlIOUnix_refcnt_dec(int fd) MUTEX_LOCK(&PL_perlio_mutex); #endif if (fd >= PL_perlio_fd_refcnt_size) { + /* diag_listed_as: refcnt_dec: fd %d%s */ Perl_croak(aTHX_ "refcnt_dec: fd %d >= refcnt_size %d\n", fd, PL_perlio_fd_refcnt_size); } if (PL_perlio_fd_refcnt[fd] <= 0) { + /* diag_listed_as: refcnt_dec: fd %d%s */ Perl_croak(aTHX_ "refcnt_dec: fd %d: %d <= 0\n", fd, PL_perlio_fd_refcnt[fd]); } @@ -2464,11 +2430,43 @@ PerlIOUnix_refcnt_dec(int fd) MUTEX_UNLOCK(&PL_perlio_mutex); #endif } else { + /* diag_listed_as: refcnt_dec: fd %d%s */ Perl_croak(aTHX_ "refcnt_dec: fd %d < 0\n", fd); } return cnt; } +int +PerlIOUnix_refcnt(int fd) +{ + dTHX; + int cnt = 0; + if (fd >= 0) { + dVAR; +#ifdef USE_ITHREADS + MUTEX_LOCK(&PL_perlio_mutex); +#endif + if (fd >= PL_perlio_fd_refcnt_size) { + /* diag_listed_as: refcnt: fd %d%s */ + Perl_croak(aTHX_ "refcnt: fd %d >= refcnt_size %d\n", + fd, PL_perlio_fd_refcnt_size); + } + if (PL_perlio_fd_refcnt[fd] <= 0) { + /* diag_listed_as: refcnt: fd %d%s */ + Perl_croak(aTHX_ "refcnt: fd %d: %d <= 0\n", + fd, PL_perlio_fd_refcnt[fd]); + } + cnt = PL_perlio_fd_refcnt[fd]; +#ifdef USE_ITHREADS + MUTEX_UNLOCK(&PL_perlio_mutex); +#endif + } else { + /* diag_listed_as: refcnt: fd %d%s */ + Perl_croak(aTHX_ "refcnt: fd %d < 0\n", fd); + } + return cnt; +} + void PerlIO_cleanup(pTHX) { @@ -2565,8 +2563,10 @@ S_perlio_async_run(pTHX_ PerlIO* f) { SAVEDESTRUCTOR_X(S_lockcnt_dec, (void*)f); PerlIO_lockcnt(f)++; PERL_ASYNC_CHECK(); - if ( !(PerlIOBase(f)->flags & PERLIO_F_CLEARED) ) + if ( !(PerlIOBase(f)->flags & PERLIO_F_CLEARED) ) { + LEAVE; return 0; + } /* we've just run some perl-level code that could have done * anything, including closing the file or clearing this layer. * If so, free any lower layers that have already been @@ -2578,6 +2578,7 @@ S_perlio_async_run(pTHX_ PerlIO* f) { *f = l->next; Safefree(l); } + LEAVE; return 1; } @@ -3219,9 +3220,7 @@ PerlIOStdio_invalidate_fileno(pTHX_ FILE *f) f->_file = -1; return 1; # elif defined(WIN32) -# if defined(__BORLANDC__) - f->fd = PerlLIO_dup(fileno(f)); -# elif defined(UNDER_CE) +# if defined(UNDER_CE) /* WIN_CE does not have access to FILE internals, it hardly has FILE structure at all */ @@ -4522,12 +4521,10 @@ PerlIOCrlf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab) PerlIOBase(f)->flags); #endif { - /* Enable the first CRLF capable layer you can find, but if none - * found, the one we just pushed is fine. This results in at - * any given moment at most one CRLF-capable layer being enabled - * in the whole layer stack. */ + /* If the old top layer is a CRLF layer, reactivate it (if + * necessary) and remove this new layer from the stack */ PerlIO *g = PerlIONext(f); - while (PerlIOValid(g)) { + if (PerlIOValid(g)) { PerlIOl *b = PerlIOBase(g); if (b && b->tab == &PerlIO_crlf) { if (!(b->flags & PERLIO_F_CRLF)) @@ -4535,8 +4532,7 @@ PerlIOCrlf_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab) S_inherit_utf8_flag(g); PerlIO_pop(aTHX_ f); return code; - } - g = PerlIONext(g); + } } } S_inherit_utf8_flag(f);