develooper Front page | perl.perl5.porters | Postings from December 2011

Re: [PATCH] Fix PerlIO::via's GETARG method

Thread Previous
Leon Timmermans
December 28, 2011 02:47
Re: [PATCH] Fix PerlIO::via's GETARG method
Message ID:
On Mon, Oct 17, 2011 at 1:22 AM, Brian Fraser <> wrote:
> First patch makes this:
> use PerlIO::via::QuotedPrint;
> sub PerlIO::via::QuotedPrint::GETARG { "QuotedPrint" }
> open my $fh, "<:via(QuotedPrint)", undef or die $!;
> print PerlIO::get_layers($fh);
> Stop throwing "Attempt to free" warnings by creating a fresh scalar; This is
> required because of this comment in perlio.c's PerlIO_get_layers:
> /* There is some collusion in the implementation of
> XS_PerlIO_get_layers - it knows that name and flags are
> generated as fresh SVs here, and takes advantage of that to
> "copy" them by taking a reference. If it changes here, it needs
> to change there too. */
> The second patch makes
> use PerlIO::via::QuotedPrint;
> open my $fh, "<:via(QuotedPrint)", undef or die $!;
> print PerlIO::get_layers($fh);
> Return "via(QuotedPrint)" instead of an argless "via"; It also stop an
> assertion from failing if those are enabled, as before it would return NULL
> instead of an SV.
> Is GETARG worth documenting? Using it before this patch was broken, and
> using it after is mostly superfluous. Seems like the kind of implementation
> detail to hide under the rug.
> Also, surprisingly (to me), redefining GETARG after an open does not affect
> the name returned by the already-existing filehandle:
> perl -MPerlIO::via::QuotedPrint -E ' *PerlIO::via::QuotedPrint::GETARG = sub
> { "Eeyup" }; open my $fh, "<:via(QuotedPrint)", undef or die $!; say
> PerlIO::get_layers($fh); *PerlIO::via::QuotedPrint::GETARG = sub { "Uunope"
> }; say PerlIO::get_layers($fh);'
> I'm guessing that's intended behavior?

GETARG is fucked, it suffers from the same bug as :encoding does (RT#31923).

perl -Mthreads -MPerlIO::via::QuotedPrint -E 'sub
PerlIO::via::QuotedPrint::GETARG { "QuotedPrint" } binmode STDOUT,
":via(QuotedPrint)"; threads->new( sub { say for
PerlIO::get_layers(*STDOUT); print "K=\n";})->join; say for
Segmentation fault

The Getarg method is used on only two occasions:
* PerlIO::get_layers
* PerlIO duplication (when cloning a new thread)

You're trying to fix the first, but it's the second that's most
problematic. You see, method calls give segfaults during PerlIO
duplication, but calling a method is the whole point of :via.
Actually, PUSHED has a similar problem, but we could solve that by
cloning handles in a smarter way that doesn't use PerlIO_push. There's
no such hope for GETARG.

And quite frankly, I don't see why anyone would want to change the
return value of GETARG/Getarg anyway. IMO PerlIO should take care of
that itself.


Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About