> Steven N . Hirsch <[EMAIL PROTECTED]> writes: > >On Thu, 29 Nov 2001, Forrest Cahoon wrote: > > > >> Lack of documentation is driving me nuts! > >> > >> All the references I can find point me to perlapio for information about > >> dealing with Perl I/O inside of XS functions. That's nice ... now how do I > >> get one into or out of XS code? That I can't find anywhere. > > In theory (at least in perl5.7.*) the default typemap should have > an entry for PerlIO * > > So : > > PerlIO * > ThingThatReturnsOne(...) > > and > > ThingThatExpectsOne(PerlIO *f) > > should "just work" - what gets messy is that that
I'm using 5.6.1 (on Linux) and may have to run on 5.00503 (on VMS) as well: are these things that I can add to my local typemap? Or should I stay away from PerlIO and use the former interface (which I also have no clue about)? I had really hoped to use the latest and greatest, but I have to stick to what people are really using in production environments. > >> > >> If I create an IO::File object in perl and pass it into my XS function, can > >> I just cast the SV * into a PerlIO * and work with that? Is that what I'm > >> supposed to do? > > No. In general the SV will be a reference-to-a-glob. I thought IO::File was going to be the "new way" in Perl and we were going to do away with all those ugly \*FOO -style parameters. Is that not correct? Is IO::File just a blessed globref, or what? If I do want to pass an IO::File object to my XS function, do I need to do something different here? > You need to dereference > it and then use GvIO to get the IO - sv_2io() does that for you, > you then and then IoIFP() to get the PerlIO * - unless you want IoOFP of course. > - more indirections that one could possibly want :-( > > For INPUT > > $var = IoIFP(sv_2io($arg)) OK, I think I actually understand this (scary!). So does sv_2io() get a FILE * from my SV * that was passed into XS as a globref and IoIFP() turn that FILE * into a PerlIO * ? > >> > >> If I create a PerlIO * in my XS code, do I pass it back to perl as an SV *? > >> Is it blessed in some appropriate way? What would it be, IO::Handle? > > The default typemap creates a blessed reference to a new glob in the > XS's package and then uses a messy call to the internals to import the > PerlIO * This is the 5.7.x typemap, right? (I guess in earlier Perls I'm not gonna be using PerlIO *, or should I?) And what is the glob reference blessed to ... IO::Handle, as I guessed earlier? > >> > >> I also can't find any way to search the perl-xs archives ... I suspect this > >> has been covered many times already. Sorry about the probable repitition. I actually did find searchable archives at http://www.xray.mpe.mpg.de/mailing-lists/perl-xs/ but I still didn't find any useful discussion (for a clueless person like myself) of this topic. > >> I really appreciate any help I might receive. Yeah, I meant that. Thanks, Nick! Forrest Cahoon not speaking for merrill corporation
