Mark new_warnings_bitfield as XE, and add it to __DATA__ in makedef.pl
[p5sagit/p5-mst-13.2.git] / perlio.c
index 92a2879..8a93acb 100644 (file)
--- a/perlio.c
+++ b/perlio.c
@@ -602,6 +602,8 @@ PerlIO_list_push(pTHX_ PerlIO_list_t *list, PerlIO_funcs *funcs, SV *arg)
 {
     dVAR;
     PerlIO_pair_t *p;
+    PERL_UNUSED_CONTEXT;
+
     if (list->cur >= list->len) {
        list->len += 8;
        if (list->array)
@@ -612,14 +614,14 @@ 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)) {
-       (void)SvREFCNT_inc(arg);
+       SvREFCNT_inc_simple_void_NN(arg);
     }
 }
 
 PerlIO_list_t *
 PerlIO_clone_list(pTHX_ PerlIO_list_t *proto, CLONE_PARAMS *param)
 {
-    PerlIO_list_t *list = (PerlIO_list_t *) NULL;
+    PerlIO_list_t *list = NULL;
     if (proto) {
        int i;
        list = PerlIO_list_alloc(aTHX);
@@ -772,8 +774,7 @@ PerlIO_find_layer(pTHX_ const char *name, STRLEN len, int load)
            SAVEINT(PL_in_load_module);
            if (cv) {
                SAVEGENERICSV(PL_warnhook);
-               (void)SvREFCNT_inc(cv);
-               PL_warnhook = (SV *) cv;
+               PL_warnhook = (SV *) (SvREFCNT_inc_simple_NN(cv));
            }
            PL_in_load_module++;
            /*
@@ -856,7 +857,7 @@ XS(XS_io_MODIFY_SCALAR_ATTRIBUTES)
        const char * const name = SvPV_const(ST(i), len);
        SV * const layer = PerlIO_find_layer(aTHX_ name, len, 1);
        if (layer) {
-           av_push(av, SvREFCNT_inc(layer));
+           av_push(av, SvREFCNT_inc_simple_NN(layer));
        }
        else {
            ST(count) = ST(i);
@@ -1497,7 +1498,7 @@ PerlIO_resolve_layers(pTHX_ const char *layers,
        }
        else {
            PerlIO_list_free(aTHX_ av);
-           return (PerlIO_list_t *) NULL;
+           return NULL;
        }
     }
     else {
@@ -2863,7 +2864,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);
                    }
@@ -2871,9 +2871,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;
                }
@@ -2911,9 +2912,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;
            }
@@ -2972,31 +2972,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;
@@ -3067,7 +3043,6 @@ PerlIOStdio_close(pTHX_ PerlIO *f)
     }
     else {
         const int fd = fileno(stdio);
-       int socksfd = 0;
        int invalidate = 0;
        IV result = 0;
        int saveerr = 0;
@@ -3079,36 +3054,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
@@ -3118,10 +3083,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);
@@ -3743,6 +3708,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)) {