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

Re: [perl #96008] use and require are affected by the open pragma

Thread Previous | Thread Next
From:
Brian Fraser
Date:
September 22, 2011 07:29
Subject:
Re: [perl #96008] use and require are affected by the open pragma
Message ID:
CA+nL+nZAyanO=p2NFybjq6dONfQvqMLdhJd0SMfQqRX_LWBPpQ@mail.gmail.com
On Mon, Aug 22, 2011 at 6:34 PM, Father Chrysostomos via RT <
perlbug-followup@perl.org> wrote:

> On Thu Aug 04 01:11:45 2011, fraserbn@gmail.com wrote:
> > On Tue, Aug 2, 2011 at 3:36 PM, Jan Dubois <jand@activestate.com> wrote:
> >
> > > On Tue, 02 Aug 2011, Leon Timmermans wrote:
> > > > Perl modules/scripts are text files, not binary files. I don't think
> > > > ":raw" really is the correct thing to do, though it may work out in
> > > > the end.
> > >
> > > No, it won't. It will switch the DATA filehandle to :raw mode as well,
> > > so you'll end up with "\r\n" line endings on Windows.
> > >
> > > Perl actually used to read the source in :raw mode on Windows, but
> > > (incompletely) turned on text mode when it reached the __DATA__ token.
> > > This created quite a number of bugs, all merged into this ticket:
> > >
> > > https://rt.perl.org/rt3/Public/Bug/Display.html?id=28106
> > >
> > > For Perl 5.14 I changed the default to reading source code in text
> mode,
> > > which fixed all those bugs. I'll soon remove the broken code that
> > > unsuccessfully tries to switch on text-mode mid-stream because it
> > > appears that nobody knows how to fix it (and it is unrelated to the
> open
> > > pragma anyways).
> > >
> > > Cheers,
> > > -Jan
> > >
> > >
> > >
> > Alright, then I think that Father C's suggestion is our winner here.
>
> Except it can’t work properly, because SAVEHINTS and PL_hints deal with
> *compile-time* hints, whereas PerlIO looks at the hints in the
> already-compiled op tree that is running (in PL_curcop, in other words).
>
> PL_curcop->cop_hints can’t be modified, because that won’t be thread-safe.
>
> >
> > Unfortunately I can't get SAVEHINTS(); to play nice (my ignorance of
> PerlIO
> > is only surpassed by my inexperience with scope.c), so I can't volunteer
> > myself for this one. But if it helps, from my hamhanded testing, all you
> > need to do is clear PL_curcop->cop_hints of HINT_LEXICAL_IO_(IN|OUT)
> before
> > calling PerlIO_openn.
>
>
>
>
Bit of a surprising discovery; Turns out that passing a single ":" for the
layers skips the fetch from the context layers:
perl -wE 'use open qw( :encoding(UTF-8) ); open my $fh, "<:", "etc"; say
PerlIO::get_layers($fh);'

That will only get the relevant default layers, while removing the colons
makes it work as usual -- So we can abuse this (mis)feature to fix the bug:

diff --git a/pp_ctl.c b/pp_ctl.c
index 3a2de27..a9c0afd 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3692,7 +3692,7 @@ S_check_type_and_open(pTHX_ SV *name)
}

#if !defined(PERLIO_IS_STDIO) && !defined(USE_SFIO)
- return PerlIO_openn(aTHX_ NULL, PERL_SCRIPT_MODE, -1, 0, 0, NULL, 1,
&name);
+ return PerlIO_openn(aTHX_ ":", PERL_SCRIPT_MODE, -1, 0, 0, NULL, 1,
&name);
#else
return PerlIO_open(p, PERL_SCRIPT_MODE);
#endif

(tests in a previous mail)

Is this worth documenting somewhere?

Thread Previous | 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