Well, another alternative is to use plain old file descriptors
in your XS code and have your module wrap that code in a Perl
sub that converts to/from a file handle. Something like:
sub input {
my( $fh )= shift;
$fh= caller()."::".$fh
if ! ref($fh) && $fh !~ /[':]/;
my $fd= fileno($fh);
croak "Invalid file handle ($fh).\n"
if ! defined $fd;
input_xs( $fd );
}
sub output {
my $fd= output_xs();
my $fh= do { local(*FILE); \*FILE };
open $fh, "<&=$fd"
or die "Can't fdopen $fd: $!\n";
}
Otherwise your XS code is probably going to have to get
rather complex in order to detect and deal with all of
the different possible types of file handles:
strings (where you may need to prepend a package)
globs
refs to globs (includes objects)
Tye