Change 17328 by jhi@alpha on 2002/06/20 17:41:42

        Integrate perlio:
        
        [ 17327]
        Fix segv on IO::File->open("/dev/null").

Affected files ...

.... //depot/perl/doio.c#204 integrate
.... //depot/perl/perlio.c#183 integrate

Differences ...

==== //depot/perl/doio.c#204 (text) ====
Index: perl/doio.c
--- perl/doio.c#203~17032~      Thu Jun  6 05:47:34 2002
+++ perl/doio.c Thu Jun 20 10:41:42 2002
@@ -663,7 +663,10 @@
     if (writing) {
        if (IoTYPE(io) == IoTYPE_SOCKET
            || (IoTYPE(io) == IoTYPE_WRONLY && fd >= 0 && S_ISCHR(PL_statbuf.st_mode)) 
) {
-           mode[0] = 'w';
+           char *s = mode;
+           if (*s == 'I' || *s == '#')
+            s++;
+           *s = 'w';
            if (!(IoOFP(io) = PerlIO_openn(aTHX_ type,mode,fd,0,0,NULL,0,svp))) {
                PerlIO_close(fp);
                IoIFP(io) = Nullfp;

==== //depot/perl/perlio.c#183 (text) ====
Index: perl/perlio.c
--- perl/perlio.c#182~17312~    Wed Jun 19 14:27:24 2002
+++ perl/perlio.c       Thu Jun 20 10:41:42 2002
@@ -2243,12 +2243,11 @@
            f = PerlIO_allocate(aTHX);
        }
        if (!PerlIOValid(f)) {
-           s = PerlIOSelf(PerlIO_push(aTHX_ f, self, mode, PerlIOArg),
-                          PerlIOUnix);
-       }
-       else {
-           s = PerlIOSelf(f, PerlIOUnix);
+           if (!(f = PerlIO_push(aTHX_ f, self, mode, PerlIOArg))) {
+               return NULL;
+           }
        }
+       s = PerlIOSelf(f, PerlIOUnix);
        s->fd = fd;
        s->oflags = imode;
        PerlIOBase(f)->flags |= PERLIO_F_OPEN;
@@ -2473,12 +2472,12 @@
               varies between stdio implementations.
             */
            int fd = PerlLIO_dup(fileno(stdio));
-           FILE *f2 = fdopen(fd, (mode = "r+"));
+           FILE *f2 = PerlSIO_fdopen(fd, (mode = "r+"));
            if (!f2) {
-               f2 = fdopen(fd, (mode = "w"));
+               f2 = PerlSIO_fdopen(fd, (mode = "w"));
            }
            if (!f2) {
-               f2 = fdopen(fd, (mode = "r"));
+               f2 = PerlSIO_fdopen(fd, (mode = "r"));
            }
            if (!f2) {
                /* Don't seem to be able to open */
@@ -2487,10 +2486,10 @@
            }
            fclose(f2);
        }
-       s = PerlIOSelf(PerlIO_push
-                          (aTHX_(f = PerlIO_allocate(aTHX)), &PerlIO_stdio,
-                           mode, Nullsv), PerlIOStdio);
-       s->stdio = stdio;
+       if ((f = PerlIO_push(aTHX_(f = PerlIO_allocate(aTHX)), &PerlIO_stdio, mode, 
+Nullsv))) {
+           s = PerlIOSelf(f, PerlIOStdio);
+           s->stdio = stdio;
+       }
     }
     return f;
 }
@@ -2528,12 +2527,13 @@
                    if (!f) {
                        f = PerlIO_allocate(aTHX);
                    }
-                   s = PerlIOSelf(PerlIO_push(aTHX_ f, self,
+                   if ((f = PerlIO_push(aTHX_ f, self,
                                    (mode = PerlIOStdio_mode(mode, tmode)),
-                                   PerlIOArg),
-                                  PerlIOStdio);
-                   s->stdio = stdio;
-                   PerlIOUnix_refcnt_inc(fileno(s->stdio));
+                                   PerlIOArg))) {
+                       s = PerlIOSelf(f, PerlIOStdio);
+                       s->stdio = stdio;
+                       PerlIOUnix_refcnt_inc(fileno(s->stdio));
+                   }
                }
                return f;
            }
@@ -2567,9 +2567,11 @@
                if (!f) {
                    f = PerlIO_allocate(aTHX);
                }
-               s = PerlIOSelf(PerlIO_push(aTHX_ f, self, mode, PerlIOArg), 
PerlIOStdio);
-               s->stdio = stdio;
-               PerlIOUnix_refcnt_inc(fileno(s->stdio));
+               if ((f = PerlIO_push(aTHX_ f, self, mode, PerlIOArg))) {
+                   s = PerlIOSelf(f, PerlIOStdio);
+                   s->stdio = stdio;
+                   PerlIOUnix_refcnt_inc(fileno(s->stdio));
+               }
                return f;
            }
        }
@@ -2589,7 +2591,7 @@
            int fd = PerlLIO_dup(fileno(stdio));
            if (fd >= 0) {
                char mode[8];
-               stdio = fdopen(fd, PerlIO_modestr(o,mode));
+               stdio = PerlSIO_fdopen(fd, PerlIO_modestr(o,mode));
            }
            else {
                /* FIXME: To avoid messy error recovery if dup fails
@@ -2975,12 +2977,12 @@
     if (!mode || !*mode) {
        mode = PerlIO_modestr(f,buf);
     }
-    stdio = fdopen(PerlIO_fileno(f), mode);
+    stdio = PerlSIO_fdopen(PerlIO_fileno(f), mode);
     if (stdio) {
-       PerlIOStdio *s =
-           PerlIOSelf(PerlIO_push(aTHX_ f, &PerlIO_stdio, buf, Nullsv),
-                      PerlIOStdio);
-       s->stdio = stdio;
+       if ((f = PerlIO_push(aTHX_ f, &PerlIO_stdio, buf, Nullsv))) {
+           PerlIOStdio *s = PerlIOSelf(f,PerlIOStdio);
+           s->stdio = stdio;
+       }
     }
     return stdio;
 }
@@ -4440,11 +4442,10 @@
     PerlIO *f = NULL;
     FILE *stdio = PerlSIO_tmpfile();
     if (stdio) {
-       PerlIOStdio *s =
-           PerlIOSelf(PerlIO_push
-                      (aTHX_(f = PerlIO_allocate(aTHX)), &PerlIO_stdio,
-                       "w+", Nullsv), PerlIOStdio);
-       s->stdio = stdio;
+       if ((f = PerlIO_push(aTHX_(PerlIO_allocate(aTHX)), &PerlIO_stdio, "w+", 
+Nullsv))) {
+           PerlIOStdio *s = PerlIOSelf(f, PerlIOStdio);
+           s->stdio = stdio;
+       }
     }
     return f;
 #else
End of Patch.

Reply via email to