On Thu, Jun 5, 2008 at 7:53 AM, chromatic <[EMAIL PROTECTED]> wrote: > ... could be cleaner with the macro mem_allocate_n_typed.
Agree, corrected version attached. -- Salu2
Index: src/io/io_layers.c =================================================================== --- src/io/io_layers.c (revisión: 28099) +++ src/io/io_layers.c (copia de trabajo) @@ -177,11 +177,11 @@ PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL ParrotIOLayer * -PIO_get_layer(SHIM_INTERP, ARGIN(const char *name)) +PIO_get_layer(PARROT_INTERP, ARGIN(const char *name)) { ParrotIOLayer **t; - for (t = pio_registered_layers; *t; ++t) + for (t = interp->piolayers; *t; ++t) if (strcmp(name, (*t)->name) == 0) return *t; return NULL; Index: src/io/io_private.h =================================================================== --- src/io/io_private.h (revisión: 28099) +++ src/io/io_private.h (copia de trabajo) @@ -85,12 +85,6 @@ #define PIO_DEFAULTMODE DEFAULT_OPEN_MODE #define PIO_UNBOUND (size_t)-1 -/* This is list of valid layers */ -extern ParrotIOLayer **pio_registered_layers; - -/* This is the actual (default) layer stack which is used for IO */ -/* extern ParrotIOLayer *pio_default_stack; */ - typedef struct _ParrotIOBuf ParrotIOBuf; typedef PMC **ParrotIOTable; Index: src/io/io.c =================================================================== --- src/io/io.c (revisión: 28099) +++ src/io/io.c (copia de trabajo) @@ -36,15 +36,7 @@ /* HEADERIZER HFILE: include/parrot/io.h */ -/* This is list of valid layers */ -ParrotIOLayer **pio_registered_layers = NULL; - -/* This is the default stack used for IO. Copy this to each new interp */ /* -ParrotIOLayer * pio_default_stack; -*/ - -/* The standard streams are: interp->piodata->table[PIO_STD*_FILENO]. @@ -375,10 +367,11 @@ PARROT_API void -PIO_internal_shutdown(SHIM_INTERP) +PIO_internal_shutdown(PARROT_INTERP) { - mem_sys_free(pio_registered_layers); - pio_registered_layers = NULL; + PARROT_ASSERT(! interp->parent_interpreter); + mem_sys_free(interp->piolayers); + interp->piolayers = NULL; } /* @@ -415,11 +408,17 @@ PIO_push_layer(interp, PMCNULL, PIO_base_new_layer(&pio_buf_layer)); fill = 0; - if (!pio_registered_layers) { + if (!interp->piolayers) { n = 5; /* 2 default layers for now + utf8, mmap, string */ - pio_registered_layers = (ParrotIOLayer **)mem_sys_allocate( - sizeof (ParrotIOLayer *) * (n + 1)); - fill = 1; + if (interp->parent_interpreter) { + PARROT_ASSERT(interp->parent_interpreter->piolayers); + interp->piolayers = interp->parent_interpreter->piolayers; + } + else { + interp->piolayers = (ParrotIOLayer **)mem_allocate_n_typed( + n + 1, ParrotIOLayer *); + fill = 1; + } } /* Note: All layer pushes should be done before init calls */ @@ -427,8 +426,8 @@ bottom = p; if (fill) { PARROT_ASSERT(i < n); /* XXX n can be undefined at this point. */ - pio_registered_layers[i++] = p; - pio_registered_layers[i] = NULL; + interp->piolayers[i++] = p; + interp->piolayers[i] = NULL; } } /* @@ -451,11 +450,11 @@ } if (fill) { PARROT_ASSERT(i == 2); - PARROT_ASSERT(pio_registered_layers[2] == NULL); - pio_registered_layers[2] = PIO_utf8_register_layer(); - pio_registered_layers[3] = PIO_mmap_register_layer(); - pio_registered_layers[4] = PIO_string_register_layer(); - pio_registered_layers[5] = NULL; + PARROT_ASSERT(interp->piolayers[2] == NULL); + interp->piolayers[2] = PIO_utf8_register_layer(); + interp->piolayers[3] = PIO_mmap_register_layer(); + interp->piolayers[4] = PIO_string_register_layer(); + interp->piolayers[5] = NULL; } return 0; Index: include/parrot/io.h =================================================================== --- include/parrot/io.h (revisión: 28099) +++ include/parrot/io.h (copia de trabajo) @@ -264,7 +264,7 @@ __attribute__nonnull__(1); PARROT_API -void PIO_internal_shutdown(SHIM_INTERP); +void PIO_internal_shutdown(PARROT_INTERP); PARROT_API PARROT_WARN_UNUSED_RESULT Index: include/parrot/interpreter.h =================================================================== --- include/parrot/interpreter.h (revisión: 28099) +++ include/parrot/interpreter.h (copia de trabajo) @@ -309,6 +309,7 @@ int n_vtable_max; /* highest used type */ int n_vtable_alloced; /* alloced vtable space */ + struct _ParrotIOLayer **piolayers; /* IO registered layers */ struct _ParrotIOData *piodata; /* interpreter's IO system */ op_lib_t *op_lib; /* Opcode library */