Skip to content

Commit 73db921

Browse files
author
neal.norwitz
committed
On 64 bit systems, int literals that use less than 64 bits are now ints
rather than longs. This also fixes the test for eval(-sys.maxint - 1). git-svn-id: http://svn.python.org/projects/python/trunk@50497 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 4cd48b9 commit 73db921

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

Lib/test/test_compile.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,21 @@ def test_unary_minus(self):
216216
self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 1)), int))
217217
self.assertTrue(isinstance(eval("%s" % (-sys.maxint - 2)), long))
218218

219+
if sys.maxint == 9223372036854775807:
220+
def test_32_63_bit_values(self):
221+
a = +4294967296 # 1 << 32
222+
b = -4294967296 # 1 << 32
223+
c = +281474976710656 # 1 << 48
224+
d = -281474976710656 # 1 << 48
225+
e = +4611686018427387904 # 1 << 62
226+
f = -4611686018427387904 # 1 << 62
227+
g = +9223372036854775807 # 1 << 63 - 1
228+
h = -9223372036854775807 # 1 << 63 - 1
229+
230+
for variable in self.test_32_63_bit_values.func_code.co_consts:
231+
if variable is not None:
232+
self.assertTrue(isinstance(variable, int))
233+
219234
def test_sequence_unpacking_error(self):
220235
# Verify sequence packing/unpacking with "or". SF bug #757818
221236
i,j = (1, -1) or (-1, 1)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Core and builtins
3030

3131
- Bug #1519018: 'as' is now validated properly in import statements.
3232

33+
- On 64 bit systems, int literals that use less than 64 bits are
34+
now ints rather than longs.
35+
3336
Library
3437
-------
3538

Python/mystrtoul.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,22 @@ static unsigned long smallmax[] = {
6969
* calculated by [int(math.floor(math.log(2**32, i))) for i in range(2, 37)].
7070
* Note that this is pessimistic if sizeof(long) > 4.
7171
*/
72+
#if SIZEOF_LONG == 4
7273
static int digitlimit[] = {
7374
0, 0, 32, 20, 16, 13, 12, 11, 10, 10, /* 0 - 9 */
7475
9, 9, 8, 8, 8, 8, 8, 7, 7, 7, /* 10 - 19 */
7576
7, 7, 7, 7, 6, 6, 6, 6, 6, 6, /* 20 - 29 */
7677
6, 6, 6, 6, 6, 6, 6}; /* 30 - 36 */
78+
#elif SIZEOF_LONG == 8
79+
/* [int(math.floor(math.log(2**64, i))) for i in range(2, 37)] */
80+
static int digitlimit[] = {
81+
0, 0, 64, 40, 32, 27, 24, 22, 21, 20, /* 0 - 9 */
82+
19, 18, 17, 17, 16, 16, 16, 15, 15, 15, /* 10 - 19 */
83+
14, 14, 14, 14, 13, 13, 13, 13, 13, 13, /* 20 - 29 */
84+
13, 12, 12, 12, 12, 12, 12}; /* 30 - 36 */
85+
#else
86+
#error "Need table for SIZEOF_LONG"
87+
#endif
7788

7889
/*
7990
** strtoul

0 commit comments

Comments
 (0)