develooper Front page | perl.perl5.porters | Postings from January 2009

[perl #62114] Re: perl5.10.0's perl.h requires additional check for C99 compliance

From:
Stuart Shelton
Date:
January 9, 2009 05:06
Subject:
[perl #62114] Re: perl5.10.0's perl.h requires additional check for C99 compliance
Message ID:
rt-3.6.HEAD-28035-1231496764-1210.62114-75-0@perl.org
# New Ticket Created by  "Stuart Shelton" 
# Please include the string:  [perl #62114]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=62114 >


Actually, if '__c99' isn't standard, then a more portable replacement could be:

#if defined(HAS_SNPRINTF) && defined(HAS_C99_VARIADIC_MACROS) &&
!(defined(DEBUGGING) && !defined(PERL_USE_GCC_BRACE_GROUPS)) &&
!defined(PERL_GCC_PEDANTIC) && (!defined __sgi || (defined __sgi &&
defined __c99))


2009/1/8 NetBSD <netbsd@fuel.openobjects.com>:
>
> This is a bug report for perl from netbsd@fuel.local,
> generated with the help of perlbug 1.36 running under perl 5.10.0.
>
>
> -----------------------------------------------------------------
> [Please enter your report here]
>
> On IRIX, the native compiler can be invoked as 'cc' which is equivalent to
> 'cc -c89' or as 'c99' which is equivalent to 'cc -c99'.  C99 syntax is only
> available with the latter invokation.
>
> With this in mind, I built perl using 'c99 -c99' to cover all circumstances,
> whilst retaining meximum compatibility with modules containing native code
> (most of which naturally include C99 code these days).
>
> However, some (broken) perl modules ignore either $CC and the perl $cc and/or
> $CFLAGS and the perl $optimize values.  Where both are ignored then there is a
> problem as, when bulit this way, perl's CORE/perl.h includes C99 constructs.
>
> BSD::Resource was failing to build under CPAN, stating that <sys/resource.h> was
> unavailable, despite it being present and correct.  The problem was due to the
> module's Makefile ignoring both $cc and $optimize.  The build was actually
> choking on perl5/5.10.0/mips-irix/CORE/perl.h:
>
> #if defined(HAS_SNPRINTF) && defined(HAS_C99_VARIADIC_MACROS) && !(defined(DEBUGGING) && !defined(PERL_USE_GCC_BRACE_GROUPS)) && !defined(PERL_GCC_PEDANTIC)
> #  ifdef PERL_USE_GCC_BRACE_GROUPS
> #      define my_snprintf(buffer, len, ...) ({ int __len__ = snprintf(buffer, len, __VA_ARGS__); if ((len) > 0 && (Size_t)__len__ >= (len)) Perl_croak_nocontext("panic: snprintf buffer overflow"); __len__; })
> #      define PERL_MY_SNPRINTF_GUARDED
> #  else
> #    define my_snprintf(buffer, len, ...) snprintf(buffer, len, __VA_ARGS__)
> #  endif
> #else
> #  define my_snprintf  Perl_my_snprintf
> #  define PERL_MY_SNPRINTF_GUARDED
> #endif
>
> ... because HAS_C99_VARIADIC_MACROS is only true when invoked under C99 mode -
> by ignoring both $cc and $optimize, the module removed the compiler's ability
> to parse variadic macros: it was hitting 'buffer, len, ...' and aborting.
>
> Whilst the module should be fixed, perl.h could also be updated to work around
> the problem.  I'm not sure how standard it is, but the MIPSpro compilers define
> '__c99' when C99 mode is in effect.  If this is a standard, then the following
> patch:
>
> --- perl5/5.10.0/mips-irix/CORE/perl.h.old
> +++ perl5/5.10.0/mips-irix/CORE/perl.h
> @@ -1578,7 +1578,7 @@
>  * that should be true only if the snprintf()/vsnprintf() are true
>  * to the standard. */
>
> -#if defined(HAS_SNPRINTF) && defined(HAS_C99_VARIADIC_MACROS) && !(defined(DEBUGGING) && !defined(PERL_USE_GCC_BRACE_GROUPS)) && !defined(PERL_GCC_PEDANTIC)
> +#if defined(HAS_SNPRINTF) && defined(HAS_C99_VARIADIC_MACROS) && !(defined(DEBUGGING) && !defined(PERL_USE_GCC_BRACE_GROUPS)) && !defined(PERL_GCC_PEDANTIC) && defined __c99
>  #  ifdef PERL_USE_GCC_BRACE_GROUPS
>  #      define my_snprintf(buffer, len, ...) ({ int __len__ = snprintf(buffer, len, __VA_ARGS__); if ((len) > 0 && (Size_t)__len__ >= (len)) Perl_croak_nocontext("panic: snprintf buffer overflow"); __len__; })
>  #      define PERL_MY_SNPRINTF_GUARDED
> @@ -1590,7 +1590,7 @@
>  #  define PERL_MY_SNPRINTF_GUARDED
>  #endif
>
> -#if defined(HAS_VSNPRINTF) && defined(HAS_C99_VARIADIC_MACROS) && !(defined(DEBUGGING) && !defined(PERL_USE_GCC_BRACE_GROUPS)) && !defined(PERL_GCC_PEDANTIC)
> +#if defined(HAS_VSNPRINTF) && defined(HAS_C99_VARIADIC_MACROS) && !(defined(DEBUGGING) && !defined(PERL_USE_GCC_BRACE_GROUPS)) && !defined(PERL_GCC_PEDANTIC) && defined __c99
>  #  ifdef PERL_USE_GCC_BRACE_GROUPS
>  #      define my_vsnprintf(buffer, len, ...) ({ int __len__ = vsnprintf(buffer, len, __VA_ARGS__); if ((len) > 0 && (Size_t)__len__ >= (len)) Perl_croak_nocontext("panic: vsnprintf buffer overflow"); __len__; })
>  #      define PERL_MY_VSNPRINTF_GUARDED
>
> ... adds a simple final check that, regardless of whether variadic macros were
> available when perl was built, they can be correctly parsed under the current
> compiler environment.
>
> Thanks in advance,
>
> Stuart
>
>
> [Please do not change anything below this line]
> -----------------------------------------------------------------
> ---
> Flags:
>    category=library
>    severity=medium
> ---
> Site configuration information for perl 5.10.0:
>
> Configured by netbsd at Tue Dec  9 10:59:21 GMT 2008.
>
> Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
>  Platform:
>    osname=irix, osvers=6.5, archname=mips-irix
>    uname='irix64 fuel 6.5 07202013 ip35 mips irix '
>    config_args='undef'
>    hint=recommended, useposix=true, d_sigaction=define
>    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='c99 -c99 -n32 -mips4 -r14000 -float_const -use_readonly_const -TARG:isa=mips4:platform=ip35:processor=r14000 -TENV:zeroinit_in_bss=ON', ccflags ='-woff 1174,1183,1184,1185,1188,1196,1204,1548,1552,3970,3968 -D_BSD_TYPES -D_BSD_TIME -DLANGUAGE_C -I/usr/bsd/include',
>    optimize='-c99 -O2 -n32 -mips4 -r14000 -float_const -use_readonly_const -TARG:isa=mips4:platform=ip35:processor=r14000 -TENV:zeroinit_in_bss=ON -OPT:fast_io=ON:Olimit=8192:reorg_common=ON:swp=ON -LNO:auto_dist=ON:fusion_peeling_limit=8:gather_scatter=2 ',
>    cppflags='-woff 1174,1183,1184,1185,1188,1196,1204,1209,1548,1552,3970,3968 -D_BSD_TYPES -D_BSD_TIME -DLANGUAGE_C -I/usr/bsd/include'
>    ccversion='MIPSpro Compilers: Version 7.4.4m', gccversion='', gccosandvers=''
>    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
>    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
>    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
>    alignbytes=8, prototype=define
>  Linker and Libraries:
>    ld='c99 -c99 -n32 -mips4 -r14000 -float_const -use_readonly_const -TARG:isa=mips4:platform=ip35:processor=r14000 -TENV:zeroinit_in_bss=ON', ldflags ='-Wl,-v,-s,-x,-n32,-mips4,-rdata_shared,-allow_jump_at_eop,-rpath,/usr/bsd/lib -L/usr/bsd/lib'
>    libpth=/usr/lib32 /lib32 /usr/bsd/lib32 /usr/nekoware/lib /usr/freeware/lib32
>    libs=-lm
>    perllibs=-lm
>    libc=/usr/lib32/libc.so, so=so, useshrplib=true, libperl=libperl.so
>    gnulibc_version=''
>  Dynamic Linking:
>    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-n32 -mips4 -Wl,-v,-s,-x,-n32,-mips4,-rdata_shared,-allow_jump_at_eop,-rpath,/usr/bsd/lib/perl5/5.10.0/mips-irix/CORE'
>    cccdlflags=' ', lddlflags='-Wl,-v,-s,-x,-n32,-mips4,-rdata_shared,-allow_jump_at_eop,-rpath,/usr/bsd/lib -shared -L/usr/bsd/lib'
>
> Locally applied patches:
>
>
> ---
> @INC for perl 5.10.0:
>    /usr/bsd/lib/perl5/site_perl/5.10.0/mips-irix
>    /usr/bsd/lib/perl5/site_perl/5.10.0
>    /usr/bsd/lib/perl5/site_perl/5.10.0/mips-irix
>    /usr/bsd/lib/perl5/site_perl/5.10.0
>    /usr/bsd/lib/perl5/site_perl
>    /usr/bsd/lib/perl5/vendor_perl/5.10.0/mips-irix
>    /usr/bsd/lib/perl5/vendor_perl/5.10.0
>    /usr/bsd/lib/perl5/vendor_perl/5.10.0/mips-irix
>    /usr/bsd/lib/perl5/vendor_perl/5.10.0
>    /usr/bsd/lib/perl5/vendor_perl
>    /usr/bsd/lib/perl5/5.10.0/mips-irix
>    /usr/bsd/lib/perl5/5.10.0
>    .
>
> ---
> Environment for perl 5.10.0:
>    HOME=/usr/bsd/src
>    LANG=en_GB
>    LANGUAGE (unset)
>    LC_COLLATE=C
>    LD_LIBRARYN32_PATH=/usr/lib32:/usr/bsd/lib:/usr/gnu/lib:/usr/local/lib
>    LD_LIBRARY_PATH=/usr/lib
>    LOGDIR (unset)
>    PATH=/usr/bsd/sbin:/usr/bsd/bin:/usr/freeware/sbin:/usr/gnu/bin:/usr/freeware/bin:/usr/bsd:/usr/local/bin:/usr/sbin:/usr/sbin:/usr/bsd:/sbin:/usr/bin:/usr/bin/X11
>    PERL_BADLANG (unset)
>    SHELL=/usr/bsd/bin/bash
>




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About