develooper Front page | perl.perl5.porters | Postings from March 2013

Re: [perl #117305] ISO C forbids braced-groups within expressions(cv.h, inline.h in 5.17.9)

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
March 22, 2013 23:14
Subject:
Re: [perl #117305] ISO C forbids braced-groups within expressions(cv.h, inline.h in 5.17.9)
Message ID:
20130322231328.GG2413@iabyn.com
On Fri, Mar 22, 2013 at 12:30:23PM -0700, Mark Martinec wrote:
> Perl include files (cv.h, inline.h, possibly others) use certain
> macros as expressions (like CvNAMED, MUTABLE_PTR), but these macros
> expand to "braced-group", which is not allowed in an expression
> according to ISO C - but is mercifully allowed by gcc.
> 
> Some Perl modules use cc options -std=c99 -pedantic-errors
> and include these perl .h files, so their compilation fails
> with compile time errors like:
> 
> .../5.17.9/mach/CORE/cv.h:194: error: ISO C forbids braced-groups within expressions
> .../5.17.9/mach/CORE/cv.h:196: error: ISO C forbids braced-groups within expressions
> .../5.17.9/mach/CORE/cv.h:201: error: ISO C forbids braced-groups within expressions
> .../5.17.9/mach/CORE/cv.h:202: error: ISO C forbids braced-groups within expressions
> .../5.17.9/mach/CORE/inline.h:23: error: ISO C forbids braced-groups within expressions
> 
> Here is a source code example from cv.h near line 194:
> 
> PERL_STATIC_INLINE GV *
> S_CvGV(CV *sv)
> {
>     return CvNAMED(sv)
> 	? 0
> 	: ((XPVCV*)MUTABLE_PTR(SvANY(sv)))->xcv_gv_u.xcv_gv;
> }
> 
> which gets expanded by a C preprocessor into:
> 
> S_CvGV(CV *sv)
> {
>   return (((XPVCV*)({ void *_p = ((sv)->sv_any); _p; }))->xcv_flags & 0x8000)
>     ? 0
>     : ((XPVCV*)({ void *_p = ((sv)->sv_any); _p; }))->xcv_gv_u.xcv_gv;
> }
> 
> which illustrates where "braced-group within expression"
> comes into play.

But these definitions are conditional:


    #if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
    #  define MUTABLE_PTR(p) ({ void *_p = (p); _p; })
    #else
    #  define MUTABLE_PTR(p) ((void *) (p))
    #endif

Further:

    #if defined(PERL_GCC_PEDANTIC) || \
	(defined(__GNUC__) && defined(__cplusplus) && \
	    ((__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 2))))
    #  ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN
    #    define PERL_GCC_BRACE_GROUPS_FORBIDDEN
    #  endif
    #endif

> An example of such CPAN module is ZMQ::LibZMQ3.  I have opened
> a ticket with this module ([rt.cpan.org #84124] suggesting to
> drop the -pedantic-errors option) - here is the author's reply:
> 
>   ( https://rt.cpan.org/Ticket/Display.html?id=84124 )
> 
>   Given some discussion on #p5p, I suspect that there is something wrong
>   in the bleadperl isn't setting PERL_GCC_PEDANTIC. You might want to file
>   this bug via perlbug. If they decide to release perl-5.18 without fixing
>   this, I'll release a new version with manual PERL_GCC_PEDANTIC define.
> 
> 
> So I suggest such constructs are either avoided, or clearly documented
> that these include files do not comply with ISO C99 standard.

I'm not sure I understand this. Is the author suggesting that bleadperl
built with -pedantic-errors doesn't set PERL_GCC_PEDANTIC?

Because:

$ sh Configure -des -Dusedevel -Accflags="-pedantic-errors"
...
$ make
`sh  cflags "optimize='-O2'" perlmini.o`  -DPERL_IS_MINIPERL -DPERL_EXTERNAL_GLOB perlmini.c
	  CCCMD =  cc -DPERL_CORE -c -pedantic-errors -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -O2  -Wall -DPERL_GCC_PEDANTIC 

(note the -DPERL_GCC_PEDANTIC on the command-line)

Or, is the author's module being built on a non-pedantic perl, but it adds
-pedantic-errors to the command line when building the module's source
files? In which case, I don't think perl has ever added PERL_GCC_PEDANTIC
to the command line or any include file.

Do you have a definite pass / transition, i.e. this module builds under
5.X, but doesn't build under 5.Y?



-- 
I've often wanted to drown my troubles, but I can't get my wife to go
swimming.

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