Sisyphus
2006-04-04 01:46:49 UTC
Hi,
I guess the succinct way of asking the question is "how do I convert from a
FILE* to a PerlIO* ?".
By way of elaboration, consider the following Inline::C script (which works
fine and as expected):
---------------------
use warnings;
use Inline C => Config =>
BUILD_NOISY => 1;
use Inline C => <<'EOC';
void c_write(FILE * handle) {
fprintf(handle, "hello world\n");
}
EOC
open($wr, '>', 'hello.txt') or die "Opening \$wr: $!";
c_write($wr);
close $wr or die "Closing \$wr: $!";
__END__
-------------------
Suppose now that instead of having the c_write() function write to the
filehandle using fprintf(), I wish it to write using PerlIO_printf(). What
hoops does the c_write() function then have to jump through ?
I'm not sure exactly why I'm asking this question .... I think I'm hoping to
learn something, but I'm not exactly sure what ..... if I learn anything at
all, then I guess that's progress :-)
One thing that puzzles me is that 'perldoc perlclib' recommends using the
PerlIO* types instead of the FILE* types. If that's the recommendation, then
it seems anomalous that perl facilitates the passing of a FILE* from perl to
XS, but not the passing of a PerlIO* from perl to XS. (At least that's the
way it appears to me at the moment.)
Cheers,
Rob
I guess the succinct way of asking the question is "how do I convert from a
FILE* to a PerlIO* ?".
By way of elaboration, consider the following Inline::C script (which works
fine and as expected):
---------------------
use warnings;
use Inline C => Config =>
BUILD_NOISY => 1;
use Inline C => <<'EOC';
void c_write(FILE * handle) {
fprintf(handle, "hello world\n");
}
EOC
open($wr, '>', 'hello.txt') or die "Opening \$wr: $!";
c_write($wr);
close $wr or die "Closing \$wr: $!";
__END__
-------------------
Suppose now that instead of having the c_write() function write to the
filehandle using fprintf(), I wish it to write using PerlIO_printf(). What
hoops does the c_write() function then have to jump through ?
I'm not sure exactly why I'm asking this question .... I think I'm hoping to
learn something, but I'm not exactly sure what ..... if I learn anything at
all, then I guess that's progress :-)
One thing that puzzles me is that 'perldoc perlclib' recommends using the
PerlIO* types instead of the FILE* types. If that's the recommendation, then
it seems anomalous that perl facilitates the passing of a FILE* from perl to
XS, but not the passing of a PerlIO* from perl to XS. (At least that's the
way it appears to me at the moment.)
Cheers,
Rob