cvsuser     04/05/19 06:22:55

  Modified:    .        MANIFEST
               io       io.c
               config/gen/makefiles root.in
  Added:       io       io_layers.c
  Log:
  io_layers 2 - split io_layers.c
  
  Revision  Changes    Path
  1.651     +1 -0      parrot/MANIFEST
  
  Index: MANIFEST
  ===================================================================
  RCS file: /cvs/public/parrot/MANIFEST,v
  retrieving revision 1.650
  retrieving revision 1.651
  diff -u -w -r1.650 -r1.651
  --- MANIFEST  19 May 2004 09:32:26 -0000      1.650
  +++ MANIFEST  19 May 2004 13:22:47 -0000      1.651
  @@ -1800,6 +1800,7 @@
   io/TODO                                           [main]doc
   io/io.c                                           []
   io/io_buf.c                                       []
  +io/io_layers.c                                    []
   io/io_passdown.c                                  []
   io/io_private.h                                   []
   io/io_stdio.c                                     []
  
  
  
  1.88      +2 -207    parrot/io/io.c
  
  Index: io.c
  ===================================================================
  RCS file: /cvs/public/parrot/io/io.c,v
  retrieving revision 1.87
  retrieving revision 1.88
  diff -u -w -r1.87 -r1.88
  --- io.c      23 Apr 2004 09:20:34 -0000      1.87
  +++ io.c      19 May 2004 13:22:51 -0000      1.88
  @@ -1,6 +1,6 @@
   /*
   Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -$Id: io.c,v 1.87 2004/04/23 09:20:34 jrieks Exp $
  +$Id: io.c,v 1.88 2004/05/19 13:22:51 leo Exp $
   
   =head1 NAME
   
  @@ -16,7 +16,7 @@
   
   This file implements the generic functionality. Specific layers are in
   separate files: F<io/io_buf.c>, F<io/io_stdio.c>, F<io/io_unix.c>,
  -F<io/io_win32.c>.
  +F<io/io_win32.c>, and F<io/io_layers.c>.
   
   The C<ParrotIO> PMC provides the class-based interface that is used in
   Parrot ops. The C<ParrotIO struct> is defined in F<io/io_private.h>.
  @@ -364,211 +364,6 @@
       return 0;
   }
   
  -/*
  -
  -=back
  -
  -=head2 Layer and Stack Functions
  -
  -=over 4
  -
  -=item C<ParrotIOLayer *
  -PIO_base_new_layer(ParrotIOLayer *proto)>
  -
  -The default IO layer constructor. Creates and returns a new
  -C<ParrotIOLayer>. If a prototype C<*proto> is supplied then it's values
  -will be copied to the new instance.
  -
  -=cut
  -
  -*/
  -
  -ParrotIOLayer *
  -PIO_base_new_layer(ParrotIOLayer *proto)
  -{
  -    ParrotIOLayer *new_layer;
  -
  -    new_layer = mem_sys_allocate(sizeof(ParrotIOLayer));
  -    if (proto) {
  -        /* FIXME: Flag here to indicate whether to free strings */
  -        new_layer->name = proto->name;
  -        new_layer->flags = proto->flags;
  -        new_layer->api = proto->api;
  -    }
  -    else {
  -        new_layer->name = NULL;
  -        new_layer->flags = 0;
  -        new_layer->api = NULL;
  -    }
  -    new_layer->self = 0;
  -    new_layer->up = NULL;
  -    new_layer->down = NULL;
  -    return new_layer;
  -}
  -
  -/*
  -
  -=item C<void
  -PIO_base_delete_layer(ParrotIOLayer *layer)>
  -
  -The default IO layer destructor. Frees the memory associated with
  -C<*layer>.
  -
  -=cut
  -
  -*/
  -
  -void
  -PIO_base_delete_layer(ParrotIOLayer *layer)
  -{
  -    if (layer != NULL)
  -        mem_sys_free(layer);
  -}
  -
  -/*
  -
  -=item C<INTVAL
  -PIO_push_layer(theINTERP, ParrotIOLayer *layer, PMC *pmc)>
  -
  -Push a layer onto an IO object (C<*pmc>) or the default stack.
  -
  -=cut
  -
  -*/
  -
  -INTVAL
  -PIO_push_layer(theINTERP, ParrotIOLayer *layer, PMC *pmc)
  -{
  -    ParrotIOLayer *t;
  -
  -    if (layer == NULL)
  -        return -1;
  -    if (!PMC_IS_NULL(pmc)) {
  -        ParrotIO *io = PMC_data(pmc);
  -        if (!io)
  -            return -1;
  -        if (io->stack == NULL && (layer->flags & PIO_L_TERMINAL) == 0) {
  -            /* Error( 1st layer must be terminal) */
  -            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.
  -         * -Melvin
  -         */
  -        for (t = io->stack; t; t = t->down) {
  -            if (t == layer)
  -                return -1;
  -        }
  -
  -        layer->down = io->stack;
  -        if (io->stack)
  -            io->stack->up = layer;
  -        io->stack = layer;
  -        if (layer->api->Pushed)
  -            (*layer->api->Pushed) (layer, io);
  -    }
  -    else {
  -        ParrotIOData *d = interpreter->piodata;
  -        if (d->default_stack == NULL && (layer->flags & PIO_L_TERMINAL) == 0) {
  -            /* Error( 1st layer must be terminal) */
  -            return -1;
  -        }
  -        /* Sanity check */
  -        for (t = d->default_stack; t; t = t->down) {
  -            if (t == layer)
  -                return -1;
  -        }
  -
  -        layer->down = d->default_stack;
  -        if (d->default_stack)
  -            d->default_stack->up = layer;
  -        d->default_stack = layer;
  -        return 0;
  -    }
  -    return -1;
  -}
  -
  -/*
  -
  -=item C<ParrotIOLayer *
  -PIO_pop_layer(theINTERP, PMC *pmc)>
  -
  -Pop a layer from an IO object (C<*pmc>) or the default stack.
  -
  -=cut
  -
  -*/
  -
  -ParrotIOLayer *
  -PIO_pop_layer(theINTERP, PMC *pmc)
  -{
  -    ParrotIOLayer *layer;
  -    ParrotIO *io = PMC_data(pmc);
  -
  -    if (!PMC_IS_NULL(pmc)) {
  -        if (!io)
  -            return 0;
  -        layer = io->stack;
  -        if (layer) {
  -            io->stack = layer->down;
  -            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 *d;
  -        d = interpreter->piodata;
  -        layer = d->default_stack;
  -        if (layer) {
  -            d->default_stack = layer->down;
  -            d->default_stack->up = NULL;
  -            layer->up = 0;
  -            layer->down = 0;
  -            return layer;
  -        }
  -    }
  -
  -    return 0;
  -}
  -
  -/*
  -
  -=item C<ParrotIOLayer *
  -PIO_copy_stack(ParrotIOLayer *stack)>
  -
  -Primarily used to copy the default IO stack for a new IO object. Later
  -we will do some funky copy-on-write stuff.
  -
  -=cut
  -
  -*/
  -
  -ParrotIOLayer *
  -PIO_copy_stack(ParrotIOLayer *stack)
  -{
  -    ParrotIOLayer *ptr_new;
  -    ParrotIOLayer **ptr_ptr_new;
  -    ParrotIOLayer *ptr_proto;
  -    ParrotIOLayer *ptr_last = NULL;
  -    ptr_ptr_new = &ptr_new;
  -    ptr_proto = stack;
  -    while (ptr_proto) {
  -        *ptr_ptr_new = PIO_base_new_layer(ptr_proto);
  -        (*ptr_ptr_new)->up = ptr_last;
  -        ptr_proto = ptr_proto->down;
  -        ptr_last = *ptr_ptr_new;
  -        ptr_ptr_new = &((*ptr_ptr_new)->down);
  -    }
  -
  -    return ptr_new;
  -}
   
   /*
   
  
  
  
  1.1                  parrot/io/io_layers.c
  
  Index: io_layers.c
  ===================================================================
  /*
  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  $Id: io_layers.c,v 1.1 2004/05/19 13:22:51 leo Exp $
  
  =head1 NAME
  
  io/io_layers.c - IO Layer Handling
  
  =head1 DESCRIPTION
  
  The Parrot IO subsystem uses a per-interpreter stack to provide a
  layer-based approach to IO. Each layer implements a subset of the
  C<ParrotIOLayerAPI> vtable. To find an IO function the layer
  stack is searched downwards until a non-C<NULL> function pointer
  is found for that particular slot.
  
  */
  
  /*
  
  =head2 Layer and Stack Functions
  
  =over 4
  
  =item C<ParrotIOLayer *
  PIO_base_new_layer(ParrotIOLayer *proto)>
  
  The default IO layer constructor. Creates and returns a new
  C<ParrotIOLayer>. If a prototype C<*proto> is supplied then it's values
  will be copied to the new instance.
  
  =cut
  
  */
  
  #include "parrot/parrot.h"
  #include "io_private.h"
  
  ParrotIOLayer *
  PIO_base_new_layer(ParrotIOLayer *proto)
  {
      ParrotIOLayer *new_layer;
  
      new_layer = mem_sys_allocate(sizeof(ParrotIOLayer));
      if (proto) {
          /* FIXME: Flag here to indicate whether to free strings */
          new_layer->name = proto->name;
          new_layer->flags = proto->flags;
          new_layer->api = proto->api;
      }
      else {
          new_layer->name = NULL;
          new_layer->flags = 0;
          new_layer->api = NULL;
      }
      new_layer->self = 0;
      new_layer->up = NULL;
      new_layer->down = NULL;
      return new_layer;
  }
  
  /*
  
  =item C<void
  PIO_base_delete_layer(ParrotIOLayer *layer)>
  
  The default IO layer destructor. Frees the memory associated with
  C<*layer>.
  
  =cut
  
  */
  
  void
  PIO_base_delete_layer(ParrotIOLayer *layer)
  {
      if (layer != NULL)
          mem_sys_free(layer);
  }
  
  /*
  
  =item C<INTVAL
  PIO_push_layer(theINTERP, ParrotIOLayer *layer, PMC *pmc)>
  
  Push a layer onto an IO object (C<*pmc>) or the default stack.
  
  =cut
  
  */
  
  INTVAL
  PIO_push_layer(theINTERP, ParrotIOLayer *layer, PMC *pmc)
  {
      ParrotIOLayer *t;
  
      if (layer == NULL)
          return -1;
      if (!PMC_IS_NULL(pmc)) {
          ParrotIO *io = PMC_data(pmc);
          if (!io)
              return -1;
          if (io->stack == NULL && (layer->flags & PIO_L_TERMINAL) == 0) {
              /* Error( 1st layer must be terminal) */
              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.
           * -Melvin
           */
          for (t = io->stack; t; t = t->down) {
              if (t == layer)
                  return -1;
          }
  
          layer->down = io->stack;
          if (io->stack)
              io->stack->up = layer;
          io->stack = layer;
          if (layer->api->Pushed)
              (*layer->api->Pushed) (layer, io);
      }
      else {
          ParrotIOData *d = interpreter->piodata;
          if (d->default_stack == NULL && (layer->flags & PIO_L_TERMINAL) == 0) {
              /* Error( 1st layer must be terminal) */
              return -1;
          }
          /* Sanity check */
          for (t = d->default_stack; t; t = t->down) {
              if (t == layer)
                  return -1;
          }
  
          layer->down = d->default_stack;
          if (d->default_stack)
              d->default_stack->up = layer;
          d->default_stack = layer;
          return 0;
      }
      return -1;
  }
  
  /*
  
  =item C<ParrotIOLayer *
  PIO_pop_layer(theINTERP, PMC *pmc)>
  
  Pop a layer from an IO object (C<*pmc>) or the default stack.
  
  =cut
  
  */
  
  ParrotIOLayer *
  PIO_pop_layer(theINTERP, PMC *pmc)
  {
      ParrotIOLayer *layer;
      ParrotIO *io = PMC_data(pmc);
  
      if (!PMC_IS_NULL(pmc)) {
          if (!io)
              return 0;
          layer = io->stack;
          if (layer) {
              io->stack = layer->down;
              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 *d;
          d = interpreter->piodata;
          layer = d->default_stack;
          if (layer) {
              d->default_stack = layer->down;
              d->default_stack->up = NULL;
              layer->up = 0;
              layer->down = 0;
              return layer;
          }
      }
  
      return 0;
  }
  
  /*
  
  =item C<ParrotIOLayer *
  PIO_copy_stack(ParrotIOLayer *stack)>
  
  Primarily used to copy the default IO stack for a new IO object. Later
  we will do some funky copy-on-write stuff.
  
  =cut
  
  */
  
  ParrotIOLayer *
  PIO_copy_stack(ParrotIOLayer *stack)
  {
      ParrotIOLayer *ptr_new;
      ParrotIOLayer **ptr_ptr_new;
      ParrotIOLayer *ptr_proto;
      ParrotIOLayer *ptr_last = NULL;
      ptr_ptr_new = &ptr_new;
      ptr_proto = stack;
      while (ptr_proto) {
          *ptr_ptr_new = PIO_base_new_layer(ptr_proto);
          (*ptr_ptr_new)->up = ptr_last;
          ptr_proto = ptr_proto->down;
          ptr_last = *ptr_ptr_new;
          ptr_ptr_new = &((*ptr_ptr_new)->down);
      }
  
      return ptr_new;
  }
  
  /*
  
  =back
  
  =cut
  
  */
  
  
  /*
   * Local variables:
   * c-indentation-style: bsd
   * c-basic-offset: 4
   * indent-tabs-mode: nil
   * End:
   *
   * vim: expandtab shiftwidth=4:
   */
  
  
  
  1.212     +4 -1      parrot/config/gen/makefiles/root.in
  
  Index: root.in
  ===================================================================
  RCS file: /cvs/public/parrot/config/gen/makefiles/root.in,v
  retrieving revision 1.211
  retrieving revision 1.212
  diff -u -w -r1.211 -r1.212
  --- root.in   19 May 2004 09:32:22 -0000      1.211
  +++ root.in   19 May 2004 13:22:55 -0000      1.212
  @@ -1,4 +1,4 @@
  -# $Id: root.in,v 1.211 2004/05/19 09:32:22 jrieks Exp $
  +# $Id: root.in,v 1.212 2004/05/19 13:22:55 leo Exp $
   
   ###############################################################################
   #
  @@ -226,6 +226,7 @@
   IO_O_FILES = \
       io/io$(O) \
       io/io_buf$(O) \
  +    io/io_layers$(O) \
       io/io_unix$(O) \
       io/io_win32$(O) \
       io/io_stdio$(O) \
  @@ -758,6 +759,8 @@
   io/io$(O) : $(GENERAL_H_FILES) io/io_private.h
   
   io/io_buf$(O) : $(GENERAL_H_FILES) io/io_private.h
  +
  +io/io_layers$(O) : $(GENERAL_H_FILES) io/io_private.h
   
   io/io_unix$(O) : $(GENERAL_H_FILES) io/io_private.h
   
  
  
  

Reply via email to