in reply to Filter::Handle segfault in Perl 5.8+

I uncovered some more information on this problem. While the test code I originally posted didn't report anythingon the segfault, this code...

#!/usr/bin/perl -w use strict; use Filter::Handle qw/subs/; Filter \*STDOUT, sub { local $_ = "@_"; s/blue/red/g; $_ }; print "My house is blue.\n"; print "So is my cat, whose nose is blue.\n"; UnFilter \*STDOUT; print "And the plane is also blue.\n";

... gave me a "Deep recursion on subroutine "Filter::Handle::PRINT" at /Library/Perl/5.8.6/Filter/Handle.pm line 42." That gave me some clues, but what I thought was the solution isn't working.

Here is the subroutine with line 42 in it.

sub PRINT { my $self = shift; my $fh = *{ $self->{fh} }; print $fh, $self->{output}->(@_); }

The last line in #42. Immediately I thought perl is getting confused to which print to call and going into an infinite loop until a segfault happens. Thing is prepending CORE:: still ends in the same results.

sub PRINT { my $self = shift; my $fh = *{ $self->{fh} }; CORE::print $fh $self->{output}->(@_); }

I also added a "use subs" for print and printf to no avail.

use subs qw(print printf);

My experiments with Tie::Handle have return similar results so far.

What is happening here to confuse Perl that it goes into an infinite loop? Why is the use of CORE:: getting ignored or changed by this code?

Any ideas would be appreciated.

Replies are listed 'Best First'.
Re^2: Filter::Handle segfault in Perl 5.8+
by tima (Acolyte) on Oct 27, 2007 at 01:33 UTC
    OK I finally got my head out of my backside and figured it out -- at least for Perl 5.8. Here is the patch I'll be submitting to Ben:
    41,42c41,42 < my $fh = *{ $self->{fh} }; < print $fh $self->{output}->(@_); --- > open FH, ">&", \*{ $self->{fh} }; # dup to avoid potential STDOU +T recursion > print FH $self->{output}->(@_);