Bug 191409 - h2ph generates incorrect code for '#if defined A || defined B'
Summary: h2ph generates incorrect code for '#if defined A || defined B'
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: perl
Version: 4.0
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
: ---
Assignee: Jason Vas Dias
QA Contact: David Lawrence
URL: http://rt.perl.org/rt3/Ticket/Display...
Whiteboard:
Depends On:
Blocks: 191416 199151
TreeView+ depends on / blocked
 
Reported: 2006-05-11 18:08 UTC by Jason Vas Dias
Modified: 2007-11-30 22:07 UTC (History)
1 user (show)

Fixed In Version: 5.8.5-34.RHEL4
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2006-10-04 18:48:38 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Jason Vas Dias 2006-05-11 18:08:28 UTC
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

Comment 1 Jason Vas Dias 2006-05-11 19:43:02 UTC
Now fixed with perl-5.8.5-34.RHEL4 .


Note You need to log in before you can comment on or make changes to this bug.