Greets,
I need to open a filehandle in Perl, store the handle in a hash-based
object, then call an object method written in XS which will write
something to the filehandle. This seems to be the solution:
/* Extract the object hash and the output filehandle. */
SV* obj_sv = ST(0);
HV* obj_hash = (HV*)SvRV(obj_sv);
SV* out_fh_ref = *(hv_fetch(obj_hash, "fh", 2, 0));
PerlIO* fh = IoOFP( sv_2io(out_fh_ref) );
The problem is: I can't find any documentation for IoOFP or its
complement IoIFP, so I'm not sure it's safe to use.
This year-and-a-half-old post from Nick Ing-Simmons seems to imply
that it is available (though he doesn't mention it by name):
http://www.mail-archive.com/perl-xs@perl.org/msg01077.html
"First step is to get the IO * Perl_sv2io() does that.
Next you get your PerlIO * - you have a choice of two
the one for output and the one for input (often same
but not for sockets or (some) ttys)."
Is there some other way to achieve my goal, or is my present solution
sufficient?
PS. An earlier version of this was originally posted on PerlMonks.
Once this is resolved, I'll update that node.
Marvin Humphrey
Rectangular Research
http://www.rectangular.com/