Author: chromatic
Date: Thu May  3 00:57:59 2007
New Revision: 18410

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

Log:
[IO] Fix C++-hating casts in IO layers, or at least the ones that compile on my 
system.

Modified: trunk/src/io/io_buf.c
==============================================================================
--- trunk/src/io/io_buf.c       (original)
+++ trunk/src/io/io_buf.c       Thu May  3 00:57:59 2007
@@ -87,10 +87,12 @@
 {
     if (PIO_STDOUT(interp))
         PIO_buf_setlinebuf(interp, layer,
-                           PMC_data(PIO_STDOUT(interp)));
+                           PMC_data_typed(PIO_STDOUT(interp), ParrotIO *));
+
     if (PIO_STDIN(interp))
-        PIO_buf_setbuf(interp, layer, PMC_data(PIO_STDIN(interp)),
-                         PIO_UNBOUND);
+        PIO_buf_setbuf(interp, layer,
+            PMC_data_typed(PIO_STDIN(interp), ParrotIO *), PIO_UNBOUND);
+
     return 0;
 }
 
@@ -146,7 +148,7 @@
 PIO_buf_setbuf(Interp *interp, ParrotIOLayer *layer, ParrotIO *io, size_t 
bufsize)
 {
     ParrotIOLayer * const l = layer ? layer : io->stack;
-    ParrotIOBuf * const b = &io->b;
+    ParrotIOBuf   * const b = &io->b;
 
     /* If there is a buffer, make sure we flush before
      * dinking around with the buffer.
@@ -173,7 +175,7 @@
     }
 
     if (b->size > 0) {
-        b->startb = b->next = mem_sys_allocate(b->size);
+        b->startb = b->next = (unsigned char *)mem_sys_allocate(b->size);
         b->flags |= PIO_BF_MALLOC;
     }
     else

Modified: trunk/src/io/io_layers.c
==============================================================================
--- trunk/src/io/io_layers.c    (original)
+++ trunk/src/io/io_layers.c    Thu May  3 00:57:59 2007
@@ -39,16 +39,16 @@
 ParrotIOLayer *
 PIO_base_new_layer(ParrotIOLayer *proto)
 {
-    ParrotIOLayer * const new_layer = mem_sys_allocate(sizeof (ParrotIOLayer));
+    ParrotIOLayer * const new_layer = mem_allocate_typed(ParrotIOLayer);
 
     /*
      * XXX use managed memory here ?
      */
     if (proto) {
         /* FIXME: Flag here to indicate whether to free strings */
-        new_layer->name = proto->name;
+        new_layer->name  = proto->name;
         new_layer->flags = proto->flags;
-        new_layer->api = proto->api;
+        new_layer->api   = proto->api;
     }
     else {
         new_layer->name = NULL;
@@ -99,18 +99,20 @@
 INTVAL
 PIO_push_layer(Interp *interp,  PMC *pmc, ParrotIOLayer *layer)
 {
-
     if (layer == NULL)
         return -1;
+
     if (!PMC_IS_NULL(pmc)) {
-        ParrotIOLayer *t;
-        ParrotIO * const io = PMC_data(pmc);
+        ParrotIOLayer    *t;
+        ParrotIO * const io = PMC_data_typed(pmc, ParrotIO *);
+
         if (!io)
             return -1;
-        if (io->stack == NULL && (layer->flags & PIO_L_TERMINAL) == 0) {
-            /* Error( 1st layer must be terminal) */
+
+        /* Error( 1st layer must be terminal) */
+        if (io->stack == NULL && (layer->flags & PIO_L_TERMINAL) == 0)
             return -1;
-        }
+
         /* Check and see if this layer already is on stack
          * This is a internals sanity check not a user level
          * check, at least until I fix copy-on-write stacks.
@@ -120,18 +122,20 @@
             if (t == layer)
                 return -1;
         }
-        /*
-         * if this is a global layer create a copy first
-         */
-        if (!(io->stack->flags & PIO_L_LAYER_COPIED)) {
+
+        /* if this is a global layer create a copy first */
+        if (!(io->stack->flags & PIO_L_LAYER_COPIED))
             io->stack = PIO_copy_stack(io->stack);
-        }
 
         layer->down = io->stack;
+
         if (io->stack)
             io->stack->up = layer;
+
         io->stack = layer;
+
         PMC_struct_val(pmc) = layer;
+
         if (layer->api->Pushed)
             (*layer->api->Pushed) (layer, io);
     }
@@ -205,40 +209,46 @@
 ParrotIOLayer *
 PIO_pop_layer(Interp *interp, PMC *pmc)
 {
-    ParrotIO * const io = PMC_data(pmc);
+    ParrotIO * const io = PMC_data_typed(pmc, ParrotIO *);
 
     if (!PMC_IS_NULL(pmc)) {
         ParrotIOLayer *layer;
+
         if (!io)
             return 0;
-        /*
-         * if this is a global layer create a copy first
-         */
-        if (!(io->stack->flags & PIO_L_LAYER_COPIED)) {
+
+        /* if this is a global layer create a copy first */
+        if (!(io->stack->flags & PIO_L_LAYER_COPIED))
             io->stack = PIO_copy_stack(io->stack);
-        }
+
         layer = io->stack;
+
         if (layer) {
-            io->stack = layer->down;
+            io->stack           = layer->down;
             PMC_struct_val(pmc) = io->stack;
-            io->stack->up = 0;
-            layer->up = 0;
-            layer->down = 0;
+            io->stack->up       = 0;
+            layer->up           = 0;
+            layer->down         = 0;
+
             if (layer->api->Popped)
                 (*layer->api->Popped) (layer, io);
+
             return layer;
         }
+
         return layer;
     }
     /* Null io object - use default stack */
     else {
-        ParrotIOData * const d = interp->piodata;
+        ParrotIOData  * const d     = interp->piodata;
         ParrotIOLayer * const layer = d->default_stack;
+
         if (layer) {
-            d->default_stack = layer->down;
+            d->default_stack     = layer->down;
             d->default_stack->up = NULL;
-            layer->up = 0;
-            layer->down = 0;
+            layer->up            = 0;
+            layer->down          = 0;
+
             return layer;
         }
     }

Modified: trunk/src/io/io_string.c
==============================================================================
--- trunk/src/io/io_string.c    (original)
+++ trunk/src/io/io_string.c    Thu May  3 00:57:59 2007
@@ -51,7 +51,7 @@
     if (l->self == 0)
         return 0;
 
-    *buf    = l->self;
+    *buf    = (STRING *)l->self;
     l->self = 0;
 
     return (*buf)->strlen;
@@ -60,10 +60,8 @@
 static size_t
 PIO_string_write(Interp *interp, ParrotIOLayer *l, ParrotIO *io, STRING *s)
 {
-    STRING * old_string;
-
+    STRING *old_string = (STRING *)l->self;
     UNUSED(io);
-    old_string = l->self;
 
     if (old_string == 0) {
         l->self = s;
@@ -71,7 +69,7 @@
     }
 
     l->self = string_append(interp, old_string, s);
-    return string_length(interp, l->self);
+    return string_length(interp, (STRING *)l->self);
 }
 
 static const ParrotIOLayerAPI pio_string_layer_api = {

Reply via email to