Skip to content
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

Bug in format/write #6624

Closed
p5pRT opened this issue Jul 14, 2003 · 17 comments
Closed

Bug in format/write #6624

p5pRT opened this issue Jul 14, 2003 · 17 comments

Comments

@p5pRT
Copy link

p5pRT commented Jul 14, 2003

Migrated from rt.perl.org#22977 (status was 'resolved')

Searchable as RT22977$

@p5pRT
Copy link
Author

p5pRT commented Jul 14, 2003

From schopper@usm.uni-muenchen.de

Hi there,

I belive, that we've found a bug in perl. We discovered it when changing from
perl-5.4.4 to perl-5.8.0, where we got strange results with
write in a program we heavily used without problems.

We found, that write no longer use the actual values of the variables
but get stuck with those during the first call to write. This behaviour depends
on wether the writing subroutine ist declared or not.

A sample program would be​:

  1 #!/usr/lib/perl5/neu/usr-bin/perl -w
  2
  3 use strict;
  4
  5 sub show_woche (); # Comment out to get right result!
  6
  7 sub show_woche ()
  8 { my $tag;
  9 my $eintrag;
10 my $datum;
11
12 my @​tag = (
13 [0 , [['a'], ['b']]],
14 [50000 , [['d'], ['e']]],
15 );
16
17 foreach $tag (@​tag)
18 { my $eintrag_liste = $tag->[1];
19 $datum = $tag->[0];
20 foreach $eintrag (@​{$eintrag_liste})
21 { my @​test = ($datum, $eintrag->[0]);
22 #printf "%-8s %-10s\n", @​test;
23 write;
24
25 format STDOUT =
26 @​<<<<<<< @​<<<<<<<<<<<<<<<<<<<<
27 @​test
28 .
29 }
30 }
31 }
32
33 show_woche;
34
35 exit 0;

This gives the wrong output​:
0 a
0 a
0 a
0 a

But when we comment out line 5 we get the right result​:
0 a
0 b
50000 d
50000 e

The old (correct) version of perl is​:

Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration​:
  Platform​:
  osname=linux, osvers=2.0.30, archname=i586-linux
  uname='linux lar 2.0.30 #1 mon jun 9 14​:40​:34 mesz 1997 i686 '
  hint=recommended, useposix=true, d_sigaction=define
  bincompat3=n useperlio=undef d_sfio=undef
  Compiler​:
  cc='gcc', optimize='-O2 -fomit-frame-pointer -pipe -m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2', gccversion=2.7.2.2.f.2
  cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
  ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
  stdchar='char', d_stdstdio=define, usevfork=false
  voidflags=15, castflags=0, d_casti32=define, d_castneg=define
  intsize=4, alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries​:
  ld='gcc', ldflags ='-L/usr/local/lib -s'
  libpth=/usr/local/lib /shlib /lib /usr/lib
  libs=-lgdbm -ldbm -ldb -ldl -lm -lc
  libc=/lib/libc.so.5.4.33, so=so
  useshrplib=true, libperl=libperl.so
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/i586-linux/5.00404/CORE'
  cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Characteristics of this binary (from libperl)​:
  Built under linux
  Compiled at Dec 4 1997 17​:44​:17
  @​INC​:
  /usr/lib/perl5/i586-linux/5.00404
  /usr/lib/perl5
  /usr/lib/perl5/site_perl/i586-linux
  /usr/lib/perl5/site_perl
  /usr/lib/perl5/i586-linux
  .

The new (buggy) Version is​:

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration​:
  Platform​:
  osname=linux, osvers=2.4.21-pre5, archname=i686-linux
  uname='linux lar 2.4.21-pre5 #1 smp thu feb 27 12​:10​:15 mez 2003 i686 '
  config_args=''
  hint=previous, useposix=true, d_sigaction=define
  usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
  useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
  use64bitint=undef use64bitall=undef uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-fomit-frame-pointer -mcpu=athlon-mp -falign-loops=1 -falign-jumps=1 -falign-functions=1 -mpreferred-stack-boundary=2',
  cppflags='-fno-strict-aliasing -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
  ccversion='', gccversion='3.2.2', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=4, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags ='-s'
  libpth=/usr/i686-pc-linux-gnulibc2/lib /usr/i686-pc-linux-gnulibc2/local/lib
  libs=-lnsl -ldl -lm -lc -lcrypt -lutil
  perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil
  libc=, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.3.2'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
  cccdlflags='-fpic', lddlflags='-shared'

Characteristics of this binary (from libperl)​:
  Compile-time options​: USE_LARGE_FILES
  Built under linux
  Compiled at Mar 25 2003 10​:46​:58
  @​INC​:
  /usr/lib/perl5/5.8.0/i686-linux
  /usr/lib/perl5/5.8.0
  /usr/lib/perl5/site_perl/5.8.0/i686-linux
  /usr/lib/perl5/site_perl/5.8.0
  /usr/lib/perl5/site_perl
  .

Thanks in advance for any help you can give.

With best regards

Rüdiger Schopper

GPG/PGP-Key​:
wwwkeys.pgp.net​:11371/pks/lookup?op=vindex&search=0x97A5CFE9&fingerprint=on
Fingerprint = B44F 7109 A40F B383 AA1B 778D 43B9 767C 97A5 CFE9

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ _/
_/ (`-'-,-. _. _/
_/ '._ (_ '.__.-, _/
_/ .-;`-.-`_..-' _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ `\___-.(_ _/ _/
_/ _.) a'-._ _/ Rüdiger Schopper _/
_/ __ .' `\ _/ schopper@​usm.uni-muenchen.de _/
_/ .' ` ._^/ _/ _/
_/ _..._.-' /`\ / _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ _.' \ / ) _/ _/
_/ (/ / ) |/ _/ The surest sign that intelli- _/
_/ | | / ;-. _/ gent life in universe exists _/
_/ ;\ /'-.__.| /-. \ _/ is that none of it has tried _/
_/ / ) / | | '.\ _/ to contact us ! _/
_/ / /| / \ | || _/ _/
_/ | / / / | | / | _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ || \ \ | | \_/ _/
_/ )_`\ )_`\ )_`\ _/
_/ `""` `""` `""` _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*** This message was entirely written with recycled electrons ***

@p5pRT
Copy link
Author

p5pRT commented Jul 14, 2003

From @iabyn

On Mon, Jul 14, 2003 at 05​:37​:42AM -0000, Ruediger Schopper wrote​:

I belive, that we've found a bug in perl. We discovered it when changing from
perl-5.4.4 to perl-5.8.0, where we got strange results with
write in a program we heavily used without problems.

The bug can be reduced to the simpler case​:

  sub f ($); # Comment out to get right result!
  sub f ($) {
  my $test = $_[0];
  write;
  format STDOUT =
  @​<<<<<<<
  $test
  .
  }
  f(1);
  f(2);

It's due to there being multiple CVs associated with f due to to the
forward declaration, and to newATTRSUB() copying the contents of the
second CV to the first. This causes any nested subs to have CvOUTSIDE
pointing to the wrong CV. A call to pad_fixup_inner_anons() fixes up any
nested anon subs, but nested formats aren't fixed up.

Since I'm currently working on trying to get sub declarations
to take effect at the start of a sub rather than at the end (eg
sub f($) { f(1) }), I'll see if I can work in a fix for this at the
same time.

--
"You're so sadly neglected, and often ignored.
A poor second to Belgium, When going abroad."
Monty Python - "Finland"

@p5pRT
Copy link
Author

p5pRT commented Jul 21, 2003

From schopper@usm.uni-muenchen.de

Hi Dave,

thanks for the extremely fast response. I would like to know if we might be
able to help you with the subroutine/format bug? We are clearly not deep
enough into the stuff to be able to effectively offer time, but perhaps we
might help with money. Do you think we can be of any help, or shall we just
wait until you come up with a bugfix?

Our problem is, that we have to upgrade perl eventually, so we are in principle
perfectly willing to contibute in order to get over that bug.

I don't want to annoy you, so just give us a short notice, if you like.

Best regards

Rüdiger

On Mon, Jul 14, 2003 at 05​:37​:42AM -0000, Ruediger Schopper wrote​:

I belive, that we've found a bug in perl. We discovered it when changing from
perl-5.4.4 to perl-5.8.0, where we got strange results with
write in a program we heavily used without problems.

The bug can be reduced to the simpler case​:

sub f \($\); \# Comment out to get right result\!
sub f \($\) \{
my $test = $\_\[0\];
write;
format STDOUT =
@&#8203;\<\<\<\<\<\<\<
$test
\.
\}
f\(1\);
f\(2\);

It's due to there being multiple CVs associated with f due to to the
forward declaration, and to newATTRSUB() copying the contents of the
second CV to the first. This causes any nested subs to have CvOUTSIDE
pointing to the wrong CV. A call to pad_fixup_inner_anons() fixes up any
nested anon subs, but nested formats aren't fixed up.

Since I'm currently working on trying to get sub declarations
to take effect at the start of a sub rather than at the end (eg
sub f($) { f(1) }), I'll see if I can work in a fix for this at the
same time.

--
"You're so sadly neglected, and often ignored.
A poor second to Belgium, When going abroad."
Monty Python - "Finland"

GPG/PGP-Key​:
wwwkeys.pgp.net​:11371/pks/lookup?op=vindex&search=0x97A5CFE9&fingerprint=on
Fingerprint = B44F 7109 A40F B383 AA1B 778D 43B9 767C 97A5 CFE9

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ _/
_/ (`-'-,-. _. _/
_/ '._ (_ '.__.-, _/
_/ .-;`-.-`_..-' _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ `\___-.(_ _/ _/
_/ _.) a'-._ _/ Rüdiger Schopper _/
_/ __ .' `\ _/ schopper@​usm.uni-muenchen.de _/
_/ .' ` ._^/ _/ _/
_/ _..._.-' /`\ / _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ _.' \ / ) _/ _/
_/ (/ / ) |/ _/ The surest sign that intelli- _/
_/ | | / ;-. _/ gent life in universe exists _/
_/ ;\ /'-.__.| /-. \ _/ is that none of it has tried _/
_/ / ) / | | '.\ _/ to contact us ! _/
_/ / /| / \ | || _/ _/
_/ | / / / | | / | _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ || \ \ | | \_/ _/
_/ )_`\ )_`\ )_`\ _/
_/ `""` `""` `""` _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*** This message was entirely written with recycled electrons ***

@p5pRT
Copy link
Author

p5pRT commented Jul 22, 2003

From @iabyn

On Mon, Jul 21, 2003 at 05​:43​:39PM +0200, Ruediger Schopper wrote​:

Hi Dave,
thanks for the extremely fast response. I would like to know if we might be
able to help you with the subroutine/format bug? We are clearly not deep
enough into the stuff to be able to effectively offer time, but perhaps we
might help with money. Do you think we can be of any help, or shall we just
wait until you come up with a bugfix?

Thanks for the kind offer, but I don't think that giving money to me
personally would speed up the bugfix.

However, if you want to contribute financially to the development of Perl
generally, you might consider a donation to the Perl Foundation,
http​://perlfoundation.org/, which (amongst other things) provides grants
to various individuals associated with Perl.

I am hoping to have a patch ready in 2-3 weeks time, but it's
unlikely to be included in the soon-to-be-released 5.8.1, so it will most
likely appear in 5.10.0 (or possibly a 5.8.2). Either of these may be a
year or more away.

Of course, I may find that I can't fix it after all...

Regards,

Dave.

--
"But Sidley Park is already a picture, and a most amiable picture too.
The slopes are green and gentle. The trees are companionably grouped at
intervals that show them to advantage. The rill is a serpentine ribbon
unwound from the lake peaceably contained by meadows on which the right
amount of sheep are tastefully arranged." Lady Croom - Arcadia

@p5pRT
Copy link
Author

p5pRT commented Sep 2, 2003

From schopper@usm.uni-muenchen.de

Hi Dave,

do you have any news concerning the subroutine/format bug I sent you a
couple of weeks ago? If so, we would be happy hear from you.

With best regards

Rüdiger

I am hoping to have a patch ready in 2-3 weeks time, but it's
unlikely to be included in the soon-to-be-released 5.8.1, so it will most
likely appear in 5.10.0 (or possibly a 5.8.2). Either of these may be a
year or more away.

Of course, I may find that I can't fix it after all...

Regards,

Dave.

--
"But Sidley Park is already a picture, and a most amiable picture too.
The slopes are green and gentle. The trees are companionably grouped at
intervals that show them to advantage. The rill is a serpentine ribbon
unwound from the lake peaceably contained by meadows on which the right
amount of sheep are tastefully arranged." Lady Croom - Arcadia

GPG/PGP-Key​:
wwwkeys.pgp.net​:11371/pks/lookup?op=vindex&search=0x97A5CFE9&fingerprint=on
Fingerprint = B44F 7109 A40F B383 AA1B 778D 43B9 767C 97A5 CFE9

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ _/
_/ (`-'-,-. _. _/
_/ '._ (_ '.__.-, _/
_/ .-;`-.-`_..-' _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ `\___-.(_ _/ _/
_/ _.) a'-._ _/ Rüdiger Schopper _/
_/ __ .' `\ _/ schopper@​usm.uni-muenchen.de _/
_/ .' ` ._^/ _/ _/
_/ _..._.-' /`\ / _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ _.' \ / ) _/ _/
_/ (/ / ) |/ _/ The surest sign that intelli- _/
_/ | | / ;-. _/ gent life in universe exists _/
_/ ;\ /'-.__.| /-. \ _/ is that none of it has tried _/
_/ / ) / | | '.\ _/ to contact us ! _/
_/ / /| / \ | || _/ _/
_/ | / / / | | / | _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/ || \ \ | | \_/ _/
_/ )_`\ )_`\ )_`\ _/
_/ `""` `""` `""` _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
*** This message was entirely written with recycled electrons ***

@p5pRT
Copy link
Author

p5pRT commented Sep 2, 2003

From @iabyn

On Tue, Sep 02, 2003 at 01​:28​:58PM +0200, Ruediger Schopper wrote​:

Hi Dave,

do you have any news concerning the subroutine/format bug I sent you a
couple of weeks ago? If so, we would be happy hear from you.

I'm working on a opath, bug have got side-tracked with things more
directlky related to the shortly-to-be-released 5.8.1. It also turned out
to be more compilated than I had thought. So no ETA, I'm afraid :-(

I am hoping to have a patch ready in 2-3 weeks time, but it's
unlikely to be included in the soon-to-be-released 5.8.1, so it will most
likely appear in 5.10.0 (or possibly a 5.8.2). Either of these may be a
year or more away.

Of course, I may find that I can't fix it after all...

--
"Strange women lying in ponds distributing swords is no basis for a system
of government. Supreme executive power derives from a mandate from the
masses, not from some farcical aquatic ceremony."
Dennis - Monty Python and the Holy Grail.

@p5pRT
Copy link
Author

p5pRT commented Sep 2, 2003

From @iabyn

On Tue, Sep 02, 2003 at 09​:01​:05PM +0100, Dave Mitchell wrote​:

Would have helped if I'd proof-read it before hitting the send key.
Here it is again in English​:

I'm working on a patch, but have got side-tracked with things more
directly related to the shortly-to-be-released 5.8.1. It also turned out
to be more complicated than I had thought. So no ETA, I'm afraid :-(

--
To collect all the latest movies, simply place an unprotected ftp server
on the Internet, and wait for the disk to fill....

@p5pRT
Copy link
Author

p5pRT commented Sep 7, 2004

From Alexander.stohr@gmx.de

It seems to me that this bug is still a pending one.
The below sample code still raises the problem.
-Alex.

#!/usr/bin/perl -w
use strict;
sub show ();
my $set_glob;
show;
sub show ()
{ my @​tag_list = ([100], [101], [102]);
  my $set_sub = [99];
  foreach $set_sub (@​tag_list)
  { $set_glob = $set_sub;
  print "$set_sub $set_sub->[0] (loop)\n";
  $~ = 'TEST_SUB';
  write;
  $~ = 'TEST_GLOB';
  write;
  print "\n";
# this is the buggy part
# it happens only for variables defined in subroutines
# the bug origin might be the perl interpreter
# the bug is present in at least​: perl, v5.8.2 built for i686-linux
format TEST_SUB =
@​<<<<<<<<<<<<<<< @​<<<<<<<<< (sub)
{ $set_sub, $set_sub->[0]
}
.
  }
}
format TEST_GLOB =
@​<<<<<<<<<<<<<<< @​<<<<<<<<< (glob)
{ $set_glob, $set_glob->[0]
}
.

Results are​:
ARRAY(0x81241c8) 100 (loop)
ARRAY(0x81242e8) 99 (sub)
ARRAY(0x81241c8) 100 (glob)

ARRAY(0x81317a4) 101 (loop)
ARRAY(0x81242e8) 99 (sub)
ARRAY(0x81317a4) 101 (glob)

ARRAY(0x8131888) 102 (loop)
ARRAY(0x81242e8) 99 (sub)
ARRAY(0x8131888) 102 (glob)

@p5pRT
Copy link
Author

p5pRT commented Jun 27, 2008

From p5p@spam.wizbit.be

On Mon Jul 14 15​:15​:03 2003, davem wrote​:

On Mon, Jul 14, 2003 at 05​:37​:42AM -0000, Ruediger Schopper wrote​:

I belive, that we've found a bug in perl. We discovered it when
changing from
perl-5.4.4 to perl-5.8.0, where we got strange results with
write in a program we heavily used without problems.

The bug can be reduced to the simpler case​:

sub f \($\); \# Comment out to get right result\!
sub f \($\) \{
my $test = $\_\[0\];
write;
format STDOUT =
@&#8203;\<\<\<\<\<\<\<
$test
\.
\}
f\(1\);
f\(2\);

It's due to there being multiple CVs associated with f due to to the
forward declaration, and to newATTRSUB() copying the contents of the
second CV to the first. This causes any nested subs to have
CvOUTSIDE
pointing to the wrong CV. A call to pad_fixup_inner_anons() fixes up
any
nested anon subs, but nested formats aren't fixed up.

Since I'm currently working on trying to get sub declarations
to take effect at the start of a sub rather than at the end (eg
sub f($) { f(1) }), I'll see if I can work in a fix for this at the
same time.

It appears that things got worse for 5.10.0/blead...

perl-5.8.8 rt-22977.pl
1
1

(Instead of 1 2)

perl-5.9.0 rt-22977.pl
Segmentation fault

perl-5.10.0 rt-22977.pl
Segmentation fault

perl-blead rt-22977.pl
Segmentation fault

@p5pRT
Copy link
Author

p5pRT commented Jun 29, 2008

From @andk

On Fri, 27 Jun 2008 12​:04​:09 -0700, "Bram via RT" <perlbug-followup@​perl.org> said​:

  > It appears that things got worse for 5.10.0/blead...

Binary search reveals...

----Program----
sub f ($); # Comment out to get right result!
sub f ($) {
  my $test = $_[0];
  write;
  format STDOUT =
@​<<<<<<<
$test
.
}
f(1);
f(2);

----Output of .../pMZAcVt/perl-5.8.0@​19648/bin/perl----
1
1

----EOF ($?='0')----
----Output of .../pgL2gwc/perl-5.8.0@​19649/bin/perl----

----EOF ($?='11')----

Change 19649 by rgs@​rgs-home on 2003/05/31 18​:33​:07

  Subject​: [PATCH] jumbo closure patch broke formats
  From​: Dave Mitchell <davem@​fdgroup.com>
  Date​: Sat, 31 May 2003 19​:54​:48 +0100
  Message-ID​: <20030531185448.GA6055@​fdgroup.com>
  Plus restore the original test script for bug #22372

--
andreas

@p5pRT
Copy link
Author

p5pRT commented May 28, 2009

From @nwc10

Dave notes​:

Was a format/closure/newATTSUB bug in 5.8.8; in 5.10.0, maint, blead, it
gets worse and becomes an assertion failure

@p5pRT
Copy link
Author

p5pRT commented Jun 25, 2009

From chromatic@wgz.org

On Friday 27 June 2008 12​:04​:09 Bram via RT wrote​:

The bug can be reduced to the simpler case​:

sub f \($\); \# Comment out to get right result\!
sub f \($\) \{
my $test = $\_\[0\];
write;
format STDOUT =
@&#8203;\<\<\<\<\<\<\<
$test
\.
\}
f\(1\);
f\(2\);

That's the same bug as RT #50528.

-- c

@p5pRT
Copy link
Author

p5pRT commented Dec 14, 2009

From zefram@fysh.org

Attached patch fixes bug #22977. make regen_perly after applying.

-zefram

@p5pRT
Copy link
Author

p5pRT commented Dec 14, 2009

From zefram@fysh.org

Inline Patch
diff --git a/perly.y b/perly.y
index 18e5875..a61a6b3 100644
--- a/perly.y
+++ b/perly.y
@@ -511,7 +511,9 @@ peg	:	PEG
 	;
 
 format	:	FORMAT startformsub formname block
-			{ SvREFCNT_inc_simple_void(PL_compcv);
+			{
+			  CV *fmtcv = PL_compcv;
+			  SvREFCNT_inc_simple_void(PL_compcv);
 #ifdef MAD
 			  $$ = newFORM($2, $3, $4);
 			  prepend_madprops($1->tk_mad, $$, 'F');
@@ -521,6 +523,10 @@ format	:	FORMAT startformsub formname block
 			  newFORM($2, $3, $4);
 			  $$ = (OP*)NULL;
 #endif
+			  if (CvOUTSIDE(fmtcv) && !CvUNIQUE(CvOUTSIDE(fmtcv))) {
+			    SvREFCNT_inc_simple_void(fmtcv);
+			    pad_add_anon((SV*)fmtcv, OP_NULL);
+			  }
 			}
 	;
 
diff --git a/t/comp/form_scope.t b/t/comp/form_scope.t
new file mode 100644
index 0000000..3ef891e
--- /dev/null
+++ b/t/comp/form_scope.t
@@ -0,0 +1,18 @@
+#!./perl
+#
+# Tests bug #22977.  Test case from Dave Mitchell.
+
+print "1..2\n";
+
+sub f ($);
+sub f ($) {
+my $test = $_[0];
+write;
+format STDOUT =
+ok @<<<<<<<
+$test
+.
+}
+
+f(1);
+f(2);

@p5pRT
Copy link
Author

p5pRT commented Dec 15, 2009

From @rgarcia

2009/12/15 Zefram <zefram@​fysh.org>​:

Attached patch fixes bug #22977.  make regen_perly after applying.

Thanks, applied, regenerated, and MANIFEST completed.

@p5pRT
Copy link
Author

p5pRT commented Dec 15, 2009

@rgs - Status changed from 'open' to 'resolved'

@p5pRT p5pRT closed this as completed Dec 15, 2009
@p5pRT
Copy link
Author

p5pRT commented Jun 28, 2012

From @cpansprout

On Tue Dec 15 02​:49​:25 2009, rgs@​consttype.org wrote​:

2009/12/15 Zefram <zefram@​fysh.org>​:

Attached patch fixes bug #22977. �make regen_perly after applying.

Thanks, applied, regenerated, and MANIFEST completed.

The commit id was 421f30e.

The commit message did not explain​: It follows Dave Mitchell’s
suggestion of adding formats to '&' entries in the enclosing sub’s pad,
so that the fixup code for subs applies to formats as well.

--

Father Chrysostomos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant