[Bug 191416] New: h2ph generates incorrect code for '#if defined A || defined B'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Please do not reply directly to this email. All additional
comments should be made in the comments box of this bug report.




https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=191416

           Summary: h2ph generates incorrect code for '#if defined A ||
                    defined B'
           Product: Fedora Core
           Version: devel
          Platform: All
               URL: http://rt.perl.org/rt3/Ticket/Display.html?id=39130
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: normal
         Component: perl
        AssignedTo: jvdias@xxxxxxxxxx
        ReportedBy: jvdias@xxxxxxxxxx
         QAContact: dkl@xxxxxxxxxx
                CC: fedora-perl-devel-list@xxxxxxxxxx,prockai@xxxxxxxxxx


+++ This bug was initially created as a clone of Bug #191409 +++

Description of problem:

This is perlbug #39130 - see URL .

For cpp statements like :

  #if defined A || defined B

h2ph would generate the code :

  if(defined (defined(&A) ? &A : 0) || defined (defined(&B) ? &B : 0)) {

which is tautologous, as defined(0) is always true .

This turns out to cause real problems on the Linux ppc64 platform,
where "endian-ness" is selectable in the compiler; every inclusion
of "endian.ph", which includes "bits/endian.ph", generates an error:
 
$ perl -e 'require "sys/socket.ph";'
Both BIG_ENDIAN and LITTLE_ENDIAN defined! at
/usr/lib/perl5/5.8.8/ppc-linux-thread-multi/bits/endian.ph line 10.
Compilation failed in require at...

Because h2ph generated this code in ../bits/endian.ph:
if(defined (defined(&__BIG_ENDIAN__) ? &__BIG_ENDIAN__ : 0) || defined
(defined(&_BIG_ENDIAN) ? &_BIG_ENDIAN : 0)) {
    if(defined (defined(&__LITTLE_ENDIAN__) ? &__LITTLE_ENDIAN__ : 0) || defined
(defined(&_LITTLE_ENDIAN) ? &_LITTLE_ENDIAN : 0)) {
        die("Both\ BIG_ENDIAN\ and\ LITTLE_ENDIAN\ defined\!");
    }
For the cpp code in /usr/include/bits/endian.h:
#if defined __BIG_ENDIAN__ || defined _BIG_ENDIAN
# if defined __LITTLE_ENDIAN__ || defined _LITTLE_ENDIAN
#  error Both BIG_ENDIAN and LITTLE_ENDIAN defined!
...

The problem does not happen if the 'defined..' conditions are in parentheses -
ie.
  #if defined(A) || defined(B)
produces correct code:
  if( defined(&A) || defined(&B) )

A trivial fix for this is to simply replace the ': 0' with ': undef' in
h2ph.PL line 517, as with this patch:
--- perl-5.8.8/utils/h2ph.PL~   2006-01-12 17:55:04.000000000 -0500
+++ perl-5.8.8/utils/h2ph.PL    2006-05-11 13:50:04.000000000 -0400
@@ -514,7 +514,7 @@
                }
            } else {
                if ($inif && $new !~ /defined\s*\($/) {
-                   $new .= '(defined(&' . $id . ') ? &' . $id . ' : 0)';
+                   $new .= '(defined(&' . $id . ') ? &' . $id . ' : undef)';
                } elsif (/^\[/) {
                    $new .= " \$$id";
                } else {

Version-Release number of selected component (if applicable):
ALL

How reproducible:
100%

Steps to Reproduce:
On a ppc64 platform with select-able endian-ness:
# perl -e 'require "sys/socket.ph";'
  
Actual results:
Both BIG_ENDIAN and LITTLE_ENDIAN defined! at
/usr/lib/perl5/5.8.8/ppc-linux-thread-multi/bits/endian.ph line 10.
Compilation failed in require at...

Expected results:
no error

-- 
Configure bugmail: https://bugzilla.redhat.com/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


[Index of Archives]     [Fedora Announce]     [Fedora Kernel]     [Fedora Testing]     [Fedora Legacy Announce]     [Fedora PHP Devel]     [Kernel Devel]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Big List of Linux Books]     [Gimp]     [Yosemite Information]
  Powered by Linux