Closed hauntsaninja closed 3 years ago
I can confirm this fixes both the ppc64 and the s390x builds / tests that we perform in openSUSE for packaging! Thanks for your work!
Is there a reason for the difference between typed_ast's and Python's asdl.c? Could there (shudders) be a bug in typed_ast that comes up only if you try to make a tuple with more than INT_MAX elements?
@JelleZijlstra The struct has the same declaration in ast27/Python/asdl.c
as in Python 2.7's asdl.c
, so if there is an issue in parsing a file with more than INT_MAX of a thing, it probably applies to Python 2.7 as well.
...That said, it looks like there is a difference in the signature of asdl_seq_new
. In ast27, it's: asdl_seq *asdl_seq_new(Py_ssize_t size, PyArena *arena);
whereas in Python 2.7 it's asdl_seq *asdl_seq_new(int size, PyArena *arena);
. This goes back to a3f63eb6, which introduced ast27/Python/asdl.c
. I'm not sure this matters, but I can change it for consistency and peaceful sleep.
Finally, looking at the macros also made me realise that ast27's ast.c currently prefers to use the macro asdl_seq_new instead of _Ta27_asdl_seq_new. On the other hand, being clever and not using obviously namespaced symbols is what caused the bug, so maybe I should get rid of the asdl_seq_new macro altogether. On the third hand, this PR has already been tested on various systems I don't have access to and so I'm reluctant to do refactoring solely for style.
Let me know!
Thanks for the explanation! It's probably not worth it to go through any more refactoring for Python 2.7 code—let's just let 2.7 die a peaceful death.
As far as I can tell https://github.com/python/typed_ast/blob/master/release_process.md is up to date, other than missing a mention of Python 3.9 (and 3.5? setup.py claims to support it still, as does mypy, so we should probably still build a macOS wheel) :-)
Fixes #151 and (probably) fixes #139
Linking shenanigans caused ast27 to link against Python's
asdl.c
, instead ofast27/Python/asdl.c
. Python'sasdl.c
usesPy_ssize_t
forasdl_seq
's size whereasast27/Python/asdl.c
usesint
. This means we were interpreting memory differently inasdl.c
andast.c
. On 64-bit big-endian systems, this caused us to misplaceasdl.c
's writes toasdl_seq->size
, sincePy_ssize_t
is eight bytes, butint
is four. The fix mirrors what we do in ast3, that is, manually namespace definitions to avoid linking conflicts.