in reply to Filter ::Handle segfaults 5.8.1

Starting with perl5.8.0, there was an internal change to how tied filehandles are implemented. This may be the cause. Can you reduce it to a test case that doesn't involve Filter::Handle, but just a small class tied to STDOUT?

You can force a call to the real builtin instead of an overriding sub by saying CORE::print, but that will probably still recurse for you.

Replies are listed 'Best First'.
Re: Re: Filter ::Handle segfaults 5.8.1
by leriksen (Curate) on Nov 17, 2003 at 09:05 UTC
    It does indeed continue to recurse.

    the code I think is resposible is in two parts

    *print = *PRINT; *printf = *PRINTF; *new = *TIEHANDLE;

    those calls happen outside of any sub in the Filter::Handle package, so they cause usage of those symbols in F::H to resolve to those subs in the Filter::Handle package.

    sub PRINT { my $self = shift; my $fh = *{$self->{fh}}}; # the file handle we tied in TIEHANDLE print $fh $self->{output}->(@_); # the sub we passed in in TIEHANDLE }

    that print never used to call PRINT again.

    I'll try to reduce it to a simple case, but it will have to wait till I get gome - it is 8:30pm here.

      Never mind reducing it, the change I suspected is in fact the culprit. That *{$self->{fh}} wraps a new glob around the file handle to try to keep from recursing. This worked pre-5.8.0 when the tie magic was placed on the glob itself. As of 5.8.0, the tie magic attaches to just the handle portion of the glob, so the new wrapper glob is still using a tied handle, and the print recurses. (If you add a use warnings to Filter::Handle you will see a Deep recursion warning, just before it segfaults :)

      I think a workaround could be done by saving a dup'ed handle in Filter::Handle::TIEHANDLE. Out of time for now.