Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
ast27: prefix exported symbols (#152)
Browse files Browse the repository at this point in the history
Fixes #151 and fixes #139

Linking shenanigans caused ast27 to link against Python's asdl.c, instead of ast27/Python/asdl.c. Python's asdl.c uses Py_ssize_t for asdl_seq's size whereas ast27/Python/asdl.c uses int. This means we were interpreting memory differently in asdl.c and ast.c. On 64-bit big-endian systems, this caused us to misplace asdl.c's writes to asdl_seq->size, since Py_ssize_t is eight bytes, but int is four. The fix mirrors what we do in ast3, that is, manually namespace definitions to avoid linking conflicts.

Co-authored-by: hauntsaninja <>
  • Loading branch information
hauntsaninja committed Dec 30, 2020
1 parent 63167ac commit 58cae99
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
9 changes: 2 additions & 7 deletions ast27/Include/asdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ typedef struct {
int elements[1];
} asdl_int_seq;

#if PY_MINOR_VERSION > 3
#define asdl_seq_new _Py_asdl_seq_new
#define asdl_int_seq_new _Py_asdl_int_seq_new
#else
#define _Py_asdl_seq_new asdl_seq_new
#define _Py_asdl_int_seq_new asdl_int_seq_new
#endif
#define asdl_seq_new _Ta27_asdl_seq_new
#define asdl_int_seq_new _Ta27_asdl_int_seq_new
asdl_seq *asdl_seq_new(Py_ssize_t size, PyArena *arena);
asdl_int_seq *asdl_int_seq_new(Py_ssize_t size, PyArena *arena);

Expand Down
4 changes: 2 additions & 2 deletions ast27/Python/asdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "../Include/asdl.h"

asdl_seq *
_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena)
_Ta27_asdl_seq_new(Py_ssize_t size, PyArena *arena)
{
asdl_seq *seq = NULL;
size_t n;
Expand Down Expand Up @@ -33,7 +33,7 @@ _Py_asdl_seq_new(Py_ssize_t size, PyArena *arena)
}

asdl_int_seq *
_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena)
_Ta27_asdl_int_seq_new(Py_ssize_t size, PyArena *arena)
{
asdl_int_seq *seq = NULL;
size_t n;
Expand Down
6 changes: 3 additions & 3 deletions ast27/Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ Ta27AST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename,
ch = CHILD(n, NCH(n) - 1);
REQ(ch, ENDMARKER);
num = NCH(ch);
type_ignores = _Py_asdl_seq_new(num, arena);
type_ignores = _Ta27_asdl_seq_new(num, arena);
if (!type_ignores)
goto error;

Expand Down Expand Up @@ -368,7 +368,7 @@ Ta27AST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename,
num++;
}

argtypes = _Py_asdl_seq_new(num, arena);
argtypes = _Ta27_asdl_seq_new(num, arena);

j = 0;
for (i = 0; i < NCH(ch); i++) {
Expand All @@ -381,7 +381,7 @@ Ta27AST_FromNode(const node *n, PyCompilerFlags *flags, const char *filename,
}
}
else
argtypes = _Py_asdl_seq_new(0, arena);
argtypes = _Ta27_asdl_seq_new(0, arena);

ret = ast_for_expr(&c, CHILD(n, NCH(n) - 1));
if (!ret)
Expand Down

0 comments on commit 58cae99

Please sign in to comment.