bpo-43244: Remove the pyarena.h header (GH-25007)

Remove the pyarena.h header file with functions:

* PyArena_New()
* PyArena_Free()
* PyArena_Malloc()
* PyArena_AddPyObject()

These functions were undocumented, excluded from the limited C API,
and were only used internally by the compiler.

Add pycore_pyarena.h header. Rename functions:

* PyArena_New() => _PyArena_New()
* PyArena_Free() => _PyArena_Free()
* PyArena_Malloc() => _PyArena_Malloc()
* PyArena_AddPyObject() => _PyArena_AddPyObject()
This commit is contained in:
Victor Stinner 2021-03-24 02:23:01 +01:00 committed by GitHub
parent 919d42d477
commit 8370e07e1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 215 additions and 187 deletions

View File

@ -1419,3 +1419,14 @@ Removed
These functions were undocumented and excluded from the limited C API. These functions were undocumented and excluded from the limited C API.
(Contributed by Victor Stinner in :issue:`43244`.) (Contributed by Victor Stinner in :issue:`43244`.)
* Remove the ``pyarena.h`` header file with functions:
* ``PyArena_New()``
* ``PyArena_Free()``
* ``PyArena_Malloc()``
* ``PyArena_AddPyObject()``
These functions were undocumented, excluded from the limited C API, and were
only used internally by the compiler.
(Contributed by Victor Stinner in :issue:`43244`.)

View File

@ -137,7 +137,6 @@
#include "pystate.h" #include "pystate.h"
#include "context.h" #include "context.h"
#include "cpython/pyarena.h"
#include "modsupport.h" #include "modsupport.h"
#include "compile.h" #include "compile.h"
#include "pythonrun.h" #include "pythonrun.h"

View File

@ -1,64 +0,0 @@
/* An arena-like memory interface for the compiler.
*/
#ifndef Py_LIMITED_API
#ifndef Py_PYARENA_H
#define Py_PYARENA_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _arena PyArena;
/* PyArena_New() and PyArena_Free() create a new arena and free it,
respectively. Once an arena has been created, it can be used
to allocate memory via PyArena_Malloc(). Pointers to PyObject can
also be registered with the arena via PyArena_AddPyObject(), and the
arena will ensure that the PyObjects stay alive at least until
PyArena_Free() is called. When an arena is freed, all the memory it
allocated is freed, the arena releases internal references to registered
PyObject*, and none of its pointers are valid.
XXX (tim) What does "none of its pointers are valid" mean? Does it
XXX mean that pointers previously obtained via PyArena_Malloc() are
XXX no longer valid? (That's clearly true, but not sure that's what
XXX the text is trying to say.)
PyArena_New() returns an arena pointer. On error, it
returns a negative number and sets an exception.
XXX (tim): Not true. On error, PyArena_New() actually returns NULL,
XXX and looks like it may or may not set an exception (e.g., if the
XXX internal PyList_New(0) returns NULL, PyArena_New() passes that on
XXX and an exception is set; OTOH, if the internal
XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but
XXX an exception is not set in that case).
*/
PyAPI_FUNC(PyArena *) PyArena_New(void);
PyAPI_FUNC(void) PyArena_Free(PyArena *);
/* Mostly like malloc(), return the address of a block of memory spanning
* `size` bytes, or return NULL (without setting an exception) if enough
* new memory can't be obtained. Unlike malloc(0), PyArena_Malloc() with
* size=0 does not guarantee to return a unique pointer (the pointer
* returned may equal one or more other pointers obtained from
* PyArena_Malloc()).
* Note that pointers obtained via PyArena_Malloc() must never be passed to
* the system free() or realloc(), or to any of Python's similar memory-
* management functions. PyArena_Malloc()-obtained pointers remain valid
* until PyArena_Free(ar) is called, at which point all pointers obtained
* from the arena `ar` become invalid simultaneously.
*/
PyAPI_FUNC(void *) PyArena_Malloc(PyArena *, size_t size);
/* This routine isn't a proper arena allocation routine. It takes
* a PyObject* and records it so that it can be DECREFed when the
* arena is freed.
*/
PyAPI_FUNC(int) PyArena_AddPyObject(PyArena *, PyObject *);
#ifdef __cplusplus
}
#endif
#endif /* !Py_PYARENA_H */
#endif /* Py_LIMITED_API */

View File

@ -8,6 +8,8 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define" # error "this header requires Py_BUILD_CORE define"
#endif #endif
#include "pycore_pyarena.h" // _PyArena_Malloc()
typedef PyObject * identifier; typedef PyObject * identifier;
typedef PyObject * string; typedef PyObject * string;
typedef PyObject * object; typedef PyObject * object;
@ -65,7 +67,7 @@ asdl_ ## NAME ## _seq *_Py_asdl_ ## NAME ## _seq_new(Py_ssize_t size, PyArena *a
return NULL; \ return NULL; \
} \ } \
n += sizeof(asdl_ ## NAME ## _seq); \ n += sizeof(asdl_ ## NAME ## _seq); \
seq = (asdl_ ## NAME ## _seq *)PyArena_Malloc(arena, n); \ seq = (asdl_ ## NAME ## _seq *)_PyArena_Malloc(arena, n); \
if (!seq) { \ if (!seq) { \
PyErr_NoMemory(); \ PyErr_NoMemory(); \
return NULL; \ return NULL; \

View File

@ -8,7 +8,8 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define" # error "this header requires Py_BUILD_CORE define"
#endif #endif
struct _mod; // Type defined in pycore_ast.h struct _arena; // Type defined in pycore_pyarena.h
struct _mod; // Type defined in pycore_ast.h
// Export the symbol for test_peg_generator (built as a library) // Export the symbol for test_peg_generator (built as a library)
PyAPI_FUNC(PyCodeObject*) _PyAST_Compile( PyAPI_FUNC(PyCodeObject*) _PyAST_Compile(
@ -16,7 +17,7 @@ PyAPI_FUNC(PyCodeObject*) _PyAST_Compile(
PyObject *filename, PyObject *filename,
PyCompilerFlags *flags, PyCompilerFlags *flags,
int optimize, int optimize,
PyArena *arena); struct _arena *arena);
extern PyFutureFeatures* _PyFuture_FromAST( extern PyFutureFeatures* _PyFuture_FromAST(
struct _mod * mod, struct _mod * mod,
PyObject *filename PyObject *filename
@ -31,7 +32,7 @@ typedef struct {
extern int _PyAST_Optimize( extern int _PyAST_Optimize(
struct _mod *, struct _mod *,
PyArena *arena, struct _arena *arena,
_PyASTOptimizeState *state); _PyASTOptimizeState *state);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -0,0 +1,64 @@
/* An arena-like memory interface for the compiler.
*/
#ifndef Py_INTERNAL_PYARENA_H
#define Py_INTERNAL_PYARENA_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif
typedef struct _arena PyArena;
/* _PyArena_New() and _PyArena_Free() create a new arena and free it,
respectively. Once an arena has been created, it can be used
to allocate memory via _PyArena_Malloc(). Pointers to PyObject can
also be registered with the arena via _PyArena_AddPyObject(), and the
arena will ensure that the PyObjects stay alive at least until
_PyArena_Free() is called. When an arena is freed, all the memory it
allocated is freed, the arena releases internal references to registered
PyObject*, and none of its pointers are valid.
XXX (tim) What does "none of its pointers are valid" mean? Does it
XXX mean that pointers previously obtained via _PyArena_Malloc() are
XXX no longer valid? (That's clearly true, but not sure that's what
XXX the text is trying to say.)
_PyArena_New() returns an arena pointer. On error, it
returns a negative number and sets an exception.
XXX (tim): Not true. On error, _PyArena_New() actually returns NULL,
XXX and looks like it may or may not set an exception (e.g., if the
XXX internal PyList_New(0) returns NULL, _PyArena_New() passes that on
XXX and an exception is set; OTOH, if the internal
XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but
XXX an exception is not set in that case).
*/
PyAPI_FUNC(PyArena*) _PyArena_New(void);
PyAPI_FUNC(void) _PyArena_Free(PyArena *);
/* Mostly like malloc(), return the address of a block of memory spanning
* `size` bytes, or return NULL (without setting an exception) if enough
* new memory can't be obtained. Unlike malloc(0), _PyArena_Malloc() with
* size=0 does not guarantee to return a unique pointer (the pointer
* returned may equal one or more other pointers obtained from
* _PyArena_Malloc()).
* Note that pointers obtained via _PyArena_Malloc() must never be passed to
* the system free() or realloc(), or to any of Python's similar memory-
* management functions. _PyArena_Malloc()-obtained pointers remain valid
* until _PyArena_Free(ar) is called, at which point all pointers obtained
* from the arena `ar` become invalid simultaneously.
*/
PyAPI_FUNC(void*) _PyArena_Malloc(PyArena *, size_t size);
/* This routine isn't a proper arena allocation routine. It takes
* a PyObject* and records it so that it can be DECREFed when the
* arena is freed.
*/
PyAPI_FUNC(int) _PyArena_AddPyObject(PyArena *, PyObject *);
#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_PYARENA_H */

View File

@ -1119,7 +1119,6 @@ PYTHON_HEADERS= \
$(srcdir)/Include/cpython/objimpl.h \ $(srcdir)/Include/cpython/objimpl.h \
$(srcdir)/Include/cpython/odictobject.h \ $(srcdir)/Include/cpython/odictobject.h \
$(srcdir)/Include/cpython/picklebufobject.h \ $(srcdir)/Include/cpython/picklebufobject.h \
$(srcdir)/Include/cpython/pyarena.h \
$(srcdir)/Include/cpython/pyctype.h \ $(srcdir)/Include/cpython/pyctype.h \
$(srcdir)/Include/cpython/pydebug.h \ $(srcdir)/Include/cpython/pydebug.h \
$(srcdir)/Include/cpython/pyerrors.h \ $(srcdir)/Include/cpython/pyerrors.h \
@ -1163,6 +1162,7 @@ PYTHON_HEADERS= \
$(srcdir)/Include/internal/pycore_long.h \ $(srcdir)/Include/internal/pycore_long.h \
$(srcdir)/Include/internal/pycore_object.h \ $(srcdir)/Include/internal/pycore_object.h \
$(srcdir)/Include/internal/pycore_pathconfig.h \ $(srcdir)/Include/internal/pycore_pathconfig.h \
$(srcdir)/Include/internal/pycore_pyarena.h \
$(srcdir)/Include/internal/pycore_pyerrors.h \ $(srcdir)/Include/internal/pycore_pyerrors.h \
$(srcdir)/Include/internal/pycore_pyhash.h \ $(srcdir)/Include/internal/pycore_pyhash.h \
$(srcdir)/Include/internal/pycore_pylifecycle.h \ $(srcdir)/Include/internal/pycore_pylifecycle.h \

View File

@ -0,0 +1,10 @@
Remove the ``pyarena.h`` header file with functions:
* ``PyArena_New()``
* ``PyArena_Free()``
* ``PyArena_Malloc()``
* ``PyArena_AddPyObject()``
These functions were undocumented, excluded from the limited C API, and were
only used internally by the compiler.
Patch by Victor Stinner.

View File

@ -201,6 +201,7 @@
<ClInclude Include="..\Include\internal\pycore_long.h" /> <ClInclude Include="..\Include\internal\pycore_long.h" />
<ClInclude Include="..\Include\internal\pycore_object.h" /> <ClInclude Include="..\Include\internal\pycore_object.h" />
<ClInclude Include="..\Include\internal\pycore_pathconfig.h" /> <ClInclude Include="..\Include\internal\pycore_pathconfig.h" />
<ClInclude Include="..\Include\internal\pycore_pyarena.h" />
<ClInclude Include="..\Include\internal\pycore_pyerrors.h" /> <ClInclude Include="..\Include\internal\pycore_pyerrors.h" />
<ClInclude Include="..\Include\internal\pycore_pyhash.h" /> <ClInclude Include="..\Include\internal\pycore_pyhash.h" />
<ClInclude Include="..\Include\internal\pycore_pylifecycle.h" /> <ClInclude Include="..\Include\internal\pycore_pylifecycle.h" />

View File

@ -564,6 +564,9 @@
<ClInclude Include="..\Include\internal\pycore_pathconfig.h"> <ClInclude Include="..\Include\internal\pycore_pathconfig.h">
<Filter>Include\internal</Filter> <Filter>Include\internal</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\Include\internal\pycore_pyarena.h">
<Filter>Include\internal</Filter>
</ClInclude>
<ClInclude Include="..\Include\internal\pycore_pyerrors.h"> <ClInclude Include="..\Include\internal\pycore_pyerrors.h">
<Filter>Include\internal</Filter> <Filter>Include\internal</Filter>
</ClInclude> </ClInclude>

View File

@ -362,7 +362,7 @@ class FunctionVisitor(PrototypeVisitor):
emit('return NULL;', 2) emit('return NULL;', 2)
emit('}', 1) emit('}', 1)
emit("p = (%s)PyArena_Malloc(arena, sizeof(*p));" % ctype, 1); emit("p = (%s)_PyArena_Malloc(arena, sizeof(*p));" % ctype, 1);
emit("if (!p)", 1) emit("if (!p)", 1)
emit("return NULL;", 2) emit("return NULL;", 2)
if union: if union:
@ -946,7 +946,7 @@ static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyO
if (obj == Py_None) if (obj == Py_None)
obj = NULL; obj = NULL;
if (obj) { if (obj) {
if (PyArena_AddPyObject(arena, obj) < 0) { if (_PyArena_AddPyObject(arena, obj) < 0) {
*out = NULL; *out = NULL;
return -1; return -1;
} }
@ -958,7 +958,7 @@ static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyO
static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena) static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
{ {
if (PyArena_AddPyObject(arena, obj) < 0) { if (_PyArena_AddPyObject(arena, obj) < 0) {
*out = NULL; *out = NULL;
return -1; return -1;
} }

View File

@ -13,7 +13,7 @@ _PyPegen_new_type_comment(Parser *p, char *s)
if (res == NULL) { if (res == NULL) {
return NULL; return NULL;
} }
if (PyArena_AddPyObject(p->arena, res) < 0) { if (_PyArena_AddPyObject(p->arena, res) < 0) {
Py_DECREF(res); Py_DECREF(res);
return NULL; return NULL;
} }
@ -121,7 +121,7 @@ _PyPegen_new_identifier(Parser *p, char *n)
id = id2; id = id2;
} }
PyUnicode_InternInPlace(&id); PyUnicode_InternInPlace(&id);
if (PyArena_AddPyObject(p->arena, id) < 0) if (_PyArena_AddPyObject(p->arena, id) < 0)
{ {
Py_DECREF(id); Py_DECREF(id);
goto error; goto error;
@ -526,7 +526,7 @@ int
_PyPegen_insert_memo(Parser *p, int mark, int type, void *node) _PyPegen_insert_memo(Parser *p, int mark, int type, void *node)
{ {
// Insert in front // Insert in front
Memo *m = PyArena_Malloc(p->arena, sizeof(Memo)); Memo *m = _PyArena_Malloc(p->arena, sizeof(Memo));
if (m == NULL) { if (m == NULL) {
return -1; return -1;
} }
@ -690,7 +690,7 @@ _PyPegen_fill_token(Parser *p)
if (t->bytes == NULL) { if (t->bytes == NULL) {
return -1; return -1;
} }
PyArena_AddPyObject(p->arena, t->bytes); _PyArena_AddPyObject(p->arena, t->bytes);
int lineno = type == STRING ? p->tok->first_lineno : p->tok->lineno; int lineno = type == STRING ? p->tok->first_lineno : p->tok->lineno;
const char *line_start = type == STRING ? p->tok->multi_line_start : p->tok->line_start; const char *line_start = type == STRING ? p->tok->multi_line_start : p->tok->line_start;
@ -1029,7 +1029,7 @@ _PyPegen_number_token(Parser *p)
return NULL; return NULL;
} }
if (PyArena_AddPyObject(p->arena, c) < 0) { if (_PyArena_AddPyObject(p->arena, c) < 0) {
Py_DECREF(c); Py_DECREF(c);
p->error_indicator = 1; p->error_indicator = 1;
return NULL; return NULL;
@ -1509,7 +1509,7 @@ _PyPegen_join_names_with_dot(Parser *p, expr_ty first_name, expr_ty second_name)
return NULL; return NULL;
} }
PyUnicode_InternInPlace(&uni); PyUnicode_InternInPlace(&uni);
if (PyArena_AddPyObject(p->arena, uni) < 0) { if (_PyArena_AddPyObject(p->arena, uni) < 0) {
Py_DECREF(uni); Py_DECREF(uni);
return NULL; return NULL;
} }
@ -1547,7 +1547,7 @@ _PyPegen_alias_for_star(Parser *p)
if (!str) { if (!str) {
return NULL; return NULL;
} }
if (PyArena_AddPyObject(p->arena, str) < 0) { if (_PyArena_AddPyObject(p->arena, str) < 0) {
Py_DECREF(str); Py_DECREF(str);
return NULL; return NULL;
} }
@ -1577,7 +1577,7 @@ CmpopExprPair *
_PyPegen_cmpop_expr_pair(Parser *p, cmpop_ty cmpop, expr_ty expr) _PyPegen_cmpop_expr_pair(Parser *p, cmpop_ty cmpop, expr_ty expr)
{ {
assert(expr != NULL); assert(expr != NULL);
CmpopExprPair *a = PyArena_Malloc(p->arena, sizeof(CmpopExprPair)); CmpopExprPair *a = _PyArena_Malloc(p->arena, sizeof(CmpopExprPair));
if (!a) { if (!a) {
return NULL; return NULL;
} }
@ -1718,7 +1718,7 @@ _PyPegen_set_expr_context(Parser *p, expr_ty expr, expr_context_ty ctx)
KeyValuePair * KeyValuePair *
_PyPegen_key_value_pair(Parser *p, expr_ty key, expr_ty value) _PyPegen_key_value_pair(Parser *p, expr_ty key, expr_ty value)
{ {
KeyValuePair *a = PyArena_Malloc(p->arena, sizeof(KeyValuePair)); KeyValuePair *a = _PyArena_Malloc(p->arena, sizeof(KeyValuePair));
if (!a) { if (!a) {
return NULL; return NULL;
} }
@ -1763,7 +1763,7 @@ _PyPegen_get_values(Parser *p, asdl_seq *seq)
NameDefaultPair * NameDefaultPair *
_PyPegen_name_default_pair(Parser *p, arg_ty arg, expr_ty value, Token *tc) _PyPegen_name_default_pair(Parser *p, arg_ty arg, expr_ty value, Token *tc)
{ {
NameDefaultPair *a = PyArena_Malloc(p->arena, sizeof(NameDefaultPair)); NameDefaultPair *a = _PyArena_Malloc(p->arena, sizeof(NameDefaultPair));
if (!a) { if (!a) {
return NULL; return NULL;
} }
@ -1776,7 +1776,7 @@ _PyPegen_name_default_pair(Parser *p, arg_ty arg, expr_ty value, Token *tc)
SlashWithDefault * SlashWithDefault *
_PyPegen_slash_with_default(Parser *p, asdl_arg_seq *plain_names, asdl_seq *names_with_defaults) _PyPegen_slash_with_default(Parser *p, asdl_arg_seq *plain_names, asdl_seq *names_with_defaults)
{ {
SlashWithDefault *a = PyArena_Malloc(p->arena, sizeof(SlashWithDefault)); SlashWithDefault *a = _PyArena_Malloc(p->arena, sizeof(SlashWithDefault));
if (!a) { if (!a) {
return NULL; return NULL;
} }
@ -1789,7 +1789,7 @@ _PyPegen_slash_with_default(Parser *p, asdl_arg_seq *plain_names, asdl_seq *name
StarEtc * StarEtc *
_PyPegen_star_etc(Parser *p, arg_ty vararg, asdl_seq *kwonlyargs, arg_ty kwarg) _PyPegen_star_etc(Parser *p, arg_ty vararg, asdl_seq *kwonlyargs, arg_ty kwarg)
{ {
StarEtc *a = PyArena_Malloc(p->arena, sizeof(StarEtc)); StarEtc *a = _PyArena_Malloc(p->arena, sizeof(StarEtc));
if (!a) { if (!a) {
return NULL; return NULL;
} }
@ -2025,7 +2025,7 @@ _PyPegen_empty_arguments(Parser *p)
AugOperator * AugOperator *
_PyPegen_augoperator(Parser *p, operator_ty kind) _PyPegen_augoperator(Parser *p, operator_ty kind)
{ {
AugOperator *a = PyArena_Malloc(p->arena, sizeof(AugOperator)); AugOperator *a = _PyArena_Malloc(p->arena, sizeof(AugOperator));
if (!a) { if (!a) {
return NULL; return NULL;
} }
@ -2070,7 +2070,7 @@ _PyPegen_class_def_decorators(Parser *p, asdl_expr_seq *decorators, stmt_ty clas
KeywordOrStarred * KeywordOrStarred *
_PyPegen_keyword_or_starred(Parser *p, void *element, int is_keyword) _PyPegen_keyword_or_starred(Parser *p, void *element, int is_keyword)
{ {
KeywordOrStarred *a = PyArena_Malloc(p->arena, sizeof(KeywordOrStarred)); KeywordOrStarred *a = _PyArena_Malloc(p->arena, sizeof(KeywordOrStarred));
if (!a) { if (!a) {
return NULL; return NULL;
} }
@ -2211,7 +2211,7 @@ _PyPegen_concatenate_strings(Parser *p, asdl_seq *strings)
} }
if (bytesmode) { if (bytesmode) {
if (PyArena_AddPyObject(p->arena, bytes_str) < 0) { if (_PyArena_AddPyObject(p->arena, bytes_str) < 0) {
goto error; goto error;
} }
return Constant(bytes_str, NULL, first->lineno, first->col_offset, last->end_lineno, return Constant(bytes_str, NULL, first->lineno, first->col_offset, last->end_lineno,

View File

@ -1031,7 +1031,7 @@ make_str_node_and_del(Parser *p, PyObject **str, Token* first_token, Token *last
PyObject *kind = NULL; PyObject *kind = NULL;
*str = NULL; *str = NULL;
assert(PyUnicode_CheckExact(s)); assert(PyUnicode_CheckExact(s));
if (PyArena_AddPyObject(p->arena, s) < 0) { if (_PyArena_AddPyObject(p->arena, s) < 0) {
Py_DECREF(s); Py_DECREF(s);
return NULL; return NULL;
} }

140
Python/Python-ast.c generated
View File

@ -961,7 +961,7 @@ static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyO
if (obj == Py_None) if (obj == Py_None)
obj = NULL; obj = NULL;
if (obj) { if (obj) {
if (PyArena_AddPyObject(arena, obj) < 0) { if (_PyArena_AddPyObject(arena, obj) < 0) {
*out = NULL; *out = NULL;
return -1; return -1;
} }
@ -973,7 +973,7 @@ static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyO
static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena) static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
{ {
if (PyArena_AddPyObject(arena, obj) < 0) { if (_PyArena_AddPyObject(arena, obj) < 0) {
*out = NULL; *out = NULL;
return -1; return -1;
} }
@ -1787,7 +1787,7 @@ Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores, PyArena
*arena) *arena)
{ {
mod_ty p; mod_ty p;
p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Module_kind; p->kind = Module_kind;
@ -1800,7 +1800,7 @@ mod_ty
Interactive(asdl_stmt_seq * body, PyArena *arena) Interactive(asdl_stmt_seq * body, PyArena *arena)
{ {
mod_ty p; mod_ty p;
p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Interactive_kind; p->kind = Interactive_kind;
@ -1817,7 +1817,7 @@ Expression(expr_ty body, PyArena *arena)
"field 'body' is required for Expression"); "field 'body' is required for Expression");
return NULL; return NULL;
} }
p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Expression_kind; p->kind = Expression_kind;
@ -1834,7 +1834,7 @@ FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena *arena)
"field 'returns' is required for FunctionType"); "field 'returns' is required for FunctionType");
return NULL; return NULL;
} }
p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = FunctionType_kind; p->kind = FunctionType_kind;
@ -1860,7 +1860,7 @@ FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq * body,
"field 'args' is required for FunctionDef"); "field 'args' is required for FunctionDef");
return NULL; return NULL;
} }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = FunctionDef_kind; p->kind = FunctionDef_kind;
@ -1894,7 +1894,7 @@ AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq * body,
"field 'args' is required for AsyncFunctionDef"); "field 'args' is required for AsyncFunctionDef");
return NULL; return NULL;
} }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = AsyncFunctionDef_kind; p->kind = AsyncFunctionDef_kind;
@ -1922,7 +1922,7 @@ ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq * keywords,
"field 'name' is required for ClassDef"); "field 'name' is required for ClassDef");
return NULL; return NULL;
} }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = ClassDef_kind; p->kind = ClassDef_kind;
@ -1943,7 +1943,7 @@ Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena) end_col_offset, PyArena *arena)
{ {
stmt_ty p; stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Return_kind; p->kind = Return_kind;
@ -1960,7 +1960,7 @@ Delete(asdl_expr_seq * targets, int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena) end_col_offset, PyArena *arena)
{ {
stmt_ty p; stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Delete_kind; p->kind = Delete_kind;
@ -1982,7 +1982,7 @@ Assign(asdl_expr_seq * targets, expr_ty value, string type_comment, int lineno,
"field 'value' is required for Assign"); "field 'value' is required for Assign");
return NULL; return NULL;
} }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Assign_kind; p->kind = Assign_kind;
@ -2016,7 +2016,7 @@ AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
"field 'value' is required for AugAssign"); "field 'value' is required for AugAssign");
return NULL; return NULL;
} }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = AugAssign_kind; p->kind = AugAssign_kind;
@ -2046,7 +2046,7 @@ AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
"field 'annotation' is required for AnnAssign"); "field 'annotation' is required for AnnAssign");
return NULL; return NULL;
} }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = AnnAssign_kind; p->kind = AnnAssign_kind;
@ -2077,7 +2077,7 @@ For(expr_ty target, expr_ty iter, asdl_stmt_seq * body, asdl_stmt_seq * orelse,
"field 'iter' is required for For"); "field 'iter' is required for For");
return NULL; return NULL;
} }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = For_kind; p->kind = For_kind;
@ -2109,7 +2109,7 @@ AsyncFor(expr_ty target, expr_ty iter, asdl_stmt_seq * body, asdl_stmt_seq *
"field 'iter' is required for AsyncFor"); "field 'iter' is required for AsyncFor");
return NULL; return NULL;
} }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = AsyncFor_kind; p->kind = AsyncFor_kind;
@ -2135,7 +2135,7 @@ While(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int lineno,
"field 'test' is required for While"); "field 'test' is required for While");
return NULL; return NULL;
} }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = While_kind; p->kind = While_kind;
@ -2159,7 +2159,7 @@ If(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int lineno, int
"field 'test' is required for If"); "field 'test' is required for If");
return NULL; return NULL;
} }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = If_kind; p->kind = If_kind;
@ -2178,7 +2178,7 @@ With(asdl_withitem_seq * items, asdl_stmt_seq * body, string type_comment, int
lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena) lineno, int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
{ {
stmt_ty p; stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = With_kind; p->kind = With_kind;
@ -2198,7 +2198,7 @@ AsyncWith(asdl_withitem_seq * items, asdl_stmt_seq * body, string type_comment,
PyArena *arena) PyArena *arena)
{ {
stmt_ty p; stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = AsyncWith_kind; p->kind = AsyncWith_kind;
@ -2222,7 +2222,7 @@ Match(expr_ty subject, asdl_match_case_seq * cases, int lineno, int col_offset,
"field 'subject' is required for Match"); "field 'subject' is required for Match");
return NULL; return NULL;
} }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Match_kind; p->kind = Match_kind;
@ -2240,7 +2240,7 @@ Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
int end_col_offset, PyArena *arena) int end_col_offset, PyArena *arena)
{ {
stmt_ty p; stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Raise_kind; p->kind = Raise_kind;
@ -2259,7 +2259,7 @@ Try(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers, asdl_stmt_seq *
end_lineno, int end_col_offset, PyArena *arena) end_lineno, int end_col_offset, PyArena *arena)
{ {
stmt_ty p; stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Try_kind; p->kind = Try_kind;
@ -2284,7 +2284,7 @@ Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
"field 'test' is required for Assert"); "field 'test' is required for Assert");
return NULL; return NULL;
} }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Assert_kind; p->kind = Assert_kind;
@ -2302,7 +2302,7 @@ Import(asdl_alias_seq * names, int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena) end_col_offset, PyArena *arena)
{ {
stmt_ty p; stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Import_kind; p->kind = Import_kind;
@ -2319,7 +2319,7 @@ ImportFrom(identifier module, asdl_alias_seq * names, int level, int lineno,
int col_offset, int end_lineno, int end_col_offset, PyArena *arena) int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
{ {
stmt_ty p; stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = ImportFrom_kind; p->kind = ImportFrom_kind;
@ -2338,7 +2338,7 @@ Global(asdl_identifier_seq * names, int lineno, int col_offset, int end_lineno,
int end_col_offset, PyArena *arena) int end_col_offset, PyArena *arena)
{ {
stmt_ty p; stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Global_kind; p->kind = Global_kind;
@ -2355,7 +2355,7 @@ Nonlocal(asdl_identifier_seq * names, int lineno, int col_offset, int
end_lineno, int end_col_offset, PyArena *arena) end_lineno, int end_col_offset, PyArena *arena)
{ {
stmt_ty p; stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Nonlocal_kind; p->kind = Nonlocal_kind;
@ -2377,7 +2377,7 @@ Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
"field 'value' is required for Expr"); "field 'value' is required for Expr");
return NULL; return NULL;
} }
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Expr_kind; p->kind = Expr_kind;
@ -2394,7 +2394,7 @@ Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
*arena) *arena)
{ {
stmt_ty p; stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Pass_kind; p->kind = Pass_kind;
@ -2410,7 +2410,7 @@ Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
*arena) *arena)
{ {
stmt_ty p; stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Break_kind; p->kind = Break_kind;
@ -2426,7 +2426,7 @@ Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
PyArena *arena) PyArena *arena)
{ {
stmt_ty p; stmt_ty p;
p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Continue_kind; p->kind = Continue_kind;
@ -2447,7 +2447,7 @@ BoolOp(boolop_ty op, asdl_expr_seq * values, int lineno, int col_offset, int
"field 'op' is required for BoolOp"); "field 'op' is required for BoolOp");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = BoolOp_kind; p->kind = BoolOp_kind;
@ -2475,7 +2475,7 @@ NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
"field 'value' is required for NamedExpr"); "field 'value' is required for NamedExpr");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = NamedExpr_kind; p->kind = NamedExpr_kind;
@ -2508,7 +2508,7 @@ BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
"field 'right' is required for BinOp"); "field 'right' is required for BinOp");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = BinOp_kind; p->kind = BinOp_kind;
@ -2537,7 +2537,7 @@ UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
"field 'operand' is required for UnaryOp"); "field 'operand' is required for UnaryOp");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = UnaryOp_kind; p->kind = UnaryOp_kind;
@ -2565,7 +2565,7 @@ Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
"field 'body' is required for Lambda"); "field 'body' is required for Lambda");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Lambda_kind; p->kind = Lambda_kind;
@ -2598,7 +2598,7 @@ IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
"field 'orelse' is required for IfExp"); "field 'orelse' is required for IfExp");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = IfExp_kind; p->kind = IfExp_kind;
@ -2617,7 +2617,7 @@ Dict(asdl_expr_seq * keys, asdl_expr_seq * values, int lineno, int col_offset,
int end_lineno, int end_col_offset, PyArena *arena) int end_lineno, int end_col_offset, PyArena *arena)
{ {
expr_ty p; expr_ty p;
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Dict_kind; p->kind = Dict_kind;
@ -2635,7 +2635,7 @@ Set(asdl_expr_seq * elts, int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena) end_col_offset, PyArena *arena)
{ {
expr_ty p; expr_ty p;
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Set_kind; p->kind = Set_kind;
@ -2657,7 +2657,7 @@ ListComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno, int
"field 'elt' is required for ListComp"); "field 'elt' is required for ListComp");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = ListComp_kind; p->kind = ListComp_kind;
@ -2680,7 +2680,7 @@ SetComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno, int
"field 'elt' is required for SetComp"); "field 'elt' is required for SetComp");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = SetComp_kind; p->kind = SetComp_kind;
@ -2709,7 +2709,7 @@ DictComp(expr_ty key, expr_ty value, asdl_comprehension_seq * generators, int
"field 'value' is required for DictComp"); "field 'value' is required for DictComp");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = DictComp_kind; p->kind = DictComp_kind;
@ -2733,7 +2733,7 @@ GeneratorExp(expr_ty elt, asdl_comprehension_seq * generators, int lineno, int
"field 'elt' is required for GeneratorExp"); "field 'elt' is required for GeneratorExp");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = GeneratorExp_kind; p->kind = GeneratorExp_kind;
@ -2756,7 +2756,7 @@ Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
"field 'value' is required for Await"); "field 'value' is required for Await");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Await_kind; p->kind = Await_kind;
@ -2773,7 +2773,7 @@ Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
end_col_offset, PyArena *arena) end_col_offset, PyArena *arena)
{ {
expr_ty p; expr_ty p;
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Yield_kind; p->kind = Yield_kind;
@ -2795,7 +2795,7 @@ YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
"field 'value' is required for YieldFrom"); "field 'value' is required for YieldFrom");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = YieldFrom_kind; p->kind = YieldFrom_kind;
@ -2818,7 +2818,7 @@ Compare(expr_ty left, asdl_int_seq * ops, asdl_expr_seq * comparators, int
"field 'left' is required for Compare"); "field 'left' is required for Compare");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Compare_kind; p->kind = Compare_kind;
@ -2842,7 +2842,7 @@ Call(expr_ty func, asdl_expr_seq * args, asdl_keyword_seq * keywords, int
"field 'func' is required for Call"); "field 'func' is required for Call");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Call_kind; p->kind = Call_kind;
@ -2867,7 +2867,7 @@ FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
"field 'value' is required for FormattedValue"); "field 'value' is required for FormattedValue");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = FormattedValue_kind; p->kind = FormattedValue_kind;
@ -2886,7 +2886,7 @@ JoinedStr(asdl_expr_seq * values, int lineno, int col_offset, int end_lineno,
int end_col_offset, PyArena *arena) int end_col_offset, PyArena *arena)
{ {
expr_ty p; expr_ty p;
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = JoinedStr_kind; p->kind = JoinedStr_kind;
@ -2908,7 +2908,7 @@ Constant(constant value, string kind, int lineno, int col_offset, int
"field 'value' is required for Constant"); "field 'value' is required for Constant");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Constant_kind; p->kind = Constant_kind;
@ -2941,7 +2941,7 @@ Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
"field 'ctx' is required for Attribute"); "field 'ctx' is required for Attribute");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Attribute_kind; p->kind = Attribute_kind;
@ -2975,7 +2975,7 @@ Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno, int
"field 'ctx' is required for Subscript"); "field 'ctx' is required for Subscript");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Subscript_kind; p->kind = Subscript_kind;
@ -3004,7 +3004,7 @@ Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
"field 'ctx' is required for Starred"); "field 'ctx' is required for Starred");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Starred_kind; p->kind = Starred_kind;
@ -3032,7 +3032,7 @@ Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
"field 'ctx' is required for Name"); "field 'ctx' is required for Name");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Name_kind; p->kind = Name_kind;
@ -3055,7 +3055,7 @@ List(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
"field 'ctx' is required for List"); "field 'ctx' is required for List");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = List_kind; p->kind = List_kind;
@ -3078,7 +3078,7 @@ Tuple(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int col_offset,
"field 'ctx' is required for Tuple"); "field 'ctx' is required for Tuple");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Tuple_kind; p->kind = Tuple_kind;
@ -3096,7 +3096,7 @@ Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset,
int end_lineno, int end_col_offset, PyArena *arena) int end_lineno, int end_col_offset, PyArena *arena)
{ {
expr_ty p; expr_ty p;
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = Slice_kind; p->kind = Slice_kind;
@ -3125,7 +3125,7 @@ MatchAs(expr_ty pattern, identifier name, int lineno, int col_offset, int
"field 'name' is required for MatchAs"); "field 'name' is required for MatchAs");
return NULL; return NULL;
} }
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = MatchAs_kind; p->kind = MatchAs_kind;
@ -3143,7 +3143,7 @@ MatchOr(asdl_expr_seq * patterns, int lineno, int col_offset, int end_lineno,
int end_col_offset, PyArena *arena) int end_col_offset, PyArena *arena)
{ {
expr_ty p; expr_ty p;
p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = MatchOr_kind; p->kind = MatchOr_kind;
@ -3170,7 +3170,7 @@ comprehension(expr_ty target, expr_ty iter, asdl_expr_seq * ifs, int is_async,
"field 'iter' is required for comprehension"); "field 'iter' is required for comprehension");
return NULL; return NULL;
} }
p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); p = (comprehension_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->target = target; p->target = target;
@ -3186,7 +3186,7 @@ ExceptHandler(expr_ty type, identifier name, asdl_stmt_seq * body, int lineno,
*arena) *arena)
{ {
excepthandler_ty p; excepthandler_ty p;
p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); p = (excepthandler_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = ExceptHandler_kind; p->kind = ExceptHandler_kind;
@ -3206,7 +3206,7 @@ arguments(asdl_arg_seq * posonlyargs, asdl_arg_seq * args, arg_ty vararg,
asdl_expr_seq * defaults, PyArena *arena) asdl_expr_seq * defaults, PyArena *arena)
{ {
arguments_ty p; arguments_ty p;
p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); p = (arguments_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->posonlyargs = posonlyargs; p->posonlyargs = posonlyargs;
@ -3229,7 +3229,7 @@ arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
"field 'arg' is required for arg"); "field 'arg' is required for arg");
return NULL; return NULL;
} }
p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); p = (arg_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->arg = arg; p->arg = arg;
@ -3252,7 +3252,7 @@ keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
"field 'value' is required for keyword"); "field 'value' is required for keyword");
return NULL; return NULL;
} }
p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); p = (keyword_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->arg = arg; p->arg = arg;
@ -3273,7 +3273,7 @@ alias(identifier name, identifier asname, PyArena *arena)
"field 'name' is required for alias"); "field 'name' is required for alias");
return NULL; return NULL;
} }
p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); p = (alias_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->name = name; p->name = name;
@ -3290,7 +3290,7 @@ withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
"field 'context_expr' is required for withitem"); "field 'context_expr' is required for withitem");
return NULL; return NULL;
} }
p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); p = (withitem_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->context_expr = context_expr; p->context_expr = context_expr;
@ -3307,7 +3307,7 @@ match_case(expr_ty pattern, expr_ty guard, asdl_stmt_seq * body, PyArena *arena)
"field 'pattern' is required for match_case"); "field 'pattern' is required for match_case");
return NULL; return NULL;
} }
p = (match_case_ty)PyArena_Malloc(arena, sizeof(*p)); p = (match_case_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->pattern = pattern; p->pattern = pattern;
@ -3325,7 +3325,7 @@ TypeIgnore(int lineno, string tag, PyArena *arena)
"field 'tag' is required for TypeIgnore"); "field 'tag' is required for TypeIgnore");
return NULL; return NULL;
} }
p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p)); p = (type_ignore_ty)_PyArena_Malloc(arena, sizeof(*p));
if (!p) if (!p)
return NULL; return NULL;
p->kind = TypeIgnore_kind; p->kind = TypeIgnore_kind;

View File

@ -16,7 +16,7 @@ make_const(expr_ty node, PyObject *val, PyArena *arena)
PyErr_Clear(); PyErr_Clear();
return 1; return 1;
} }
if (PyArena_AddPyObject(arena, val) < 0) { if (_PyArena_AddPyObject(arena, val) < 0) {
Py_DECREF(val); Py_DECREF(val);
return 0; return 0;
} }

View File

@ -828,21 +828,21 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
PyArena *arena; PyArena *arena;
mod_ty mod; mod_ty mod;
arena = PyArena_New(); arena = _PyArena_New();
if (arena == NULL) if (arena == NULL)
goto error; goto error;
mod = PyAST_obj2mod(source, arena, compile_mode); mod = PyAST_obj2mod(source, arena, compile_mode);
if (mod == NULL) { if (mod == NULL) {
PyArena_Free(arena); _PyArena_Free(arena);
goto error; goto error;
} }
if (!_PyAST_Validate(mod)) { if (!_PyAST_Validate(mod)) {
PyArena_Free(arena); _PyArena_Free(arena);
goto error; goto error;
} }
result = (PyObject*)_PyAST_Compile(mod, filename, result = (PyObject*)_PyAST_Compile(mod, filename,
&cf, optimize, arena); &cf, optimize, arena);
PyArena_Free(arena); _PyArena_Free(arena);
} }
goto finally; goto finally;
} }

View File

@ -1,4 +1,5 @@
#include "Python.h" #include "Python.h"
#include "pycore_pyarena.h" // PyArena
/* A simple arena block structure. /* A simple arena block structure.
@ -125,7 +126,7 @@ block_alloc(block *b, size_t size)
} }
PyArena * PyArena *
PyArena_New() _PyArena_New(void)
{ {
PyArena* arena = (PyArena *)PyMem_Malloc(sizeof(PyArena)); PyArena* arena = (PyArena *)PyMem_Malloc(sizeof(PyArena));
if (!arena) if (!arena)
@ -154,7 +155,7 @@ PyArena_New()
} }
void void
PyArena_Free(PyArena *arena) _PyArena_Free(PyArena *arena)
{ {
assert(arena); assert(arena);
#if defined(Py_DEBUG) #if defined(Py_DEBUG)
@ -177,7 +178,7 @@ PyArena_Free(PyArena *arena)
} }
void * void *
PyArena_Malloc(PyArena *arena, size_t size) _PyArena_Malloc(PyArena *arena, size_t size)
{ {
void *p = block_alloc(arena->a_cur, size); void *p = block_alloc(arena->a_cur, size);
if (!p) if (!p)
@ -200,7 +201,7 @@ PyArena_Malloc(PyArena *arena, size_t size)
} }
int int
PyArena_AddPyObject(PyArena *arena, PyObject *obj) _PyArena_AddPyObject(PyArena *arena, PyObject *obj)
{ {
int r = PyList_Append(arena->a_objects, obj); int r = PyList_Append(arena->a_objects, obj);
if (r >= 0) { if (r >= 0) {

View File

@ -247,7 +247,7 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename,
} }
} }
} }
arena = PyArena_New(); arena = _PyArena_New();
if (arena == NULL) { if (arena == NULL) {
Py_XDECREF(v); Py_XDECREF(v);
Py_XDECREF(w); Py_XDECREF(w);
@ -262,7 +262,7 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename,
Py_XDECREF(w); Py_XDECREF(w);
Py_XDECREF(oenc); Py_XDECREF(oenc);
if (mod == NULL) { if (mod == NULL) {
PyArena_Free(arena); _PyArena_Free(arena);
if (errcode == E_EOF) { if (errcode == E_EOF) {
PyErr_Clear(); PyErr_Clear();
return E_EOF; return E_EOF;
@ -271,12 +271,12 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename,
} }
m = PyImport_AddModuleObject(mod_name); m = PyImport_AddModuleObject(mod_name);
if (m == NULL) { if (m == NULL) {
PyArena_Free(arena); _PyArena_Free(arena);
return -1; return -1;
} }
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
v = run_mod(mod, filename, d, d, flags, arena); v = run_mod(mod, filename, d, d, flags, arena);
PyArena_Free(arena); _PyArena_Free(arena);
if (v == NULL) { if (v == NULL) {
return -1; return -1;
} }
@ -1099,7 +1099,7 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals,
if (filename == NULL) if (filename == NULL)
return NULL; return NULL;
arena = PyArena_New(); arena = _PyArena_New();
if (arena == NULL) if (arena == NULL)
return NULL; return NULL;
@ -1107,7 +1107,7 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals,
if (mod != NULL) if (mod != NULL)
ret = run_mod(mod, filename, globals, locals, flags, arena); ret = run_mod(mod, filename, globals, locals, flags, arena);
PyArena_Free(arena); _PyArena_Free(arena);
return ret; return ret;
} }
@ -1116,7 +1116,7 @@ static PyObject *
pyrun_file(FILE *fp, PyObject *filename, int start, PyObject *globals, pyrun_file(FILE *fp, PyObject *filename, int start, PyObject *globals,
PyObject *locals, int closeit, PyCompilerFlags *flags) PyObject *locals, int closeit, PyCompilerFlags *flags)
{ {
PyArena *arena = PyArena_New(); PyArena *arena = _PyArena_New();
if (arena == NULL) { if (arena == NULL) {
return NULL; return NULL;
} }
@ -1136,7 +1136,7 @@ pyrun_file(FILE *fp, PyObject *filename, int start, PyObject *globals,
else { else {
ret = NULL; ret = NULL;
} }
PyArena_Free(arena); _PyArena_Free(arena);
return ret; return ret;
} }
@ -1289,22 +1289,22 @@ Py_CompileStringObject(const char *str, PyObject *filename, int start,
{ {
PyCodeObject *co; PyCodeObject *co;
mod_ty mod; mod_ty mod;
PyArena *arena = PyArena_New(); PyArena *arena = _PyArena_New();
if (arena == NULL) if (arena == NULL)
return NULL; return NULL;
mod = _PyParser_ASTFromString(str, filename, start, flags, arena); mod = _PyParser_ASTFromString(str, filename, start, flags, arena);
if (mod == NULL) { if (mod == NULL) {
PyArena_Free(arena); _PyArena_Free(arena);
return NULL; return NULL;
} }
if (flags && (flags->cf_flags & PyCF_ONLY_AST)) { if (flags && (flags->cf_flags & PyCF_ONLY_AST)) {
PyObject *result = PyAST_mod2obj(mod); PyObject *result = PyAST_mod2obj(mod);
PyArena_Free(arena); _PyArena_Free(arena);
return result; return result;
} }
co = _PyAST_Compile(mod, filename, flags, optimize, arena); co = _PyAST_Compile(mod, filename, flags, optimize, arena);
PyArena_Free(arena); _PyArena_Free(arena);
return (PyObject *)co; return (PyObject *)co;
} }

View File

@ -1972,16 +1972,16 @@ _Py_SymtableStringObjectFlags(const char *str, PyObject *filename,
mod_ty mod; mod_ty mod;
PyArena *arena; PyArena *arena;
arena = PyArena_New(); arena = _PyArena_New();
if (arena == NULL) if (arena == NULL)
return NULL; return NULL;
mod = _PyParser_ASTFromString(str, filename, start, flags, arena); mod = _PyParser_ASTFromString(str, filename, start, flags, arena);
if (mod == NULL) { if (mod == NULL) {
PyArena_Free(arena); _PyArena_Free(arena);
return NULL; return NULL;
} }
st = _PySymtable_Build(mod, filename, 0); st = _PySymtable_Build(mod, filename, 0);
PyArena_Free(arena); _PyArena_Free(arena);
return st; return st;
} }

View File

@ -32,7 +32,7 @@ parse_file(PyObject *self, PyObject *args, PyObject *kwds)
return PyErr_Format(PyExc_ValueError, "Bad mode, must be 0 <= mode <= 2"); return PyErr_Format(PyExc_ValueError, "Bad mode, must be 0 <= mode <= 2");
} }
PyArena *arena = PyArena_New(); PyArena *arena = _PyArena_New();
if (arena == NULL) { if (arena == NULL) {
return NULL; return NULL;
} }
@ -63,7 +63,7 @@ parse_file(PyObject *self, PyObject *args, PyObject *kwds)
error: error:
Py_XDECREF(filename_ob); Py_XDECREF(filename_ob);
PyArena_Free(arena); _PyArena_Free(arena);
return result; return result;
} }
@ -80,7 +80,7 @@ parse_string(PyObject *self, PyObject *args, PyObject *kwds)
return PyErr_Format(PyExc_ValueError, "Bad mode, must be 0 <= mode <= 2"); return PyErr_Format(PyExc_ValueError, "Bad mode, must be 0 <= mode <= 2");
} }
PyArena *arena = PyArena_New(); PyArena *arena = _PyArena_New();
if (arena == NULL) { if (arena == NULL) {
return NULL; return NULL;
} }
@ -102,7 +102,7 @@ parse_string(PyObject *self, PyObject *args, PyObject *kwds)
error: error:
Py_XDECREF(filename_ob); Py_XDECREF(filename_ob);
PyArena_Free(arena); _PyArena_Free(arena);
return result; return result;
} }