Skip Menu |
 

This queue is for tickets about the Encode CPAN distribution.

Report information
The Basics
Id: 105471
Status: resolved
Priority: 0/
Queue: Encode

People
Owner: Nobody in particular
Requestors: davem [...] iabyn.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: make Encode build with -pedantic
Date: Wed, 24 Jun 2015 14:09:30 +0100
To: bug-Encode [...] rt.cpan.org
From: Dave Mitchell <davem [...] iabyn.com>
Download (untitled) / with headers
text/plain 5.8k
I've just merged into blead a commit that makes Encode build again under gcc -pedantic. See the p5p thread http://nntp.perl.org/group/perl.perl5.porters/228695 for more details. Here's the commit description and the relevant part of the diff. Thanks. Dave. commit e67e8a4a47a2610450982979717f503914221118 Author: David Mitchell <davem@iabyn.com> AuthorDate: Tue Jun 23 11:12:40 2015 +0100 Commit: David Mitchell <davem@iabyn.com> CommitDate: Wed Jun 24 13:40:47 2015 +0100 make Encode compile under -pedantic enc2xs generates some C code which contains tables. These tables contain recursive and mutually recursive pointers to other tables. Normally they are declared as 'static const', except under C++ which can't handle this, so there they are declared 'extern' and defined ''. -Wc++-compat and -pedantic put a bit of a spanner in the works. There is an existing hack to shut up a warning with -Wc++-compat by not including the table's size in the forward declaration, but this breaks -pedantic. This commit does two things to enc2xs. First it moves all the logic that examines the build options and decides whether to use 'const' etc, into a separate function, compiler_info(). Second, it fixes the -pedantic compilation failure by, in the presence of both -Wc++-compat and -pedantic, falling back to a C++-style compile without the 'static const'. This is monkey-patching an unstream-CPAN module in core due to it failing one of the smoke configurations. diff --git a/cpan/Encode/bin/enc2xs b/cpan/Encode/bin/enc2xs index 19f2b2b..ec4732c 100644 --- a/cpan/Encode/bin/enc2xs +++ b/cpan/Encode/bin/enc2xs @@ -10,7 +10,7 @@ use warnings; use Getopt::Std; use Config; my @orig_ARGV = @ARGV; -our $VERSION = do { my @r = (q$Revision: 2.17 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +our $VERSION = do { my @r = (q$Revision: 2.18 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # These may get re-ordered. # RAW is a do_now as inserted by &enter @@ -146,6 +146,52 @@ sub verbosef { printf STDERR @_ if $opt{v}; } + +# ($cpp, $static, $sized) = compiler_info($declaration) +# +# return some information about the compiler and compile options we're using: +# +# $declaration - true if we're doing a declaration rather than a definition. +# +# $cpp - we're using C++ +# $static - ok to declare the arrays as static +# $sized - the array declarations should be sized + +sub compiler_info { + my ($declaration) = @_; + + my $ccflags = $Config{ccflags}; + if (defined $Config{ccwarnflags}) { + $ccflags .= " " . $Config{ccwarnflags}; + } + my $compat = $ccflags =~ /\Q-Wc++-compat/; + my $pedantic = $ccflags =~ /-pedantic/; + + my $cpp = ($Config{d_cplusplus} || '') eq 'define'; + + # The encpage_t tables contain recursive and mutually recursive + # references. To allow them to compile under C++ and some restrictive + # cc options, it may be necessary to make the tables non-static/const + # (thus moving them from the text to the data segment) and/or not + # include the size in the declaration. + + my $static = !( + $cpp + || ($compat && $pedantic) + || ($^O eq 'MacOS' && $declaration) + ); + + # -Wc++-compat on its own warns if the array declaration is sized. + # The easiest way to avoid this warning is simply not to include + # the size in the declaration. + # With -pedantic as well, the issue doesn't arise because $static + # above becomes false. + my $sized = $declaration && !($compat && !$pedantic); + + return ($cpp, $static, $sized); +} + + # This really should go first, else the die here causes empty (non-erroneous) # output files to be written. my @encfiles; @@ -279,7 +325,7 @@ if ($doC) # push(@{$encoding{$name}},outstring(\*C,$e2u->{Cname}.'_def',$erep)); } - my $cpp = ($Config{d_cplusplus} || '') eq 'define'; + my ($cpp) = compiler_info(0); my $ext = $cpp ? 'extern "C"' : "extern"; my $exta = $cpp ? 'extern "C"' : "static"; my $extb = $cpp ? 'extern "C"' : ""; @@ -707,15 +753,10 @@ sub addstrings } if ($a->{'Forward'}) { - my $cpp = ($Config{d_cplusplus} || '') eq 'define'; - my $var = $^O eq 'MacOS' || $cpp ? 'extern' : 'static'; - my $const = $cpp ? '' : 'const'; - my $ccflags = $Config{ccflags}; - if (defined $Config{ccwarnflags}) { - $ccflags .= " " . $Config{ccwarnflags}; - } - my $count = $ccflags =~ /-Wc\+\+-compat/ ? '' : scalar(@{$a->{'Entries'}}); - print $fh "$var $const encpage_t $name\[$count];\n"; + my ($cpp, $static, $sized) = compiler_info(1); + my $var = $static ? 'static const' : 'extern'; + my $count = $sized ? scalar(@{$a->{'Entries'}}) : ''; + print $fh "$var encpage_t $name\[$count];\n"; } $a->{'DoneStrings'} = 1; foreach my $b (@{$a->{'Entries'}}) @@ -778,7 +819,7 @@ sub outbigstring } $strings = length $string_acc; - my $cpp = ($Config{d_cplusplus} || '') eq 'define'; + my ($cpp) = compiler_info(0); my $var = $cpp ? '' : 'static'; my $definition = "\n$var const U8 $name\[$strings] = { " . join(',',unpack "C*",$string_acc); @@ -805,10 +846,9 @@ sub outtable my ($s,$e,$out,$t,$end,$l) = @$b; outtable($fh,$t,$bigname) unless $t->{'Done'}; } - my $cpp = ($Config{d_cplusplus} || '') eq 'define'; - my $var = $cpp ? '' : 'static'; - my $const = $cpp ? '' : 'const'; - print $fh "\n$var $const encpage_t $name\[", + my ($cpp, $static) = compiler_info(0); + my $var = $static ? 'static const ' : ''; + print $fh "\n${var}encpage_t $name\[", scalar(@{$a->{'Entries'}}), "] = {\n"; foreach my $b (@{$a->{'Entries'}}) { -- print+qq&$}$"$/$s$,$a$d$g$s$@$.$q$,$:$.$q$^$,$@$a$~$;$.$q$m&if+map{m,^\d{0\,},,${$::{$'}}=chr($"+=$&||1)}q&10m22,42}6:17a2~2.3@3;^2dg3q/s"&=~m*\d\*.*g
Thanks, applied as: https://github.com/dankogai/p5-encode/commit/65ee96a15475be62b9de192fab7ba1d9bfcfcaae Dan the Maintainer Thereof On Wed Jun 24 09:09:48 2015, davem@iabyn.com wrote: Show quoted text
> I've just merged into blead a commit that makes Encode build again > under gcc -pedantic. > > See the p5p thread > http://nntp.perl.org/group/perl.perl5.porters/228695 > for more details. > > Here's the commit description and the relevant part of the diff. > Thanks. > Dave. > > commit e67e8a4a47a2610450982979717f503914221118 > Author: David Mitchell <davem@iabyn.com> > AuthorDate: Tue Jun 23 11:12:40 2015 +0100 > Commit: David Mitchell <davem@iabyn.com> > CommitDate: Wed Jun 24 13:40:47 2015 +0100 > > make Encode compile under -pedantic > > enc2xs generates some C code which contains tables. These tables > contain > recursive and mutually recursive pointers to other tables. Normally > they > are declared as 'static const', except under C++ which can't handle > this, > so there they are declared 'extern' and defined ''. > > -Wc++-compat and -pedantic put a bit of a spanner in the works. > There is an existing hack to shut up a warning with -Wc++-compat by > not > including the table's size in the forward declaration, but this breaks > -pedantic. > > This commit does two things to enc2xs. First it moves all the logic > that > examines the build options and decides whether to use 'const' etc, > into > a separate function, compiler_info(). Second, it fixes the -pedantic > compilation failure by, in the presence of both -Wc++-compat and > -pedantic, falling back to a C++-style compile without the 'static > const'. > > This is monkey-patching an unstream-CPAN module in core due to it > failing > one of the smoke configurations. > > diff --git a/cpan/Encode/bin/enc2xs b/cpan/Encode/bin/enc2xs > index 19f2b2b..ec4732c 100644 > --- a/cpan/Encode/bin/enc2xs > +++ b/cpan/Encode/bin/enc2xs > @@ -10,7 +10,7 @@ use warnings; > use Getopt::Std; > use Config; > my @orig_ARGV = @ARGV; > -our $VERSION = do { my @r = (q$Revision: 2.17 $ =~ /\d+/g); sprintf > "%d."."%02d" x $#r, @r }; > +our $VERSION = do { my @r = (q$Revision: 2.18 $ =~ /\d+/g); sprintf > "%d."."%02d" x $#r, @r }; > > # These may get re-ordered. > # RAW is a do_now as inserted by &enter > @@ -146,6 +146,52 @@ sub verbosef { > printf STDERR @_ if $opt{v}; > } > > + > +# ($cpp, $static, $sized) = compiler_info($declaration) > +# > +# return some information about the compiler and compile options > we're using: > +# > +# $declaration - true if we're doing a declaration rather than a > definition. > +# > +# $cpp - we're using C++ > +# $static - ok to declare the arrays as static > +# $sized - the array declarations should be sized > + > +sub compiler_info { > + my ($declaration) = @_; > + > + my $ccflags = $Config{ccflags}; > + if (defined $Config{ccwarnflags}) { > + $ccflags .= " " . $Config{ccwarnflags}; > + } > + my $compat = $ccflags =~ /\Q-Wc++-compat/; > + my $pedantic = $ccflags =~ /-pedantic/; > + > + my $cpp = ($Config{d_cplusplus} || '') eq 'define'; > + > + # The encpage_t tables contain recursive and mutually recursive > + # references. To allow them to compile under C++ and some > restrictive > + # cc options, it may be necessary to make the tables non- > static/const > + # (thus moving them from the text to the data segment) and/or not > + # include the size in the declaration. > + > + my $static = !( > + $cpp > + || ($compat && $pedantic) > + || ($^O eq 'MacOS' && $declaration) > + ); > + > + # -Wc++-compat on its own warns if the array declaration is > sized. > + # The easiest way to avoid this warning is simply not to include > + # the size in the declaration. > + # With -pedantic as well, the issue doesn't arise because $static > + # above becomes false. > + my $sized = $declaration && !($compat && !$pedantic); > + > + return ($cpp, $static, $sized); > +} > + > + > # This really should go first, else the die here causes empty (non- > erroneous) > # output files to be written. > my @encfiles; > @@ -279,7 +325,7 @@ if ($doC) > > # push(@{$encoding{$name}},outstring(\*C,$e2u->{Cname}.'_def',$erep)); > } > - my $cpp = ($Config{d_cplusplus} || '') eq 'define'; > + my ($cpp) = compiler_info(0); > my $ext = $cpp ? 'extern "C"' : "extern"; > my $exta = $cpp ? 'extern "C"' : "static"; > my $extb = $cpp ? 'extern "C"' : ""; > @@ -707,15 +753,10 @@ sub addstrings > } > if ($a->{'Forward'}) > { > - my $cpp = ($Config{d_cplusplus} || '') eq 'define'; > - my $var = $^O eq 'MacOS' || $cpp ? 'extern' : 'static'; > - my $const = $cpp ? '' : 'const'; > - my $ccflags = $Config{ccflags}; > - if (defined $Config{ccwarnflags}) { > - $ccflags .= " " . $Config{ccwarnflags}; > - } > - my $count = $ccflags =~ /-Wc\+\+-compat/ ? '' : scalar(@{$a-
> >{'Entries'}});
> - print $fh "$var $const encpage_t $name\[$count];\n"; > + my ($cpp, $static, $sized) = compiler_info(1); > + my $var = $static ? 'static const' : 'extern'; > + my $count = $sized ? scalar(@{$a->{'Entries'}}) : ''; > + print $fh "$var encpage_t $name\[$count];\n"; > } > $a->{'DoneStrings'} = 1; > foreach my $b (@{$a->{'Entries'}}) > @@ -778,7 +819,7 @@ sub outbigstring > } > > $strings = length $string_acc; > - my $cpp = ($Config{d_cplusplus} || '') eq 'define'; > + my ($cpp) = compiler_info(0); > my $var = $cpp ? '' : 'static'; > my $definition = "\n$var const U8 $name\[$strings] = { " . > join(',',unpack "C*",$string_acc); > @@ -805,10 +846,9 @@ sub outtable > my ($s,$e,$out,$t,$end,$l) = @$b; > outtable($fh,$t,$bigname) unless $t->{'Done'}; > } > - my $cpp = ($Config{d_cplusplus} || '') eq 'define'; > - my $var = $cpp ? '' : 'static'; > - my $const = $cpp ? '' : 'const'; > - print $fh "\n$var $const encpage_t $name\[", > + my ($cpp, $static) = compiler_info(0); > + my $var = $static ? 'static const ' : ''; > + print $fh "\n${var}encpage_t $name\[", > scalar(@{$a->{'Entries'}}), "] = {\n"; > foreach my $b (@{$a->{'Entries'}}) > {


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.