develooper Front page | perl.perl5.porters | Postings from March 2017

Re: [perl #128365] IO layer for STDERR not set

Thread Next
From:
Zefram
Date:
March 27, 2017 03:59
Subject:
Re: [perl #128365] IO layer for STDERR not set
Message ID:
20170327035837.GK6453@fysh.org
E. Choroba wrote:
>When reopening STDERR, its encoding layer doesn't change.

This actually happens when, and only when, reopening a file handle that
currently has a fd in the std{in,out,err} range.  It happens regardless
of which of those fds it is, and regardless of how the reopened handle
was originally opened.  The code responsible is trying to preserve the
special fd across a reopen, which is behaviour that we want to keep.
It's certainly a bug that we don't honour the layer specification when
doing this.  The code is in S_openn_cleanup() in doio.c, which has this
alarming comment:

    /* Eeek - FIXME !!!
     * If this is a standard handle we discard all the layer stuff
     * and just dup the fd into whatever was on the handle before !
     */

The issue is that the new handle configuration is initially opened on a
new fd and has to move to the special fd number, but (I think) we don't
have any API to change the fd number in an existing handle configuration.
The code is taking the easy, but wrong, approach of reusing the old
handle configuration, which of course already has the right fd number.

-zefram

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About