Skip to content
Snippets Groups Projects
Commit ad363913 authored by Mathieu Bridon's avatar Mathieu Bridon Committed by Eric Engestrom
Browse files

python: Explicitly add the 'L' suffix on Python 3


Python 2 had two integer types: int and long. Python 3 dropped the
latter, as it made the int type automatically support bigger numbers.

As a result, Python 3 lost the 'L' suffix on integer litterals.

This probably doesn't make much difference when compiling the generated
C code, but adding it explicitly means that both Python 2 and 3 generate
the exact same C code anyway, which makes it easier to compare and check
for discrepencies when moving to Python 3.

Signed-off-by: default avatarMathieu Bridon <bochecha@daitauha.fr>
Reviewed-by: default avatarDylan Baker <dylan@pnwbakers.com>
parent a71df208
No related branches found
No related tags found
Loading
......@@ -139,7 +139,16 @@ class Constant(Value):
if isinstance(self.value, (int, long)):
return hex(self.value)
elif isinstance(self.value, float):
return hex(struct.unpack('Q', struct.pack('d', self.value))[0])
i = struct.unpack('Q', struct.pack('d', self.value))[0]
h = hex(i)
# On Python 2 this 'L' suffix is automatically added, but not on Python 3
# Adding it explicitly makes the generated file identical, regardless
# of the Python version running this script.
if h[-1] != 'L' and i > sys.maxsize:
h += 'L'
return h
else:
assert False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment