New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use and require are affected by the open pragma #11541
Comments
From @LeontThis is a bug report for perl from fawaka@gmail.com, use and require are affected by the open pragma, as seen here: % perl -e 'print "package F;\n # \xF1\n;1;"' > x.pl Flags: Site configuration information for perl 5.14.1: Configured by leon at Tue Jun 28 15:59:52 CEST 2011. Summary of my perl5 (revision 5 version 14 subversion 1) configuration: Platform: Locally applied patches: @INC for perl 5.14.1: Environment for perl 5.14.1: |
From @iabynOn Sun, Jul 31, 2011 at 02:05:23PM -0700, Leon Timmermans wrote:
Well, the pragma's docs says that it affects "all I/O" within the lexical -- |
The RT System itself - Status changed from 'new' to 'open' |
From @LeontOn Mon Aug 01 02:27:45 2011, davem wrote:
I really don't think loading a module is can be reasonably called «I/O Leon |
From @nwc10On Mon, Aug 01, 2011 at 10:27:12AM +0100, Dave Mitchell wrote:
$ cat >y.pl No warning. perlfunc.pod says: Otherwise, C<require> demands that a library file be included if it and makes no comment about lexical pragmata. The y.pl example above shows So it looks like the current behaviour is "as if" [and probably actually All things above being equal, I'm not sure if I think that this is a bug. require only loads a file once. Hence if you have two modules which require use open ":encoding(utf8)" and the other is no open; then what you actually get in %foo:: is going to depend on the order that Which is action at a distance. And feels horribly like it will cause much And caustic blog posts are bad marketing, even if we are so callous as to Or at least, that's how somewhat sleep-deprived me sees it. Nicholas Clark |
From @LeontOn Mon Aug 01 07:36:28 2011, nicholas wrote:
That's exactly what happens (see pp_require and check_type_and_open in
Yeah, that is another complication of this. The open pragma seems to be Leon |
From @HugmeirOn Mon, Aug 1, 2011 at 11:36 AM, Nicholas Clark <nick@ccl4.org> wrote:
Well, assuming this is considered a bug, here's a patch to resolve it : ) It Inline Patchdiff --git a/lib/open.t b/lib/open.t
index 1bf7dca..1d61086 100644
--- a/lib/open.t
+++ b/lib/open.t
@@ -186,18 +186,39 @@ SKIP: {
eval q[use Encode::Alias;use open ":std", ":locale"];
is($@, '', 'can use :std and :locale');
- use open IN => ':non-existent';
- eval {
- require Symbol; # Anything that exists but we havn't loaded
- };
- like($@, qr/Can't locate Symbol|Recursive call/i,
- "test for an endless loop in PerlIO_find_layer");
+#This test was using dubious behaviour - It relied on the open pragma to
END { # the test cases beyond __DATA__ need to be executed separately Inline Patchdiff --git a/pp_ctl.c b/pp_ctl.c
index d5924d8..7d5e58a 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3649,7 +3649,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,
|
From @Hugmeiropen_noprop.diffdiff --git a/lib/open.t b/lib/open.t
index 1bf7dca..1d61086 100644
--- a/lib/open.t
+++ b/lib/open.t
@@ -186,18 +186,39 @@ SKIP: {
eval q[use Encode::Alias;use open ":std", ":locale"];
is($@, '', 'can use :std and :locale');
- use open IN => ':non-existent';
- eval {
- require Symbol; # Anything that exists but we havn't loaded
- };
- like($@, qr/Can't locate Symbol|Recursive call/i,
- "test for an endless loop in PerlIO_find_layer");
+#This test was using dubious behaviour - It relied on the open pragma to propagate
+#it's effect into the layer used for require, which is no longer true.
+#See the next test as for why this was changed.
+
+# use open IN => ':non-existent';
+# eval {
+# require Symbol; # Anything that exists but we havn't loaded
+# };
+# like($@, qr/Can't locate Symbol|Recursive call/i,
+# "test for an endless loop in PerlIO_find_layer");
+
+
+ open my $out_fh, ">:raw", "x.pl";
+ print { $out_fh } "package F;\n # \xF1\n;1;";
+ close $out_fh;
+
+#This require would've thrown "utf8 "\xF1" does not map to Unicode" if require
+#was affected by open.
+ {
+ use open qw( :encoding(utf8) );
+ eval {
+ local @INC = ".";
+ require "x.pl";
+ };
+ is $@, '', "open does not propagate into require()";
+ }
}
END {
1 while unlink "utf8";
1 while unlink "a";
1 while unlink "b";
+ 1 while unlink "x.pl";
}
# the test cases beyond __DATA__ need to be executed separately
diff --git a/pp_ctl.c b/pp_ctl.c
index d5924d8..7d5e58a 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3649,7 +3649,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_ ":raw", PERL_SCRIPT_MODE, -1, 0, 0, NULL, 1, &name);
#else
return PerlIO_open(p, PERL_SCRIPT_MODE);
#endif
|
From tchrist@perl.comJust because you call a function that does I/O doesn't mean do provides a separate lexical scope. A different question is $foo = `cat $file`. --tom |
From @LeontOn Mon, Aug 1, 2011 at 9:29 PM, Brian Fraser <fraserbn@gmail.com> wrote:
Perl modules/scripts are text files, not binary files. I don't think Leon |
From @nwc10On Mon, Aug 01, 2011 at 04:29:40PM -0300, Brian Fraser wrote:
Except I *think* that the call:
now opens the file then pushes "raw", and pushing "raw" does binmode() on the I'm not sure how to call PerlIO in such a way as to override the open pragma, PerlIO is not my favourite part of the core Perl source code, and hasn't been Nicholas Clark |
From @LeontOn Tue Aug 02 02:55:21 2011, nicholas wrote:
I think we should add a :default pseudo-layer. It should be fairly
It's nobody's favorite part of the core, which is its main problem. Leon |
From @cpansproutOn Tue Aug 02 02:55:21 2011, nicholas wrote:
How about temporarily clearing the hints (after using a SAVE* macro)?
|
From @cpansproutOn Tue Aug 02 06:21:58 2011, sprout wrote:
Or pushing the new scope before opening the file?
|
From @janduboisOn Tue, 02 Aug 2011, Leon Timmermans wrote:
No, it won't. It will switch the DATA filehandle to :raw mode as well, Perl actually used to read the source in :raw mode on Windows, but https://rt-archive.perl.org/perl5/Public/Bug/Display.html?id=28106 For Perl 5.14 I changed the default to reading source code in text mode, Cheers, |
From @HugmeirOn Tue, Aug 2, 2011 at 3:36 PM, Jan Dubois <jand@activestate.com> wrote:
Alright, then I think that Father C's suggestion is our winner here. Unfortunately I can't get SAVEHINTS(); to play nice (my ignorance of PerlIO |
From @LeontOn Tue, Aug 2, 2011 at 2:47 PM, Leon Timmermans via RT
Attached the patch. It turned out to be quite simple. Leon |
From @Leontdefault-perlio.patchdiff --git a/perlio.c b/perlio.c
index 72a71fe..c8d7141 100644
--- a/perlio.c
+++ b/perlio.c
@@ -837,6 +837,9 @@ PerlIO_get_layers(pTHX_ PerlIO *f)
* XS Interface for perl code
*/
+#define PerlIO_default_top() PerlIO_default_layer(aTHX_ -1)
+#define PerlIO_default_btm() PerlIO_default_layer(aTHX_ 0)
+
PerlIO_funcs *
PerlIO_find_layer(pTHX_ const char *name, STRLEN len, int load)
{
@@ -844,6 +847,8 @@ PerlIO_find_layer(pTHX_ const char *name, STRLEN len, int load)
IV i;
if ((SSize_t) len <= 0)
len = strlen(name);
+ if (len == 7 && strEQ(name, "default"))
+ return PerlIO_default_top();
for (i = 0; i < PL_known_layers->cur; i++) {
PerlIO_funcs * const f = PL_known_layers->array[i].funcs;
if (memEQ(f->name, name, len) && f->name[len] == 0) {
@@ -1246,9 +1251,6 @@ PerlIO_default_layer(pTHX_ I32 n)
return PerlIO_layer_fetch(aTHX_ av, n, PERLIO_FUNCS_CAST(&PerlIO_stdio));
}
-#define PerlIO_default_top() PerlIO_default_layer(aTHX_ -1)
-#define PerlIO_default_btm() PerlIO_default_layer(aTHX_ 0)
-
void
PerlIO_stdstreams(pTHX)
{
|
From @HugmeirOn Sun, Aug 7, 2011 at 6:42 PM, Leon Timmermans <fawaka@gmail.com> wrote:
With 5.15.2 out of the door, can this get committed? |
From @cpansproutOn Sat Aug 20 21:37:43 2011, fraserbn@gmail.com wrote:
If this adds a new pseudo-layer accessible from Perl space, then it |
From @HugmeirOn Sun, Aug 21, 2011 at 3:37 AM, Father Chrysostomos via RT <
Would something like this do? Inline Patchdiff --git a/lib/PerlIO.pm b/lib/PerlIO.pm
index 46e6e44..2c36d72 100644
--- a/lib/PerlIO.pm
+++ b/lib/PerlIO.pm
@@ -190,6 +190,15 @@ On Win32 platforms this I<experimental> layer uses the
+=item :default =head2 Custom Layers |
From @LeontOn Sun, Aug 21, 2011 at 8:37 AM, Father Chrysostomos via RT
At least as important, it needs tests. I wrote some, but I bumped into I think it'd be better to fix that first before applying this. Leon |
From @cpansproutOn Thu Aug 04 01:11:45 2011, fraserbn@gmail.com wrote:
Except it can’t work properly, because SAVEHINTS and PL_hints deal with PL_curcop->cop_hints can’t be modified, because that won’t be thread-safe.
|
From @HugmeirOn Mon, Aug 22, 2011 at 6:34 PM, Father Chrysostomos via RT <
Bit of a surprising discovery; Turns out that passing a single ":" for the That will only get the relevant default layers, while removing the colons Inline Patchdiff --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) (tests in a previous mail) Is this worth documenting somewhere? |
From @rgarciaOn 22 September 2011 16:29, Brian Fraser <fraserbn@gmail.com> wrote:
I vote yes, because I find this accidental feature actually neat. And |
From tchrist@perl.comRafael Garcia-Suarez <rgs@consttype.org> wrote
My instinct says that you're right. It is always cool to find new uses I *REALLY* wish I understood layers better. I can do simple stuff, thanks, --tom |
From @rgarciaOn 22 September 2011 17:09, Tom Christiansen <tchrist@perl.com> wrote:
There's the scary low-level docs in perliol. |
From @cpansproutOn Thu Sep 22 07:30:00 2011, fraserbn@gmail.com wrote:
Thank you. Applied as 639dfab.
I didn’t read that sentence until I had already written one. It turns |
From @cpansproutOn Thu Sep 22 07:30:00 2011, fraserbn@gmail.com wrote:
Yes, and I have documented it with commit c0fd9d2. |
@cpansprout - Status changed from 'open' to 'resolved' |
From @LeontOn Thu, Sep 22, 2011 at 5:09 PM, Tom Christiansen <tchrist@perl.com> wrote:
Barely. perliol defines some internals but that's not useful for Most of it is reading the source and trying things out. That's also Leon |
Migrated from rt.perl.org#96008 (status was 'resolved')
Searchable as RT96008$
The text was updated successfully, but these errors were encountered: