This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make PL_perlio an array of PerlIOl, not PerlIO *
authorDavid Mitchell <davem@iabyn.com>
Mon, 15 Nov 2010 17:06:37 +0000 (17:06 +0000)
committerDavid Mitchell <davem@iabyn.com>
Fri, 26 Nov 2010 16:01:33 +0000 (16:01 +0000)
commit303f2dc3d5bda8ee962db318dd53acb167c07485
tree68a6126a6960890a270e1323a393ae9e96984d1a
parent507a68aa3c321b422f95b772611c878ce13952df
make PL_perlio an array of PerlIOl, not PerlIO *

Layers in PerlIO are implemented as a linked list of PerlIOl structs;
eaxch one has a 'next' field pointing to the next layer. Now here's the
clever bit: When PerlIO* pointers are passed around to refer to a
particular handle, these are actually pointers to the 'next' field of the
*parent* layer (so to access the flags field say of a PerlIOl, you have to
double-defref it, e.g. (*f)->flags). The big advantage of this is that
it's easy for a layer to pop itself; when you call PerlIO_pop(f), f is a
pointer to the parent's 'next' field, so pop(f) can just do
*f = (*f)->next.

This means that there has to be a fake 'next' field above the topmost
layer. This is where PL_perlio comes in: it's a pointer to an arena of
arrays of pointers, each one capable of pointing to a PerlIOl structure.
When  a new handle is created, a spare arena slot is grabbed, and the
address of that slot is returned. This also allows for a handle with no
layers.

What this commit does is change PL_perlio from being an array of
PerlIO* into an array of PerlIOl structures - i.e. each element in the
array goes from being a single pointer, to having several fields. These
will be made used of in follow-up commits.
intrpvar.h
perlio.c
perliol.h