h2ph: workarounds for too large hexadecimal constants.
Jarkko Hietaniemi [Sat, 8 Jun 2002 14:58:43 +0000 (14:58 +0000)]
Now 'perlivp' passes without a whimper in Solaris 8 and
Tru64 4.0F (Debian 2.2 Linux/x86 doesn't but my header
installation is weird; e.g. float.h is not in /usr/include...
(cd /usr/include; h2ph -l -r .)

p4raw-id: //depot/perl@17094

utils/h2ph.PL

index 206df49..094a275 100644 (file)
@@ -300,7 +300,20 @@ sub expr {
        s/^\&\&// && do { $new .= " &&"; next;}; # handle && operator
        s/^\&([\(a-z\)]+)/$1/i; # hack for things that take the address of
        s/^(\s+)//              && do {$new .= ' '; next;};
-       s/^(0X[0-9A-F]+)[UL]*//i                && do {$new .= lc($1); next;};
+       s/^0X([0-9A-F]+)[UL]*//i 
+           && do {my $hex = $1;
+                  $hex =~ s/^0+//;
+                  if (length $hex > 8 && !$Config{use64bitint}) {
+                      # Croak if nv_preserves_uv_bits < 64 ?
+                      $new .=         hex(substr($hex, -8)) +
+                              2**32 * hex(substr($hex,  0, -8));
+                      # The above will produce "errorneus" code
+                      # if the hex constant was e.g. inside UINT64_C
+                      # macro, but then again, h2ph is an approximation.
+                  } else {
+                      $new .= lc("0x$hex");
+                  }
+                  next;};
        s/^(-?\d+\.\d+E[-+]?\d+)[FL]?//i        && do {$new .= $1; next;};
        s/^(\d+)\s*[LU]*//i     && do {$new .= $1; next;};
        s/^("(\\"|[^"])*")//    && do {$new .= $1; next;};