This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add 5.27.2 to perlhist
[perl5.git] / perlio.c
index ad1c6fe..209af1b 100644 (file)
--- a/perlio.c
+++ b/perlio.c
@@ -547,11 +547,12 @@ PerlIO_list_push(pTHX_ PerlIO_list_t *list, PerlIO_funcs *funcs, SV *arg)
     PERL_UNUSED_CONTEXT;
 
     if (list->cur >= list->len) {
-       list->len += 8;
+        const IV new_len = list->len + 8;
        if (list->array)
-           Renew(list->array, list->len, PerlIO_pair_t);
+           Renew(list->array, new_len, PerlIO_pair_t);
        else
-           Newx(list->array, list->len, PerlIO_pair_t);
+           Newx(list->array, new_len, PerlIO_pair_t);
+       list->len = new_len;
     }
     p = &(list->array[list->cur++]);
     p->funcs = funcs;
@@ -1314,7 +1315,7 @@ PerlIO_binmode(pTHX_ PerlIO *f, int iotype, int mode, const char *names)
           (for example :unix which is never going to call them)
           it can do the flush when it is pushed.
         */
-       return PerlIO_apply_layers(aTHX_ f, NULL, names) == 0 ? TRUE : FALSE;
+       return cBOOL(PerlIO_apply_layers(aTHX_ f, NULL, names) == 0);
     }
     else {
        /* Fake 5.6 legacy of using this call to turn ON O_TEXT */
@@ -1355,7 +1356,7 @@ PerlIO_binmode(pTHX_ PerlIO *f, int iotype, int mode, const char *names)
        /* Legacy binmode is now _defined_ as being equivalent to pushing :raw
           So code that used to be here is now in PerlIORaw_pushed().
         */
-       return PerlIO_push(aTHX_ f, PERLIO_FUNCS_CAST(&PerlIO_raw), NULL, NULL) ? TRUE : FALSE;
+       return cBOOL(PerlIO_push(aTHX_ f, PERLIO_FUNCS_CAST(&PerlIO_raw), NULL, NULL));
     }
 }
 
@@ -2273,9 +2274,7 @@ S_more_refcounted_fds(pTHX_ const int new_fd)
     new_array = (int*) realloc(PL_perlio_fd_refcnt, new_max * sizeof(int));
 
     if (!new_array) {
-#ifdef USE_ITHREADS
        MUTEX_UNLOCK(&PL_perlio_mutex);
-#endif
        croak_no_mem();
     }
 
@@ -2304,9 +2303,7 @@ PerlIOUnix_refcnt_inc(int fd)
     if (fd >= 0) {
        dVAR;
 
-#ifdef USE_ITHREADS
        MUTEX_LOCK(&PL_perlio_mutex);
-#endif
        if (fd >= PL_perlio_fd_refcnt_size)
            S_more_refcounted_fds(aTHX_ fd);
 
@@ -2319,9 +2316,7 @@ PerlIOUnix_refcnt_inc(int fd)
        DEBUG_i( PerlIO_debug("refcnt_inc: fd %d refcnt=%d\n",
                               fd, PL_perlio_fd_refcnt[fd]) );
 
-#ifdef USE_ITHREADS
        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);
@@ -2338,9 +2333,7 @@ PerlIOUnix_refcnt_dec(int fd)
 #else
        dVAR;
 #endif
-#ifdef USE_ITHREADS
        MUTEX_LOCK(&PL_perlio_mutex);
-#endif
        if (fd >= PL_perlio_fd_refcnt_size) {
            /* diag_listed_as: refcnt_dec: fd %d%s */
            Perl_croak_nocontext("refcnt_dec: fd %d >= refcnt_size %d\n",
@@ -2353,9 +2346,7 @@ PerlIOUnix_refcnt_dec(int fd)
        }
        cnt = --PL_perlio_fd_refcnt[fd];
        DEBUG_i( PerlIO_debug("refcnt_dec: fd %d refcnt=%d\n", fd, cnt) );
-#ifdef USE_ITHREADS
        MUTEX_UNLOCK(&PL_perlio_mutex);
-#endif
     } else {
        /* diag_listed_as: refcnt_dec: fd %d%s */
        Perl_croak_nocontext("refcnt_dec: fd %d < 0\n", fd);
@@ -2370,9 +2361,7 @@ PerlIOUnix_refcnt(int fd)
     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",
@@ -2384,9 +2373,7 @@ PerlIOUnix_refcnt(int fd)
                       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);
@@ -3231,7 +3218,7 @@ PerlIOStdio_invalidate_fileno(pTHX_ FILE *f)
        structure at all
      */
 #    else
-    f->_file = -1;
+    PERLIO_FILE_file(f) = -1;
 #    endif
     return 1;
 #  else
@@ -3289,7 +3276,6 @@ PerlIOStdio_close(pTHX_ PerlIO *f)
            if (stdio == stdout || stdio == stderr)
                return PerlIO_flush(f);
         }
-#ifdef USE_ITHREADS
         MUTEX_LOCK(&PL_perlio_mutex);
         /* Right. We need a mutex here because for a brief while we
            will have the situation that fd is actually closed. Hence if
@@ -3308,7 +3294,6 @@ PerlIOStdio_close(pTHX_ PerlIO *f)
 
            Except that correctness trumps speed.
            Advice from klortho #11912. */
-#endif
        if (invalidate) {
             /* Tricky - must fclose(stdio) to free memory but not close(fd)
               Use Sarathy's trick from maint-5.6 to invalidate the
@@ -3346,9 +3331,7 @@ PerlIOStdio_close(pTHX_ PerlIO *f)
            PerlLIO_dup2(dupfd,fd);
            PerlLIO_close(dupfd);
        }
-#ifdef USE_ITHREADS
         MUTEX_UNLOCK(&PL_perlio_mutex);
-#endif
        return result;
     }
 }