From: Jarkko Hietaniemi Date: Fri, 30 Nov 2001 04:49:56 +0000 (+0000) Subject: Paragraph rewrapping. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1d11c889c9f2aa4165f7828fe119dbbd463be4b9;p=p5sagit%2Fp5-mst-13.2.git Paragraph rewrapping. p4raw-id: //depot/perl@13380 --- diff --git a/pod/perliol.pod b/pod/perliol.pod index 5a2438e..4ef52d7 100644 --- a/pod/perliol.pod +++ b/pod/perliol.pod @@ -34,9 +34,9 @@ believe) from the use of the term in "sfio", which in turn borrowed it from "line disciplines" on Unix terminals. However, this document (and the C code) uses the term "layer". -This is, I hope, a natural term given the implementation, and should avoid -connotations that are inherent in earlier uses of "discipline" for things -which are rather different. +This is, I hope, a natural term given the implementation, and should +avoid connotations that are inherent in earlier uses of "discipline" +for things which are rather different. =head2 Data Structures @@ -53,13 +53,14 @@ The basic data structure is a PerlIOl: IV flags; /* Various flags for state */ }; -A C is a pointer to the struct, and the I level -C is a pointer to a C - i.e. a pointer to a pointer to -the struct. This allows the application level C to remain -constant while the actual C underneath changes. (Compare perl's -C which remains constant while its C field changes as the -scalar's type changes.) An IO stream is then in general represented as a -pointer to this linked-list of "layers". +A C is a pointer to the struct, and the I +level C is a pointer to a C - i.e. a pointer +to a pointer to the struct. This allows the application level C +to remain constant while the actual C underneath +changes. (Compare perl's C which remains constant while its +C field changes as the scalar's type changes.) An IO stream is +then in general represented as a pointer to this linked-list of +"layers". It should be noted that because of the double indirection in a C, a C<< &(perlio-Enext) >> "is" a C, and so to some degree @@ -150,17 +151,18 @@ Functions to support Perl's traditional "fast" access to the buffer. =back -A layer does not have to implement all the functions, but the whole table has -to be present. Unimplemented slots can be NULL (which will result in an error -when called) or can be filled in with stubs to "inherit" behaviour from -a "base class". This "inheritance" is fixed for all instances of the layer, -but as the layer chooses which stubs to populate the table, limited -"multiple inheritance" is possible. +A layer does not have to implement all the functions, but the whole +table has to be present. Unimplemented slots can be NULL (which will +result in an error when called) or can be filled in with stubs to +"inherit" behaviour from a "base class". This "inheritance" is fixed +for all instances of the layer, but as the layer chooses which stubs +to populate the table, limited "multiple inheritance" is possible. =head2 Per-instance Data -The per-instance data are held in memory beyond the basic PerlIOl struct, -by making a PerlIOl the first member of the layer's struct thus: +The per-instance data are held in memory beyond the basic PerlIOl +struct, by making a PerlIOl the first member of the layer's struct +thus: typedef struct { @@ -173,8 +175,8 @@ by making a PerlIOl the first member of the layer's struct thus: IV oneword; /* Emergency buffer */ } PerlIOBuf; -In this way (as for perl's scalars) a pointer to a PerlIOBuf can be treated -as a pointer to a PerlIOl. +In this way (as for perl's scalars) a pointer to a PerlIOBuf can be +treated as a pointer to a PerlIOl. =head2 Layers in action. @@ -209,10 +211,10 @@ dynamically) with a "socket" layer. =item * -Different handles can have different buffering schemes. The "top" layer -could be the "mmap" layer if reading disk files was quicker using C -than C. An "unbuffered" stream can be implemented simply by -not having a buffer layer. +Different handles can have different buffering schemes. The "top" +layer could be the "mmap" layer if reading disk files was quicker +using C than C. An "unbuffered" stream can be implemented +simply by not having a buffer layer. =item * @@ -225,16 +227,17 @@ internal encoding (conceptually at least Unicode as UTF-8), and the =item * -A layer can be added that does "\n" to CRLF translation. This layer can be used -on any platform, not just those that normally do such things. +A layer can be added that does "\n" to CRLF translation. This layer +can be used on any platform, not just those that normally do such +things. =back =head2 Per-instance flag bits -The generic flag bits are a hybrid of C style flags deduced from -the mode string passed to C, and state bits for typical buffer -layers. +The generic flag bits are a hybrid of C style flags deduced +from the mode string passed to C, and state bits for +typical buffer layers. =over 4 @@ -324,30 +327,33 @@ to change during one "get".) =item IV (*Pushed)(PerlIO *f,const char *mode, SV *arg); -The only absolutely mandatory method. Called when the layer is pushed onto the stack. -The C argument may be NULL if this occurs post-open. The C will be non-C -if an argument string was passed. In most cases this should call -C to convert C into the appropriate -C flags in addition to any actions the layer itself takes. -If a layer is not expecting an argument it need neither save the one passed to it, nor -provide C (it could perhaps C that the argument was un-expected). +The only absolutely mandatory method. Called when the layer is pushed +onto the stack. The C argument may be NULL if this occurs +post-open. The C will be non-C if an argument string was +passed. In most cases this should call C to +convert C into the appropriate C flags in +addition to any actions the layer itself takes. If a layer is not +expecting an argument it need neither save the one passed to it, nor +provide C (it could perhaps C that the argument +was un-expected). =item IV (*Popped)(PerlIO *f); -Called when the layer is popped from the stack. A layer will normally be -popped after C is called. But a layer can be popped without being -closed if the program is dynamically managing layers on the stream. In -such cases C should free any resources (buffers, translation -tables, ...) not held directly in the layer's struct. -It should also C any unconsumed data that has been read and buffered -from the layer below back to that layer, so that it can be re-provided to what -ever is now above. +Called when the layer is popped from the stack. A layer will normally +be popped after C is called. But a layer can be popped +without being closed if the program is dynamically managing layers on +the stream. In such cases C should free any resources +(buffers, translation tables, ...) not held directly in the layer's +struct. It should also C any unconsumed data that has been +read and buffered from the layer below back to that layer, so that it +can be re-provided to what ever is now above. =item PerlIO * (*Open)(...); -The C method has lots of arguments because it combines the functions -of perl's C, C, perl's C, C and C. -The full prototype is as follows: +The C method has lots of arguments because it combines the +functions of perl's C, C, perl's C, +C and C. The full prototype is as +follows: PerlIO * (*Open)(pTHX_ PerlIO_funcs *tab, AV *layers, IV n, @@ -356,39 +362,45 @@ The full prototype is as follows: PerlIO *old, int narg, SV **args); -Open should (perhaps indirectly) call C to allocate a slot in the table and -associate it with the layers information for the opened file, by calling C. -The I AV is an array of all the layers destined for the C, -and any arguments passed to them, I is the index into that array of the -layer being called. The macro C will return a (possibly C) SV * -for the argument passed to the layer. - -The I string is an "C-like" string which would match the regular -expression C. - -The C<'I'> prefix is used during creation of C..C via special -C calls; the C<'#'> prefix means that this is C and that I and -I should be passed to C; C<'r'> means Bead, C<'w'> means Brite -and C<'a'> means Bppend. The C<'+'> suffix means that both reading and writing/appending -are permitted. The C<'b'> suffix means file should be binary, and C<'t'> means it -is text. (Binary/Text should be ignored by almost all layers and binary IO done, -with PerlIO. The C<:crlf> layer should be pushed to handle the distinction.) - -If I is not C then this is a C. Perl itself does not use -this (yet?) and semantics are a little vague. - -If I not negative then it is the numeric file descriptor I, which will -be open in a manner compatible with the supplied mode string, the call is -thus equivalent to C. In this case I will be zero. - -If I is greater than zero then it gives the number of arguments passed -to C, otherwise it will be 1 if for example C was called. -In simple cases SvPV_nolen(*args) is the pathname to open. - -Having said all that translation-only layers do not need to provide C at all, -but rather leave the opening to a lower level layer and wait to be "pushed". -If a layer does provide C it should normally call the C method -of next layer down (if any) and then push itself on top if that succeeds. +Open should (perhaps indirectly) call C to allocate +a slot in the table and associate it with the layers information for +the opened file, by calling C. The I AV is an +array of all the layers destined for the C, and any +arguments passed to them, I is the index into that array of the +layer being called. The macro C will return a (possibly +C) SV * for the argument passed to the layer. + +The I string is an "C-like" string which would match +the regular expression C. + +The C<'I'> prefix is used during creation of C..C via +special C calls; the C<'#'> prefix means that this is +C and that I and I should be passed to +C; C<'r'> means Bead, C<'w'> means Brite and +C<'a'> means Bppend. The C<'+'> suffix means that both reading and +writing/appending are permitted. The C<'b'> suffix means file should +be binary, and C<'t'> means it is text. (Binary/Text should be ignored +by almost all layers and binary IO done, with PerlIO. The C<:crlf> +layer should be pushed to handle the distinction.) + +If I is not C then this is a C. Perl itself +does not use this (yet?) and semantics are a little vague. + +If I not negative then it is the numeric file descriptor I, +which will be open in a manner compatible with the supplied mode +string, the call is thus equivalent to C. In this case +I will be zero. + +If I is greater than zero then it gives the number of arguments +passed to C, otherwise it will be 1 if for example +C was called. In simple cases SvPV_nolen(*args) is the +pathname to open. + +Having said all that translation-only layers do not need to provide +C at all, but rather leave the opening to a lower level layer +and wait to be "pushed". If a layer does provide C it should +normally call the C method of next layer down (if any) and +then push itself on top if that succeeds. =item SV * (*Getarg)(PerlIO *f); @@ -422,8 +434,8 @@ Basic write operation. Returns bytes written or -1 on an error. =item IV (*Seek)(PerlIO *f, Off_t offset, int whence); -Position the file pointer. Should normally call its own C method and -then the C method of next layer down. +Position the file pointer. Should normally call its own C +method and then the C method of next layer down. =item Off_t (*Tell)(PerlIO *f); @@ -508,13 +520,13 @@ between O_TEXT and O_BINARY this layer is always O_BINARY. A very complete generic buffering layer which provides the whole of PerlIO API. It is also intended to be used as a "base class" for other -layers. (For example its C method is implemented in terms of the -C/C/C methods). +layers. (For example its C method is implemented in terms of +the C/C/C methods). "perlio" over "unix" provides a complete replacement for stdio as seen via PerlIO API. This is the default for USE_PERLIO when system's stdio -does not permit perl's "fast gets" access, and which do not distinguish -between C and C. +does not permit perl's "fast gets" access, and which do not +distinguish between C and C. =item "stdio" @@ -545,9 +557,9 @@ minimalist "derived" layer. =item "pending" An "internal" derivative of "perlio" which can be used to provide -Unread() function for layers which have no buffer or cannot be bothered. -(Basically this layer's C pops itself off the stack and so resumes -reading from layer below.) +Unread() function for layers which have no buffer or cannot be +bothered. (Basically this layer's C pops itself off the stack +and so resumes reading from layer below.) =item "raw" @@ -558,8 +570,8 @@ layers until it reaches a layer with the class C bit set. =item "utf8" Another dummy layer. When pushed it pops itself and sets the -C flag on the layer which was (and now is once more) the top -of the stack. +C flag on the layer which was (and now is once more) +the top of the stack. =back @@ -569,16 +581,17 @@ which do not need to do anything special for a particular method. =head2 Extension Layers -Layers can made available by extension modules. When an unknown layer is encountered -the PerlIO code will perform the equivalent of : +Layers can made available by extension modules. When an unknown layer +is encountered the PerlIO code will perform the equivalent of : use PerlIO 'layer'; -Where I is the unknown layer. F will then attempt to : +Where I is the unknown layer. F will then attempt to: require PerlIO::layer; -If after that process the layer is still not defined then the C will fail. +If after that process the layer is still not defined then the C +will fail. The following extension layers are bundled with perl: @@ -588,8 +601,9 @@ The following extension layers are bundled with perl: use Encoding; -makes this layer available, although F "knows" where to find it. -It is an example of a layer which takes an argument as it is called thus: +makes this layer available, although F "knows" where to +find it. It is an example of a layer which takes an argument as it is +called thus: open($fh,"<:encoding(iso-8859-7)",$pathname) @@ -599,14 +613,15 @@ Provides support for open($fh,"...",\$scalar) -When a handle is so opened, then reads get bytes from the string value of I<$scalar>, -and writes change the value. In both cases the position in I<$scalar> starts as zero -but can be altered via C, and determined via C. +When a handle is so opened, then reads get bytes from the string value +of I<$scalar>, and writes change the value. In both cases the position +in I<$scalar> starts as zero but can be altered via C, and +determined via C. =item ":Object" or ":Perl" -May be provided to allow layers to be implemented as perl code - implementation -is being investigated. +May be provided to allow layers to be implemented as perl code - +implementation is being investigated. =back