Skip to content

Commit cc10a37

Browse files
committed
Widen ASDL sequences to Py_ssize_t lengths to better match PEP 353.
1 parent 33cac85 commit cc10a37

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Include/asdl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ typedef PyObject * object;
1515
/* XXX A sequence should be typed so that its use can be typechecked. */
1616

1717
typedef struct {
18-
int size;
18+
Py_ssize_t size;
1919
void *elements[1];
2020
} asdl_seq;
2121

2222
typedef struct {
23-
int size;
23+
Py_ssize_t size;
2424
int elements[1];
2525
} asdl_int_seq;
2626

27-
asdl_seq *asdl_seq_new(int size, PyArena *arena);
28-
asdl_int_seq *asdl_int_seq_new(int size, PyArena *arena);
27+
asdl_seq *asdl_seq_new(Py_ssize_t size, PyArena *arena);
28+
asdl_int_seq *asdl_int_seq_new(Py_ssize_t size, PyArena *arena);
2929

3030
#define asdl_seq_GET(S, I) (S)->elements[(I)]
3131
#define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size)

Python/Python-ast.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ static int add_attributes(PyTypeObject* type, char**attrs, int num_fields)
636636

637637
static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
638638
{
639-
int i, n = asdl_seq_LEN(seq);
639+
Py_ssize_t i, n = asdl_seq_LEN(seq);
640640
PyObject *result = PyList_New(n);
641641
PyObject *value;
642642
if (!result)
@@ -2857,7 +2857,7 @@ ast2obj_expr(void* _o)
28572857
goto failed;
28582858
Py_DECREF(value);
28592859
{
2860-
int i, n = asdl_seq_LEN(o->v.Compare.ops);
2860+
Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
28612861
value = PyList_New(n);
28622862
if (!value) goto failed;
28632863
for(i = 0; i < n; i++)

Python/asdl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "asdl.h"
33

44
asdl_seq *
5-
asdl_seq_new(int size, PyArena *arena)
5+
asdl_seq_new(Py_ssize_t size, PyArena *arena)
66
{
77
asdl_seq *seq = NULL;
88
size_t n = (size ? (sizeof(void *) * (size - 1)) : 0);
@@ -33,7 +33,7 @@ asdl_seq_new(int size, PyArena *arena)
3333
}
3434

3535
asdl_int_seq *
36-
asdl_int_seq_new(int size, PyArena *arena)
36+
asdl_int_seq_new(Py_ssize_t size, PyArena *arena)
3737
{
3838
asdl_int_seq *seq = NULL;
3939
size_t n = (size ? (sizeof(void *) * (size - 1)) : 0);

0 commit comments

Comments
 (0)