syphilis has asked for the wisdom of the Perl Monks concerning the following question:
So ... sub get_string_1 works fine and passes the string to the temporary file associated with the filehandle, from which I successfully retrieve what was written.use warnings; use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; void to_FH(FILE * stream) { fprintf(stream, "hello"); fflush(stream); } EOC my ($got1, $got2); $got1 = get_string_1(); chomp($got1); # just in case ... print "OK 1\n" if $got1 eq "hello"; $got2 = get_string_2(); chomp($got2); # just in case ... print "OK 2\n" if $got2 eq "hello"; sub get_string_1 { # Write to a temporary file open TEMPFILE, '+>', undef or die $!; to_FH(*TEMPFILE); seek TEMPFILE, 0, 0; my $ret = <TEMPFILE>; close TEMPFILE; return $ret; } sub get_string_2 { # Write to a memory file my $out; open MEM, '+>', \$out or die $!; to_FH(*MEM); #close MEM; # Makes no difference return $out; # returns undef ... why ? } __END__ For me, outputs: OK 1 Use of uninitialized value $got2 in scalar chomp at try.pl line 24. Use of uninitialized value $got2 in string eq at try.pl line 25.
But this made no discernible difference to the behaviour.void to_FH(PerlIO * stream) { FILE * stdio_stream = PerlIO_exportFILE(stream, NULL); fprintf(stdio_stream, "hello"); fflush(stdio_stream); PerlIO_releaseFILE(stream, stdio_stream); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XSub won't write to memory file
by Anonymous Monk on Jul 06, 2015 at 08:49 UTC | |
|
Re: XSub won't write to memory file
by Hansen (Friar) on Jul 09, 2015 at 13:57 UTC | |
by syphilis (Archbishop) on Jul 10, 2015 at 11:20 UTC | |
|
Re: XSub won't write to memory file
by Anonymous Monk on Jul 08, 2015 at 21:50 UTC | |
by syphilis (Archbishop) on Jul 09, 2015 at 12:38 UTC | |
by Anonymous Monk on Jul 09, 2015 at 20:52 UTC | |
by Anonymous Monk on Jul 09, 2015 at 00:08 UTC |