Author: pmichaud
Date: Sat Apr 22 09:11:26 2006
New Revision: 12398

Modified:
   trunk/src/io/io.c
   trunk/src/io/io_buf.c

Log:
* Undoing r12396/12397, caused segfaults on many platforms.


Modified: trunk/src/io/io.c
==============================================================================
--- trunk/src/io/io.c   (original)
+++ trunk/src/io/io.c   Sat Apr 22 09:11:26 2006
@@ -1,5 +1,5 @@
 /*
-Copyright: 2001-2006 The Perl Foundation.  All Rights Reserved.
+Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
 $Id$
 
 =head1 NAME
@@ -66,9 +66,14 @@
 PMC *
 new_io_pmc(theINTERP, ParrotIO *io)
 {
-    PMC * const new_pmc = pmc_new(interpreter, enum_class_ParrotIO);
+    PMC *new_pmc;
+    new_pmc = pmc_new(interpreter, enum_class_ParrotIO);
     PMC_data(new_pmc) = io;
-    PMC_struct_val(new_pmc) = io ? io->stack : NULL;
+    /* io could be NULL */
+    if(io)
+       PMC_struct_val(new_pmc) = io->stack;
+    else
+       PMC_struct_val(new_pmc) = NULL;
     return new_pmc;
 }
 
@@ -125,8 +130,10 @@
 ParrotIOTable
 alloc_pio_array(int numhandles)
 {
-    const size_t size = numhandles * sizeof(ParrotIO *);
-    return (ParrotIOTable)mem_sys_allocate_zeroed(size);
+    ParrotIOTable newhandles;
+    size_t size = numhandles * sizeof(ParrotIO *);
+    newhandles = (ParrotIOTable)mem_sys_allocate_zeroed(size);
+    return newhandles;
 }
 
 /*
@@ -166,9 +173,11 @@
 ParrotIO *
 PIO_new(theINTERP, INTVAL iotype, INTVAL flags, INTVAL mode)
 {
-    ParrotIO * const new_io = (ParrotIO *)mem_sys_allocate(sizeof(ParrotIO));
+    ParrotIO *new_io;
+
     UNUSED(iotype);
 
+    new_io = (ParrotIO *)mem_sys_allocate(sizeof(ParrotIO));
     new_io->fpos = new_io->lpos = piooffsetzero;
     new_io->flags = flags;
     new_io->mode = mode;
@@ -196,7 +205,7 @@
 void
 PIO_destroy(theINTERP, PMC *pmc)
 {
-    ParrotIO * const io = PMC_data0(pmc);
+    ParrotIO *io = PMC_data0(pmc);
     UNUSED(interpreter);
 
     if(!io)
@@ -562,8 +571,8 @@
 INTVAL
 PIO_peek(theINTERP, PMC *pmc, STRING **buffer)
 {
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data0(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data0(pmc);
     if(!io)
         return -1;
     return PIO_peek_down(interpreter, l, io, buffer);
@@ -594,7 +603,7 @@
 PIO_pioctl(theINTERP, PMC *pmc, INTVAL cmd, INTVAL arg)
 {
 
-    ParrotIO * const io = PMC_data0(pmc);
+    ParrotIO * io = PMC_data0(pmc);
     ParrotIOBuf * b;
     if(!io) return -1;
     b = &io->b;
@@ -645,8 +654,8 @@
 INTVAL
 PIO_setbuf(theINTERP, PMC *pmc, size_t bufsize)
 {
-    ParrotIOLayer * const layer = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data0(pmc);
+    ParrotIOLayer *layer = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data0(pmc);
     if(!io)
         return -1;
     PIO_flush(interpreter, pmc);
@@ -668,8 +677,8 @@
 INTVAL
 PIO_setlinebuf(theINTERP, PMC *pmc)
 {
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data0(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data0(pmc);
     if(!io)
         return -1;
 
@@ -693,7 +702,7 @@
          const char *sflags)
 {
     ParrotIO *io;
-    const INTVAL flags = PIO_parse_open_flags(sflags);
+    INTVAL flags = PIO_parse_open_flags(sflags);
 
     if (!layer) {
         layer = interpreter->piodata->default_stack;
@@ -766,8 +775,8 @@
 PIO_close(theINTERP, PMC *pmc)
 {
     INTVAL res;
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data0(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data0(pmc);
     if(!io)
         return -1;
     PIO_flush(interpreter, pmc); /* XXX boe: is this neccessary here? */
@@ -791,8 +800,8 @@
 void
 PIO_flush(theINTERP, PMC *pmc)
 {
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data0(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data0(pmc);
     if(!io)
         return;
 
@@ -819,9 +828,9 @@
 STRING *
 PIO_reads(theINTERP, PMC *pmc, size_t len)
 {
-    STRING *res;
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data0(pmc);
+    STRING *res = NULL;
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data0(pmc);
 
     if (!io)
         return new_string_header(interpreter, 0);
@@ -843,8 +852,8 @@
 INTVAL
 PIO_read(theINTERP, PMC *pmc, void *buffer, size_t len)
 {
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data0(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data0(pmc);
     STRING *res = new_string_header(interpreter, 0);
     if (!io)
         return -1;
@@ -868,8 +877,9 @@
 INTVAL
 PIO_write(theINTERP, PMC *pmc, const void *buffer, size_t len)
 {
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data0(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data0(pmc);
+    STRING fake;
     union {
         const void * __c_ptr;
         void * __ptr;
@@ -879,7 +889,6 @@
         return -1;
 
     if (io->flags & PIO_F_WRITE) {
-        STRING fake;
         /* TODO skip utf8 translation layers if any */
         fake.strstart = const_cast(buffer);
         fake.strlen = fake.bufused = len;
@@ -907,8 +916,8 @@
 PIOOFF_T
 PIO_seek(theINTERP, PMC *pmc, PIOOFF_T offset, INTVAL w)
 {
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data0(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data0(pmc);
     if(!io)
         return -1;
 
@@ -929,8 +938,8 @@
 PIOOFF_T
 PIO_tell(theINTERP, PMC *pmc)
 {
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data0(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data0(pmc);
     if(!io)
         return -1;
 
@@ -952,7 +961,7 @@
 INTVAL
 PIO_eof(theINTERP, PMC *pmc)
 {
-    ParrotIO * const io = PMC_data0(pmc);
+    ParrotIO *io = PMC_data0(pmc);
 
     UNUSED(interpreter);
 
@@ -982,7 +991,6 @@
     return PIO_write(interpreter, pmc, s, strlen(s));
 }
 
-/* XXX Should be in an external header file */
 void *Parrot_utf8_encode(void *ptr, UINTVAL c);
 
 /*
@@ -999,8 +1007,8 @@
 INTVAL
 PIO_putps(theINTERP, PMC *pmc, STRING *s)
 {
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data0(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data0(pmc);
     assert((unsigned long)l != 0xdeadbeefUL);
     assert(io != 0);
 #if ! DISABLE_GC_DEBUG
@@ -1026,7 +1034,7 @@
 PIO_fprintf(theINTERP, PMC *pmc, const char *s, ...)
 {
     va_list args;
-    INTVAL ret;
+    INTVAL ret=-1;
 
     va_start(args, s);
 
@@ -1051,12 +1059,13 @@
 INTVAL
 PIO_printf(theINTERP, const char *s, ...) {
     va_list args;
-    INTVAL ret;
+    STRING *str;
+    INTVAL ret=-1;
 
     va_start(args, s);
 
     if(interpreter) {
-        STRING * const str = Parrot_vsprintf_c(interpreter, s, args);
+        str=Parrot_vsprintf_c(interpreter, s, args);
         ret=PIO_putps(interpreter, PIO_STDOUT(interpreter), str);
     }
     else {
@@ -1085,12 +1094,13 @@
 INTVAL
 PIO_eprintf(theINTERP, const char *s, ...) {
     va_list args;
-    INTVAL ret;
+    STRING *str;
+    INTVAL ret=-1;
 
     va_start(args, s);
 
     if(interpreter) {
-        STRING * const str = Parrot_vsprintf_c(interpreter, s, args);
+        str=Parrot_vsprintf_c(interpreter, s, args);
 
         ret=PIO_putps(interpreter, PIO_STDERR(interpreter), str);
     }
@@ -1314,8 +1324,8 @@
 INTVAL
 PIO_poll(theINTERP, PMC *pmc, INTVAL which, INTVAL sec, INTVAL usec)
 {
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data0(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data0(pmc);
     return PIO_poll_down(interpreter, l, io, which, sec, usec);
 }
 
@@ -1335,8 +1345,9 @@
 PMC *
 PIO_socket(theINTERP, INTVAL fam, INTVAL type, INTVAL proto)
 {
-    ParrotIOLayer * const l = interpreter->piodata->default_stack;
-    ParrotIO * const io = PIO_socket_down(interpreter, l, fam, type, proto);
+    ParrotIO *io;
+    ParrotIOLayer *l = interpreter->piodata->default_stack;
+    io = PIO_socket_down(interpreter, l, fam, type, proto);
     /* We have to create a PMC here even if the IO handle
      * didn't create because caller has to be able to
      * check with a bool test. Can't use a NULL PMC in a bool
@@ -1359,8 +1370,8 @@
 INTVAL
 PIO_recv(theINTERP, PMC *pmc, STRING **buf)
 {
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data(pmc);
     if(!io)
         return -1;
 
@@ -1381,8 +1392,8 @@
 INTVAL
 PIO_send(theINTERP, PMC *pmc, STRING *buf)
 {
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data(pmc);
     if(!io)
         return -1;
 
@@ -1403,8 +1414,8 @@
 INTVAL
 PIO_connect(theINTERP, PMC *pmc, STRING *address)
 {
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data(pmc);
     if(!io)
         return -1;
 
@@ -1425,8 +1436,8 @@
 INTVAL
 PIO_bind(theINTERP, PMC *pmc, STRING *address)
 {
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data(pmc);
     if(!io)
         return -1;
 
@@ -1447,8 +1458,8 @@
 INTVAL
 PIO_listen(theINTERP, PMC *pmc, INTVAL backlog)
 {
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data(pmc);
     if(!io)
         return -1;
 
@@ -1469,8 +1480,8 @@
 PIO_accept(theINTERP, PMC *pmc)
 {
     ParrotIO *io2;
-    ParrotIOLayer * const l = PMC_struct_val(pmc);
-    ParrotIO * const io = PMC_data(pmc);
+    ParrotIOLayer *l = PMC_struct_val(pmc);
+    ParrotIO *io = PMC_data(pmc);
     if(!io)
         return NULL;
 
@@ -1492,7 +1503,7 @@
 INTVAL
 PIO_isatty(theINTERP, PMC *pmc)
 {
-    ParrotIO * const io = PMC_data(pmc);
+    ParrotIO *io = PMC_data(pmc);
 
     UNUSED(interpreter);
 
@@ -1507,7 +1518,7 @@
 int
 PIO_softspace(theINTERP, PMC *pmc, int new)
 {
-    ParrotIO * const io = PMC_data(pmc);
+    ParrotIO *io = PMC_data(pmc);
     int ret;
 
     UNUSED(interpreter);

Modified: trunk/src/io/io_buf.c
==============================================================================
--- trunk/src/io/io_buf.c       (original)
+++ trunk/src/io/io_buf.c       Sat Apr 22 09:11:26 2006
@@ -1,5 +1,5 @@
 /*
-Copyright: 2001-2006 The Perl Foundation.  All Rights Reserved.
+Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
 $Id$
 
 =head1 NAME
@@ -110,8 +110,10 @@
 PIO_buf_open(theINTERP, ParrotIOLayer *layer,
                const char *path, INTVAL flags)
 {
-    ParrotIOLayer * const l = PIO_DOWNLAYER(layer);
-    ParrotIO * const io = PIO_open_down(interpreter, l, path, flags);
+    ParrotIO *io;
+    ParrotIOLayer *l = PIO_DOWNLAYER(layer);
+
+    io = PIO_open_down(interpreter, l, path, flags);
     if (!io) {
         /* error creating IO stream */
         return NULL;
@@ -145,9 +147,10 @@
 static INTVAL
 PIO_buf_setbuf(theINTERP, ParrotIOLayer *layer, ParrotIO *io, size_t bufsize)
 {
-    ParrotIOLayer * const l = layer ? layer : io->stack;
-    ParrotIOBuf * const b = &io->b;
-
+    ParrotIOLayer *l = layer;
+    ParrotIOBuf *b = &io->b;
+    if(!l)
+        l = io->stack;
     /* If there is a buffer, make sure we flush before
      * dinking around with the buffer.
      */
@@ -204,7 +207,11 @@
 PIO_buf_setlinebuf(theINTERP, ParrotIOLayer *layer, ParrotIO *io)
 {
     int err;
-    ParrotIOLayer * const l = layer ? layer : io->stack;
+    ParrotIOLayer * l;
+
+    l = layer;
+    if(!l)
+        l = io->stack;
 
     /* already linebuffering */
     if (io->flags & PIO_F_LINEBUF)
@@ -235,9 +242,10 @@
 static ParrotIO *
 PIO_buf_fdopen(theINTERP, ParrotIOLayer *layer, PIOHANDLE fd, INTVAL flags)
 {
-    ParrotIOLayer * const l = PIO_DOWNLAYER(layer);
-    ParrotIO * const io = PIO_fdopen_down(interpreter, l, fd, flags);
+    ParrotIO *io;
+    ParrotIOLayer *l = PIO_DOWNLAYER(layer);
 
+    io = PIO_fdopen_down(interpreter, l, fd, flags);
     if (!io) {
         /* error creating IO stream */
         return NULL;
@@ -265,7 +273,7 @@
 static INTVAL
 PIO_buf_close(theINTERP, ParrotIOLayer *layer, ParrotIO *io)
 {
-    ParrotIOLayer * const l = PIO_DOWNLAYER(layer);
+    ParrotIOLayer *l = PIO_DOWNLAYER(layer);
     PIO_buf_flush(interpreter, layer, io);
 
     return PIO_close_down (interpreter, l, io);
@@ -299,7 +307,7 @@
      * Write flush
      */
     if (io->b.flags & PIO_BF_WRITEBUF) {
-        ParrotIOLayer * const l = layer;
+        ParrotIOLayer *l = layer;
         to_write = io->b.next - io->b.startb;
 
         /* Flush to next layer */
@@ -413,7 +421,7 @@
     out_buf = s->strstart;
     /* read Data from buffer */
     if (b->flags & PIO_BF_READBUF) {
-        const size_t avail = b->endb - b->next;
+        size_t avail = b->endb - b->next;
 
         current = avail < len ? avail : len;
         memcpy(out_buf, b->next, current);
@@ -443,11 +451,10 @@
     if (!(b->flags & PIO_BF_READBUF)) {
         size_t got;
         if (len >= io->b.size) {
-            STRING fake;
-            STRING *sf = &fake;
-
+            STRING fake, *sf;
             fake.strstart = out_buf;
             fake.bufused  = len;
+            sf = &fake;
             got = PIO_read_down(interpreter, PIO_DOWNLAYER(l), io, &sf);
             s->strlen = s->bufused = current + got;
             io->fpos += got;
@@ -481,8 +488,10 @@
     ParrotIOLayer *l = layer;
     ParrotIOBuf *b;
     size_t len = 1;
+    STRING *s;
+    size_t avail;
 
-    STRING * const s = PIO_make_io_string(interpreter, buf, 1);
+    s = PIO_make_io_string(interpreter, buf, 1);
 
     /* write buffer flush */
     if (io->b.flags & PIO_BF_WRITEBUF) {
@@ -493,7 +502,7 @@
 
     /* read Data from buffer */
     if (b->flags & PIO_BF_READBUF) {
-        const size_t avail = b->endb - b->next;
+        avail = b->endb - b->next;
 
         /* if we have data available, copy out the next byte */
         if (avail) {
@@ -540,7 +549,7 @@
     size_t l;
     unsigned char *out_buf;
     unsigned char *buf_start;
-    ParrotIOBuf * const b = &io->b;
+    ParrotIOBuf *b = &io->b;
     size_t len;
     STRING *s;
 
@@ -623,7 +632,7 @@
 {
     size_t avail;
     long wrote;
-    void * const buffer = s->strstart;
+    void *buffer = s->strstart;
     size_t len = s->bufused;
     int need_flush;
 
@@ -649,10 +658,10 @@
         char *p = (char*)buffer + len - 1;
         size_t i;
         for (i = 0; i < len; ++i, --p)
-            if (IS_EOL(io, p)) {
-                need_flush = 1;
-                break;
-            }
+        if (IS_EOL(io, p)) {
+            need_flush = 1;
+            break;
+        }
     }
 
     /*
@@ -681,7 +690,7 @@
         return len;
     }
     else {
-        const unsigned int diff = (int)(len - avail);
+        unsigned int diff = (int)(len - avail);
 
         io->b.flags |= PIO_BF_WRITEBUF;
         /* Fill remainder, flush, then try to buffer more */

Reply via email to