Creating an old library with Perl XS and PerlIO

I rather start XS, and I am studying the modification of an existing XS module that makes heavy use of the 15-year-old C base library (in fact, the module is basically just glued to this library). The problem is that I would like to be able to use PerlIO string traversal, for example:

open($fh, '<', \$string); 

and then skip $fh to the XS glue, where the library expects FILE . The problem is that XS has:

 int _parse (entry_ref, filename, file, preserve=FALSE) SV * entry_ref; char * filename; FILE * file; boolean preserve; 

and I guess it should be:

 PerlIO * file; 

This does not work, of course, because there must be more to it. When I look at the _parse code in the library, it ends with:

 AST * bt_parse_entry (FILE * infile, char * filename, btshort options, boolean * status) { AST * entry_ast = NULL; static int * err_counts = NULL; static FILE * prev_file = NULL; 

with FILE again. Now the main question I have to start is even possible without changing the library; that is, can I get pseudo-filehandle from lines of PerlIO behavior just by changing XS?

+8
perl perl-io xs
source share
1 answer

The Perl API provides PerlIO_exportFILE() ( Implementation ), which can convert a PerlIO file descriptor to a stdio FILE pointer. Since PerlIO :: Scalar is an in-memory file descriptor without a file descriptor, conversion cannot be performed. The only portable way to pass the PerlIO::Scalar descriptor is to dump it into a temporary file. A less portable way would be to use stdio, which supports callbacks such as the BSD implementation, funopen (3) .

+3
source share

All Articles