[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Patch b4_uint_type and b4_sint_type range problem
From: |
Paul Hilfinger |
Subject: |
Patch b4_uint_type and b4_sint_type range problem |
Date: |
Sun, 05 May 2002 19:05:52 -0700 |
This showed up when I recently ran the testsuite on a Sparc
Solaris installation.
m4 evaluates integer expressions as 32-bit signed quantities. As a
result, the b4_sint_type and b4_uint_type definitions don't work for
arguments larger than 32767 or 65535, respectively. More precisely,
with b4_sint_type, NO argument will cause the error message, whereas
with b4_uint_type, ANY argument larger than 65535 will cause a fatal
m4 error (because 4294967295 == -1 mod 2**32).
The simplest solution (albeit kludgy) is simply not to test for the
problematic cases, as indicated in the patch below. It is unlikely
that one would ever trip over these particular errors, after all.
Technically, I think there is another problem here, although I don't
have an up-to-date C standard to check---the type 'int' is not really
guaranteed to have 32 bits; 'long int' is. I don't know, however,
that this is an issue with any C implementation.
Paul Hilfinger
P.S. I am posting this for approval rather than just doing it since
(1) it is not specific to the stuff I'm working on, and (2) as a
newbie to this group, I prefer caution.
------------------------------------------------------------
2002-05-05 Paul Hilfinger <address@hidden>
* data/bison.simple (b4_sint_type, b4_uint_type): Correct to reflect
32-bit arithmetic.
* data/bison.c++ (b4_sint_type, b4_uint_type): Ditto.
Index: 2.8/data/bison.simple
--- 2.8/data/bison.simple Sun, 05 May 2002 16:11:30 -0700 hilfingr
(glrbison/37_bison.simp 1.1.1.2 644)
+++ 2.8(w)/data/bison.simple Sun, 05 May 2002 18:14:33 -0700 hilfingr
(glrbison/37_bison.simp 1.1.1.2 644)
@@ -6,8 +6,7 @@ m4_divert(-1)
m4_define([b4_sint_type],
[m4_if(m4_eval([$1 <= 127]), [1], [signed char],
m4_eval([$1 <= 32767]), [1], [signed short],
- m4_eval([$1 <= 2147483647]), [1], [signed int],
- [m4_fatal([no signed int type for $1])])])
+ [signed int])])
# b4_uint_type(MAX)
@@ -16,8 +15,7 @@ m4_define([b4_sint_type],
m4_define([b4_uint_type],
[m4_if(m4_eval([$1 <= 255]), [1], [unsigned char],
m4_eval([$1 <= 65535]), [1], [unsigned short],
- m4_eval([$1 <= 4294967295]), [1], [unsigned int],
- [m4_fatal([no unsigned int type for $1])])])
+ [unsigned int])])
# b4_lhs_value([TYPE])
Index: 2.8/data/bison.c++
--- 2.8/data/bison.c++ Sun, 05 May 2002 16:11:30 -0700 hilfingr
(glrbison/f/44_bison.c++ 1.2 644)
+++ 2.8(w)/data/bison.c++ Sun, 05 May 2002 18:22:10 -0700 hilfingr
(glrbison/f/44_bison.c++ 1.2 644)
@@ -6,8 +6,7 @@ m4_divert(-1)
m4_define([b4_sint_type],
[m4_if(m4_eval([$1 <= 127]), [1], [signed char],
m4_eval([$1 <= 32767]), [1], [signed short],
- m4_eval([$1 <= 2147483647]), [1], [signed int],
- [m4_fatal([no signed int type for $1])])])
+ [signed int])])
# b4_uint_type(MAX)
@@ -16,8 +15,7 @@ m4_define([b4_sint_type],
m4_define([b4_uint_type],
[m4_if(m4_eval([$1 <= 255]), [1], [unsigned char],
m4_eval([$1 <= 65535]), [1], [unsigned short],
- m4_eval([$1 <= 4294967295]), [1], [unsigned int],
- [m4_fatal([no unsigned int type for $1])])])
+ [unsigned int])])
# b4_lhs_value([TYPE])
- Patch b4_uint_type and b4_sint_type range problem,
Paul Hilfinger <=