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
Opening references to glob copies #10607
Comments
From @cpansproutThis is a regression introduced in the past week by yours truly, with change 10cea94. $ perl5.13.4 -le '$a = *foo; open $fh, ">", \$a; print $fh, "b"; print $a' bleadperl behaves the same way a 5.8.x. It seems it was changed unintentionally in 5.10.0. In any case, the 5.10/12 behaviour is less surprising and more useful. Note that I am only talking about copies of globs here, that is, globs with the FAKE flag on. (That was why I said ‘real globs’ in the commit message for 10cea94, but I forgot regenerate the patch after updating my working copy.) Flags: Site configuration information for perl 5.13.4: Configured by sprout at Sun Aug 29 17:21:22 PDT 2010. Summary of my perl5 (revision 5 version 13 subversion 4 patch v5.13.4-30-g9b47cdd) configuration: Locally applied patches: @INC for perl 5.13.4: Environment for perl 5.13.4: |
From @cpansproutOn Sep 5, 2010, at 1:01 PM, Father Chrysostomos wrote:
Here is a patch to fix this. Note that this also affects \*$glob_copy, which is controversial, but at least I am only restoring the 5.10/12 behaviour in this case. (I think ideally that an explicit * should do a SvFAKE_off temporarily [effectively], but in this case the result has no practical application, so it’s not worth the time.) |
From @cpansproutFrom: Father Chrysostomos <sprout@cpan.org> [perl #77684] Restore the 5.10/12 behaviour of open $fh, ">", \$glob_copy This restores the perl 5.10/12 behaviour, making open treat \$foo as a Inline Patch--- blead-fh-segv2.base/perlio.c 2010-09-02 06:17:59.000000000 -0700
+++ blead-fh-segv2/perlio.c 2010-09-02 08:25:35.000000000 -0700
@@ -1449,7 +1449,7 @@ PerlIO_layer_from_ref(pTHX_ SV *sv)
/*
* For any scalar type load the handler which is bundled with perl
*/
- if (SvTYPE(sv) < SVt_PVAV && !isGV_with_GP(sv)) {
+ if (SvTYPE(sv) < SVt_PVAV && (!isGV_with_GP(sv) || SvFAKE(sv))) {
PerlIO_funcs *f = PerlIO_find_layer(aTHX_ STR_WITH_LEN("scalar"), 1);
/* This isn't supposed to happen, since PerlIO::scalar is core,
* but could happen anyway in smaller installs or with PAR */
diff -rup blead-fh-segv2.base/t/io/open.t blead-fh-segv2/t/io/open.t
--- blead-fh-segv2.base/t/io/open.t 2010-09-02 06:17:59.000000000 -0700
+++ blead-fh-segv2/t/io/open.t 2010-09-02 06:22:53.000000000 -0700
@@ -10,7 +10,7 @@ $| = 1;
use warnings;
use Config;
-plan tests => 110;
+plan tests => 111;
my $Perl = which_perl();
@@ -337,3 +337,13 @@ fresh_perl_is(
',
'ok', { stderr => 1 },
'[perl #77492]: open $fh, ">", \*glob causes SEGV');
+
+# [perl #77684] Opening a reference to a glob copy.
+{
+ my $var = *STDOUT;
+ open my $fh, ">", \$var;
+ print $fh "hello";
+ is $var, "hello", '[perl #77684]: open $fh, ">", \$glob_copy'
+ # when this fails, it leaves an extra file:
+ or unlink \*STDOUT;
+} |
From @rgarciaOn 5 September 2010 22:12, Father Chrysostomos <sprout@cpan.org> wrote:
Your patch does not work for me : t$ ./perl harness io/open.t Test Summary Report io/open.t (Wstat: 6 Tests: 110 Failed: 0) |
The RT System itself - Status changed from 'new' to 'open' |
From @cpansproutOn Sep 7, 2010, at 2:46 AM, Rafael Garcia-Suarez wrote:
I tried building with -DDEBUGGING, and I get the same assertion failure. If I remove the assertion from SvCUR, it just works. What::s happening is that PerlIO'scalar is doing SvCUR_set(s->var, 0) where s->var is the glob. By setting SvCUR, it::s actually wiping the GvFLAGS. But then the variable turns into a PV afterwards anyway, so it works by accident. This revised patch adds some sv_force_normals to ext/PerlIO_scalar/scalar.xs. |
From @cpansproutFrom: Father Chrysostomos <sprout@cpan.org> [perl #77684] Restore the 5.10/12 behaviour of open $fh, ">", \$glob_copy This restores the perl 5.10/12 behaviour, making open treat \$foo as a It also fixes an existing assertion failure that the test now trig- Inline Patch--- blead-fh-segv2.base/perlio.c 2010-09-02 06:17:59.000000000 -0700
+++ blead-fh-segv2/perlio.c 2010-09-02 08:25:35.000000000 -0700
@@ -1449,7 +1449,7 @@ PerlIO_layer_from_ref(pTHX_ SV *sv)
/*
* For any scalar type load the handler which is bundled with perl
*/
- if (SvTYPE(sv) < SVt_PVAV && !isGV_with_GP(sv)) {
+ if (SvTYPE(sv) < SVt_PVAV && (!isGV_with_GP(sv) || SvFAKE(sv))) {
PerlIO_funcs *f = PerlIO_find_layer(aTHX_ STR_WITH_LEN("scalar"), 1);
/* This isn't supposed to happen, since PerlIO::scalar is core,
* but could happen anyway in smaller installs or with PAR */
diff -rup blead-fh-segv2.base/t/io/open.t blead-fh-segv2/t/io/open.t
--- blead-fh-segv2.base/t/io/open.t 2010-09-02 06:17:59.000000000 -0700
+++ blead-fh-segv2/t/io/open.t 2010-09-02 06:22:53.000000000 -0700
@@ -10,7 +10,7 @@ $| = 1;
use warnings;
use Config;
-plan tests => 110;
+plan tests => 111;
my $Perl = which_perl();
@@ -337,3 +337,13 @@ fresh_perl_is(
',
'ok', { stderr => 1 },
'[perl #77492]: open $fh, ">", \*glob causes SEGV');
+
+# [perl #77684] Opening a reference to a glob copy.
+{
+ my $var = *STDOUT;
+ open my $fh, ">", \$var;
+ print $fh "hello";
+ is $var, "hello", '[perl #77684]: open $fh, ">", \$glob_copy'
+ # when this fails, it leaves an extra file:
+ or unlink \*STDOUT;
+}
diff -rup blead-fh-segv2.base/ext/PerlIO-scalar/scalar.xs blead-fh-segv2/ext/PerlIO-scalar/scalar.xs
--- blead-fh-segv2.base/ext/PerlIO-scalar/scalar.xs 2010-05-06 02:19:09.000000000 -0700
+++ blead-fh-segv2/ext/PerlIO-scalar/scalar.xs 2010-09-08 21:47:55.000000000 -0700
@@ -47,9 +47,15 @@ PerlIOScalar_pushed(pTHX_ PerlIO * f, co
SvUPGRADE(s->var, SVt_PV);
code = PerlIOBase_pushed(aTHX_ f, mode, Nullsv, tab);
if (!SvOK(s->var) || (PerlIOBase(f)->flags) & PERLIO_F_TRUNCATE)
+ {
+ sv_force_normal(s->var);
SvCUR_set(s->var, 0);
+ }
if ((PerlIOBase(f)->flags) & PERLIO_F_APPEND)
+ {
+ sv_force_normal(s->var);
s->posn = SvCUR(s->var);
+ }
else
s->posn = 0;
SvSETMAGIC(s->var);
@@ -166,6 +172,7 @@ PerlIOScalar_write(pTHX_ PerlIO * f, con
SV *sv = s->var;
char *dst;
SvGETMAGIC(sv);
+ sv_force_normal(sv);
if ((PerlIOBase(f)->flags) & PERLIO_F_APPEND) {
dst = SvGROW(sv, SvCUR(sv) + count);
offset = SvCUR(sv); |
From @rgarciaOn 12 September 2010 21:19, Father Chrysostomos <sprout@cpan.org> wrote:
Thanks, applied to bleadperl as change 526fd1b. |
@rgs - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#77684 (status was 'resolved')
Searchable as RT77684$
The text was updated successfully, but these errors were encountered: