mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
GH-130396: Use computed stack limits on linux (GH-130398)
* Implement C recursion protection with limit pointers for Linux, MacOS and Windows * Remove calls to PyOS_CheckStack * Add stack protection to parser * Make tests more robust to low stacks * Improve error messages for stack overflow
This commit is contained in:
parent
99088ab081
commit
014223649c
58 changed files with 1295 additions and 1482 deletions
392
Python/ast.c
392
Python/ast.c
|
@ -9,34 +9,22 @@
|
|||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct validator {
|
||||
int recursion_depth; /* current recursion depth */
|
||||
int recursion_limit; /* recursion limit */
|
||||
};
|
||||
#define ENTER_RECURSIVE() \
|
||||
if (Py_EnterRecursiveCall(" during compilation")) { \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
#define ENTER_RECURSIVE(ST) \
|
||||
do { \
|
||||
if (++(ST)->recursion_depth > (ST)->recursion_limit) { \
|
||||
PyErr_SetString(PyExc_RecursionError, \
|
||||
"maximum recursion depth exceeded during compilation"); \
|
||||
return 0; \
|
||||
} \
|
||||
} while(0)
|
||||
#define LEAVE_RECURSIVE() Py_LeaveRecursiveCall();
|
||||
|
||||
#define LEAVE_RECURSIVE(ST) \
|
||||
do { \
|
||||
--(ST)->recursion_depth; \
|
||||
} while(0)
|
||||
|
||||
static int validate_stmts(struct validator *, asdl_stmt_seq *);
|
||||
static int validate_exprs(struct validator *, asdl_expr_seq *, expr_context_ty, int);
|
||||
static int validate_patterns(struct validator *, asdl_pattern_seq *, int);
|
||||
static int validate_type_params(struct validator *, asdl_type_param_seq *);
|
||||
static int validate_stmts(asdl_stmt_seq *);
|
||||
static int validate_exprs(asdl_expr_seq *, expr_context_ty, int);
|
||||
static int validate_patterns(asdl_pattern_seq *, int);
|
||||
static int validate_type_params(asdl_type_param_seq *);
|
||||
static int _validate_nonempty_seq(asdl_seq *, const char *, const char *);
|
||||
static int validate_stmt(struct validator *, stmt_ty);
|
||||
static int validate_expr(struct validator *, expr_ty, expr_context_ty);
|
||||
static int validate_pattern(struct validator *, pattern_ty, int);
|
||||
static int validate_typeparam(struct validator *, type_param_ty);
|
||||
static int validate_stmt(stmt_ty);
|
||||
static int validate_expr(expr_ty, expr_context_ty);
|
||||
static int validate_pattern(pattern_ty, int);
|
||||
static int validate_typeparam(type_param_ty);
|
||||
|
||||
#define VALIDATE_POSITIONS(node) \
|
||||
if (node->lineno > node->end_lineno) { \
|
||||
|
@ -80,7 +68,7 @@ validate_name(PyObject *name)
|
|||
}
|
||||
|
||||
static int
|
||||
validate_comprehension(struct validator *state, asdl_comprehension_seq *gens)
|
||||
validate_comprehension(asdl_comprehension_seq *gens)
|
||||
{
|
||||
assert(!PyErr_Occurred());
|
||||
if (!asdl_seq_LEN(gens)) {
|
||||
|
@ -89,32 +77,32 @@ validate_comprehension(struct validator *state, asdl_comprehension_seq *gens)
|
|||
}
|
||||
for (Py_ssize_t i = 0; i < asdl_seq_LEN(gens); i++) {
|
||||
comprehension_ty comp = asdl_seq_GET(gens, i);
|
||||
if (!validate_expr(state, comp->target, Store) ||
|
||||
!validate_expr(state, comp->iter, Load) ||
|
||||
!validate_exprs(state, comp->ifs, Load, 0))
|
||||
if (!validate_expr(comp->target, Store) ||
|
||||
!validate_expr(comp->iter, Load) ||
|
||||
!validate_exprs(comp->ifs, Load, 0))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
validate_keywords(struct validator *state, asdl_keyword_seq *keywords)
|
||||
validate_keywords(asdl_keyword_seq *keywords)
|
||||
{
|
||||
assert(!PyErr_Occurred());
|
||||
for (Py_ssize_t i = 0; i < asdl_seq_LEN(keywords); i++)
|
||||
if (!validate_expr(state, (asdl_seq_GET(keywords, i))->value, Load))
|
||||
if (!validate_expr((asdl_seq_GET(keywords, i))->value, Load))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
validate_args(struct validator *state, asdl_arg_seq *args)
|
||||
validate_args(asdl_arg_seq *args)
|
||||
{
|
||||
assert(!PyErr_Occurred());
|
||||
for (Py_ssize_t i = 0; i < asdl_seq_LEN(args); i++) {
|
||||
arg_ty arg = asdl_seq_GET(args, i);
|
||||
VALIDATE_POSITIONS(arg);
|
||||
if (arg->annotation && !validate_expr(state, arg->annotation, Load))
|
||||
if (arg->annotation && !validate_expr(arg->annotation, Load))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
@ -136,20 +124,20 @@ expr_context_name(expr_context_ty ctx)
|
|||
}
|
||||
|
||||
static int
|
||||
validate_arguments(struct validator *state, arguments_ty args)
|
||||
validate_arguments(arguments_ty args)
|
||||
{
|
||||
assert(!PyErr_Occurred());
|
||||
if (!validate_args(state, args->posonlyargs) || !validate_args(state, args->args)) {
|
||||
if (!validate_args(args->posonlyargs) || !validate_args(args->args)) {
|
||||
return 0;
|
||||
}
|
||||
if (args->vararg && args->vararg->annotation
|
||||
&& !validate_expr(state, args->vararg->annotation, Load)) {
|
||||
&& !validate_expr(args->vararg->annotation, Load)) {
|
||||
return 0;
|
||||
}
|
||||
if (!validate_args(state, args->kwonlyargs))
|
||||
if (!validate_args(args->kwonlyargs))
|
||||
return 0;
|
||||
if (args->kwarg && args->kwarg->annotation
|
||||
&& !validate_expr(state, args->kwarg->annotation, Load)) {
|
||||
&& !validate_expr(args->kwarg->annotation, Load)) {
|
||||
return 0;
|
||||
}
|
||||
if (asdl_seq_LEN(args->defaults) > asdl_seq_LEN(args->posonlyargs) + asdl_seq_LEN(args->args)) {
|
||||
|
@ -161,11 +149,11 @@ validate_arguments(struct validator *state, arguments_ty args)
|
|||
"kw_defaults on arguments");
|
||||
return 0;
|
||||
}
|
||||
return validate_exprs(state, args->defaults, Load, 0) && validate_exprs(state, args->kw_defaults, Load, 1);
|
||||
return validate_exprs(args->defaults, Load, 0) && validate_exprs(args->kw_defaults, Load, 1);
|
||||
}
|
||||
|
||||
static int
|
||||
validate_constant(struct validator *state, PyObject *value)
|
||||
validate_constant(PyObject *value)
|
||||
{
|
||||
assert(!PyErr_Occurred());
|
||||
if (value == Py_None || value == Py_Ellipsis)
|
||||
|
@ -180,7 +168,7 @@ validate_constant(struct validator *state, PyObject *value)
|
|||
return 1;
|
||||
|
||||
if (PyTuple_CheckExact(value) || PyFrozenSet_CheckExact(value)) {
|
||||
ENTER_RECURSIVE(state);
|
||||
ENTER_RECURSIVE();
|
||||
|
||||
PyObject *it = PyObject_GetIter(value);
|
||||
if (it == NULL)
|
||||
|
@ -196,7 +184,7 @@ validate_constant(struct validator *state, PyObject *value)
|
|||
break;
|
||||
}
|
||||
|
||||
if (!validate_constant(state, item)) {
|
||||
if (!validate_constant(item)) {
|
||||
Py_DECREF(it);
|
||||
Py_DECREF(item);
|
||||
return 0;
|
||||
|
@ -205,7 +193,7 @@ validate_constant(struct validator *state, PyObject *value)
|
|||
}
|
||||
|
||||
Py_DECREF(it);
|
||||
LEAVE_RECURSIVE(state);
|
||||
LEAVE_RECURSIVE();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -218,12 +206,12 @@ validate_constant(struct validator *state, PyObject *value)
|
|||
}
|
||||
|
||||
static int
|
||||
validate_expr(struct validator *state, expr_ty exp, expr_context_ty ctx)
|
||||
validate_expr(expr_ty exp, expr_context_ty ctx)
|
||||
{
|
||||
assert(!PyErr_Occurred());
|
||||
VALIDATE_POSITIONS(exp);
|
||||
int ret = -1;
|
||||
ENTER_RECURSIVE(state);
|
||||
ENTER_RECURSIVE();
|
||||
int check_ctx = 1;
|
||||
expr_context_ty actual_ctx;
|
||||
|
||||
|
@ -273,23 +261,23 @@ validate_expr(struct validator *state, expr_ty exp, expr_context_ty ctx)
|
|||
PyErr_SetString(PyExc_ValueError, "BoolOp with less than 2 values");
|
||||
return 0;
|
||||
}
|
||||
ret = validate_exprs(state, exp->v.BoolOp.values, Load, 0);
|
||||
ret = validate_exprs(exp->v.BoolOp.values, Load, 0);
|
||||
break;
|
||||
case BinOp_kind:
|
||||
ret = validate_expr(state, exp->v.BinOp.left, Load) &&
|
||||
validate_expr(state, exp->v.BinOp.right, Load);
|
||||
ret = validate_expr(exp->v.BinOp.left, Load) &&
|
||||
validate_expr(exp->v.BinOp.right, Load);
|
||||
break;
|
||||
case UnaryOp_kind:
|
||||
ret = validate_expr(state, exp->v.UnaryOp.operand, Load);
|
||||
ret = validate_expr(exp->v.UnaryOp.operand, Load);
|
||||
break;
|
||||
case Lambda_kind:
|
||||
ret = validate_arguments(state, exp->v.Lambda.args) &&
|
||||
validate_expr(state, exp->v.Lambda.body, Load);
|
||||
ret = validate_arguments(exp->v.Lambda.args) &&
|
||||
validate_expr(exp->v.Lambda.body, Load);
|
||||
break;
|
||||
case IfExp_kind:
|
||||
ret = validate_expr(state, exp->v.IfExp.test, Load) &&
|
||||
validate_expr(state, exp->v.IfExp.body, Load) &&
|
||||
validate_expr(state, exp->v.IfExp.orelse, Load);
|
||||
ret = validate_expr(exp->v.IfExp.test, Load) &&
|
||||
validate_expr(exp->v.IfExp.body, Load) &&
|
||||
validate_expr(exp->v.IfExp.orelse, Load);
|
||||
break;
|
||||
case Dict_kind:
|
||||
if (asdl_seq_LEN(exp->v.Dict.keys) != asdl_seq_LEN(exp->v.Dict.values)) {
|
||||
|
@ -299,34 +287,34 @@ validate_expr(struct validator *state, expr_ty exp, expr_context_ty ctx)
|
|||
}
|
||||
/* null_ok=1 for keys expressions to allow dict unpacking to work in
|
||||
dict literals, i.e. ``{**{a:b}}`` */
|
||||
ret = validate_exprs(state, exp->v.Dict.keys, Load, /*null_ok=*/ 1) &&
|
||||
validate_exprs(state, exp->v.Dict.values, Load, /*null_ok=*/ 0);
|
||||
ret = validate_exprs(exp->v.Dict.keys, Load, /*null_ok=*/ 1) &&
|
||||
validate_exprs(exp->v.Dict.values, Load, /*null_ok=*/ 0);
|
||||
break;
|
||||
case Set_kind:
|
||||
ret = validate_exprs(state, exp->v.Set.elts, Load, 0);
|
||||
ret = validate_exprs(exp->v.Set.elts, Load, 0);
|
||||
break;
|
||||
#define COMP(NAME) \
|
||||
case NAME ## _kind: \
|
||||
ret = validate_comprehension(state, exp->v.NAME.generators) && \
|
||||
validate_expr(state, exp->v.NAME.elt, Load); \
|
||||
ret = validate_comprehension(exp->v.NAME.generators) && \
|
||||
validate_expr(exp->v.NAME.elt, Load); \
|
||||
break;
|
||||
COMP(ListComp)
|
||||
COMP(SetComp)
|
||||
COMP(GeneratorExp)
|
||||
#undef COMP
|
||||
case DictComp_kind:
|
||||
ret = validate_comprehension(state, exp->v.DictComp.generators) &&
|
||||
validate_expr(state, exp->v.DictComp.key, Load) &&
|
||||
validate_expr(state, exp->v.DictComp.value, Load);
|
||||
ret = validate_comprehension(exp->v.DictComp.generators) &&
|
||||
validate_expr(exp->v.DictComp.key, Load) &&
|
||||
validate_expr(exp->v.DictComp.value, Load);
|
||||
break;
|
||||
case Yield_kind:
|
||||
ret = !exp->v.Yield.value || validate_expr(state, exp->v.Yield.value, Load);
|
||||
ret = !exp->v.Yield.value || validate_expr(exp->v.Yield.value, Load);
|
||||
break;
|
||||
case YieldFrom_kind:
|
||||
ret = validate_expr(state, exp->v.YieldFrom.value, Load);
|
||||
ret = validate_expr(exp->v.YieldFrom.value, Load);
|
||||
break;
|
||||
case Await_kind:
|
||||
ret = validate_expr(state, exp->v.Await.value, Load);
|
||||
ret = validate_expr(exp->v.Await.value, Load);
|
||||
break;
|
||||
case Compare_kind:
|
||||
if (!asdl_seq_LEN(exp->v.Compare.comparators)) {
|
||||
|
@ -339,52 +327,52 @@ validate_expr(struct validator *state, expr_ty exp, expr_context_ty ctx)
|
|||
"of comparators and operands");
|
||||
return 0;
|
||||
}
|
||||
ret = validate_exprs(state, exp->v.Compare.comparators, Load, 0) &&
|
||||
validate_expr(state, exp->v.Compare.left, Load);
|
||||
ret = validate_exprs(exp->v.Compare.comparators, Load, 0) &&
|
||||
validate_expr(exp->v.Compare.left, Load);
|
||||
break;
|
||||
case Call_kind:
|
||||
ret = validate_expr(state, exp->v.Call.func, Load) &&
|
||||
validate_exprs(state, exp->v.Call.args, Load, 0) &&
|
||||
validate_keywords(state, exp->v.Call.keywords);
|
||||
ret = validate_expr(exp->v.Call.func, Load) &&
|
||||
validate_exprs(exp->v.Call.args, Load, 0) &&
|
||||
validate_keywords(exp->v.Call.keywords);
|
||||
break;
|
||||
case Constant_kind:
|
||||
if (!validate_constant(state, exp->v.Constant.value)) {
|
||||
if (!validate_constant(exp->v.Constant.value)) {
|
||||
return 0;
|
||||
}
|
||||
ret = 1;
|
||||
break;
|
||||
case JoinedStr_kind:
|
||||
ret = validate_exprs(state, exp->v.JoinedStr.values, Load, 0);
|
||||
ret = validate_exprs(exp->v.JoinedStr.values, Load, 0);
|
||||
break;
|
||||
case FormattedValue_kind:
|
||||
if (validate_expr(state, exp->v.FormattedValue.value, Load) == 0)
|
||||
if (validate_expr(exp->v.FormattedValue.value, Load) == 0)
|
||||
return 0;
|
||||
if (exp->v.FormattedValue.format_spec) {
|
||||
ret = validate_expr(state, exp->v.FormattedValue.format_spec, Load);
|
||||
ret = validate_expr(exp->v.FormattedValue.format_spec, Load);
|
||||
break;
|
||||
}
|
||||
ret = 1;
|
||||
break;
|
||||
case Attribute_kind:
|
||||
ret = validate_expr(state, exp->v.Attribute.value, Load);
|
||||
ret = validate_expr(exp->v.Attribute.value, Load);
|
||||
break;
|
||||
case Subscript_kind:
|
||||
ret = validate_expr(state, exp->v.Subscript.slice, Load) &&
|
||||
validate_expr(state, exp->v.Subscript.value, Load);
|
||||
ret = validate_expr(exp->v.Subscript.slice, Load) &&
|
||||
validate_expr(exp->v.Subscript.value, Load);
|
||||
break;
|
||||
case Starred_kind:
|
||||
ret = validate_expr(state, exp->v.Starred.value, ctx);
|
||||
ret = validate_expr(exp->v.Starred.value, ctx);
|
||||
break;
|
||||
case Slice_kind:
|
||||
ret = (!exp->v.Slice.lower || validate_expr(state, exp->v.Slice.lower, Load)) &&
|
||||
(!exp->v.Slice.upper || validate_expr(state, exp->v.Slice.upper, Load)) &&
|
||||
(!exp->v.Slice.step || validate_expr(state, exp->v.Slice.step, Load));
|
||||
ret = (!exp->v.Slice.lower || validate_expr(exp->v.Slice.lower, Load)) &&
|
||||
(!exp->v.Slice.upper || validate_expr(exp->v.Slice.upper, Load)) &&
|
||||
(!exp->v.Slice.step || validate_expr(exp->v.Slice.step, Load));
|
||||
break;
|
||||
case List_kind:
|
||||
ret = validate_exprs(state, exp->v.List.elts, ctx, 0);
|
||||
ret = validate_exprs(exp->v.List.elts, ctx, 0);
|
||||
break;
|
||||
case Tuple_kind:
|
||||
ret = validate_exprs(state, exp->v.Tuple.elts, ctx, 0);
|
||||
ret = validate_exprs(exp->v.Tuple.elts, ctx, 0);
|
||||
break;
|
||||
case NamedExpr_kind:
|
||||
if (exp->v.NamedExpr.target->kind != Name_kind) {
|
||||
|
@ -392,7 +380,7 @@ validate_expr(struct validator *state, expr_ty exp, expr_context_ty ctx)
|
|||
"NamedExpr target must be a Name");
|
||||
return 0;
|
||||
}
|
||||
ret = validate_expr(state, exp->v.NamedExpr.value, Load);
|
||||
ret = validate_expr(exp->v.NamedExpr.value, Load);
|
||||
break;
|
||||
/* This last case doesn't have any checking. */
|
||||
case Name_kind:
|
||||
|
@ -404,7 +392,7 @@ validate_expr(struct validator *state, expr_ty exp, expr_context_ty ctx)
|
|||
PyErr_SetString(PyExc_SystemError, "unexpected expression");
|
||||
ret = 0;
|
||||
}
|
||||
LEAVE_RECURSIVE(state);
|
||||
LEAVE_RECURSIVE();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -480,10 +468,10 @@ ensure_literal_complex(expr_ty exp)
|
|||
}
|
||||
|
||||
static int
|
||||
validate_pattern_match_value(struct validator *state, expr_ty exp)
|
||||
validate_pattern_match_value(expr_ty exp)
|
||||
{
|
||||
assert(!PyErr_Occurred());
|
||||
if (!validate_expr(state, exp, Load)) {
|
||||
if (!validate_expr(exp, Load)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -493,7 +481,7 @@ validate_pattern_match_value(struct validator *state, expr_ty exp)
|
|||
/* Ellipsis and immutable sequences are not allowed.
|
||||
For True, False and None, MatchSingleton() should
|
||||
be used */
|
||||
if (!validate_expr(state, exp, Load)) {
|
||||
if (!validate_expr(exp, Load)) {
|
||||
return 0;
|
||||
}
|
||||
PyObject *literal = exp->v.Constant.value;
|
||||
|
@ -545,15 +533,15 @@ validate_capture(PyObject *name)
|
|||
}
|
||||
|
||||
static int
|
||||
validate_pattern(struct validator *state, pattern_ty p, int star_ok)
|
||||
validate_pattern(pattern_ty p, int star_ok)
|
||||
{
|
||||
assert(!PyErr_Occurred());
|
||||
VALIDATE_POSITIONS(p);
|
||||
int ret = -1;
|
||||
ENTER_RECURSIVE(state);
|
||||
ENTER_RECURSIVE();
|
||||
switch (p->kind) {
|
||||
case MatchValue_kind:
|
||||
ret = validate_pattern_match_value(state, p->v.MatchValue.value);
|
||||
ret = validate_pattern_match_value(p->v.MatchValue.value);
|
||||
break;
|
||||
case MatchSingleton_kind:
|
||||
ret = p->v.MatchSingleton.value == Py_None || PyBool_Check(p->v.MatchSingleton.value);
|
||||
|
@ -563,7 +551,7 @@ validate_pattern(struct validator *state, pattern_ty p, int star_ok)
|
|||
}
|
||||
break;
|
||||
case MatchSequence_kind:
|
||||
ret = validate_patterns(state, p->v.MatchSequence.patterns, /*star_ok=*/1);
|
||||
ret = validate_patterns(p->v.MatchSequence.patterns, /*star_ok=*/1);
|
||||
break;
|
||||
case MatchMapping_kind:
|
||||
if (asdl_seq_LEN(p->v.MatchMapping.keys) != asdl_seq_LEN(p->v.MatchMapping.patterns)) {
|
||||
|
@ -591,7 +579,7 @@ validate_pattern(struct validator *state, pattern_ty p, int star_ok)
|
|||
continue;
|
||||
}
|
||||
}
|
||||
if (!validate_pattern_match_value(state, key)) {
|
||||
if (!validate_pattern_match_value(key)) {
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
|
@ -599,7 +587,7 @@ validate_pattern(struct validator *state, pattern_ty p, int star_ok)
|
|||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
ret = validate_patterns(state, p->v.MatchMapping.patterns, /*star_ok=*/0);
|
||||
ret = validate_patterns(p->v.MatchMapping.patterns, /*star_ok=*/0);
|
||||
break;
|
||||
case MatchClass_kind:
|
||||
if (asdl_seq_LEN(p->v.MatchClass.kwd_attrs) != asdl_seq_LEN(p->v.MatchClass.kwd_patterns)) {
|
||||
|
@ -608,7 +596,7 @@ validate_pattern(struct validator *state, pattern_ty p, int star_ok)
|
|||
ret = 0;
|
||||
break;
|
||||
}
|
||||
if (!validate_expr(state, p->v.MatchClass.cls, Load)) {
|
||||
if (!validate_expr(p->v.MatchClass.cls, Load)) {
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
|
@ -644,12 +632,12 @@ validate_pattern(struct validator *state, pattern_ty p, int star_ok)
|
|||
break;
|
||||
}
|
||||
|
||||
if (!validate_patterns(state, p->v.MatchClass.patterns, /*star_ok=*/0)) {
|
||||
if (!validate_patterns(p->v.MatchClass.patterns, /*star_ok=*/0)) {
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = validate_patterns(state, p->v.MatchClass.kwd_patterns, /*star_ok=*/0);
|
||||
ret = validate_patterns(p->v.MatchClass.kwd_patterns, /*star_ok=*/0);
|
||||
break;
|
||||
case MatchStar_kind:
|
||||
if (!star_ok) {
|
||||
|
@ -673,7 +661,7 @@ validate_pattern(struct validator *state, pattern_ty p, int star_ok)
|
|||
ret = 0;
|
||||
}
|
||||
else {
|
||||
ret = validate_pattern(state, p->v.MatchAs.pattern, /*star_ok=*/0);
|
||||
ret = validate_pattern(p->v.MatchAs.pattern, /*star_ok=*/0);
|
||||
}
|
||||
break;
|
||||
case MatchOr_kind:
|
||||
|
@ -683,7 +671,7 @@ validate_pattern(struct validator *state, pattern_ty p, int star_ok)
|
|||
ret = 0;
|
||||
break;
|
||||
}
|
||||
ret = validate_patterns(state, p->v.MatchOr.patterns, /*star_ok=*/0);
|
||||
ret = validate_patterns(p->v.MatchOr.patterns, /*star_ok=*/0);
|
||||
break;
|
||||
// No default case, so the compiler will emit a warning if new pattern
|
||||
// kinds are added without being handled here
|
||||
|
@ -692,7 +680,7 @@ validate_pattern(struct validator *state, pattern_ty p, int star_ok)
|
|||
PyErr_SetString(PyExc_SystemError, "unexpected pattern");
|
||||
ret = 0;
|
||||
}
|
||||
LEAVE_RECURSIVE(state);
|
||||
LEAVE_RECURSIVE();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -707,56 +695,56 @@ _validate_nonempty_seq(asdl_seq *seq, const char *what, const char *owner)
|
|||
#define validate_nonempty_seq(seq, what, owner) _validate_nonempty_seq((asdl_seq*)seq, what, owner)
|
||||
|
||||
static int
|
||||
validate_assignlist(struct validator *state, asdl_expr_seq *targets, expr_context_ty ctx)
|
||||
validate_assignlist(asdl_expr_seq *targets, expr_context_ty ctx)
|
||||
{
|
||||
assert(!PyErr_Occurred());
|
||||
return validate_nonempty_seq(targets, "targets", ctx == Del ? "Delete" : "Assign") &&
|
||||
validate_exprs(state, targets, ctx, 0);
|
||||
validate_exprs(targets, ctx, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
validate_body(struct validator *state, asdl_stmt_seq *body, const char *owner)
|
||||
validate_body(asdl_stmt_seq *body, const char *owner)
|
||||
{
|
||||
assert(!PyErr_Occurred());
|
||||
return validate_nonempty_seq(body, "body", owner) && validate_stmts(state, body);
|
||||
return validate_nonempty_seq(body, "body", owner) && validate_stmts(body);
|
||||
}
|
||||
|
||||
static int
|
||||
validate_stmt(struct validator *state, stmt_ty stmt)
|
||||
validate_stmt(stmt_ty stmt)
|
||||
{
|
||||
assert(!PyErr_Occurred());
|
||||
VALIDATE_POSITIONS(stmt);
|
||||
int ret = -1;
|
||||
ENTER_RECURSIVE(state);
|
||||
ENTER_RECURSIVE();
|
||||
switch (stmt->kind) {
|
||||
case FunctionDef_kind:
|
||||
ret = validate_body(state, stmt->v.FunctionDef.body, "FunctionDef") &&
|
||||
validate_type_params(state, stmt->v.FunctionDef.type_params) &&
|
||||
validate_arguments(state, stmt->v.FunctionDef.args) &&
|
||||
validate_exprs(state, stmt->v.FunctionDef.decorator_list, Load, 0) &&
|
||||
ret = validate_body(stmt->v.FunctionDef.body, "FunctionDef") &&
|
||||
validate_type_params(stmt->v.FunctionDef.type_params) &&
|
||||
validate_arguments(stmt->v.FunctionDef.args) &&
|
||||
validate_exprs(stmt->v.FunctionDef.decorator_list, Load, 0) &&
|
||||
(!stmt->v.FunctionDef.returns ||
|
||||
validate_expr(state, stmt->v.FunctionDef.returns, Load));
|
||||
validate_expr(stmt->v.FunctionDef.returns, Load));
|
||||
break;
|
||||
case ClassDef_kind:
|
||||
ret = validate_body(state, stmt->v.ClassDef.body, "ClassDef") &&
|
||||
validate_type_params(state, stmt->v.ClassDef.type_params) &&
|
||||
validate_exprs(state, stmt->v.ClassDef.bases, Load, 0) &&
|
||||
validate_keywords(state, stmt->v.ClassDef.keywords) &&
|
||||
validate_exprs(state, stmt->v.ClassDef.decorator_list, Load, 0);
|
||||
ret = validate_body(stmt->v.ClassDef.body, "ClassDef") &&
|
||||
validate_type_params(stmt->v.ClassDef.type_params) &&
|
||||
validate_exprs(stmt->v.ClassDef.bases, Load, 0) &&
|
||||
validate_keywords(stmt->v.ClassDef.keywords) &&
|
||||
validate_exprs(stmt->v.ClassDef.decorator_list, Load, 0);
|
||||
break;
|
||||
case Return_kind:
|
||||
ret = !stmt->v.Return.value || validate_expr(state, stmt->v.Return.value, Load);
|
||||
ret = !stmt->v.Return.value || validate_expr(stmt->v.Return.value, Load);
|
||||
break;
|
||||
case Delete_kind:
|
||||
ret = validate_assignlist(state, stmt->v.Delete.targets, Del);
|
||||
ret = validate_assignlist(stmt->v.Delete.targets, Del);
|
||||
break;
|
||||
case Assign_kind:
|
||||
ret = validate_assignlist(state, stmt->v.Assign.targets, Store) &&
|
||||
validate_expr(state, stmt->v.Assign.value, Load);
|
||||
ret = validate_assignlist(stmt->v.Assign.targets, Store) &&
|
||||
validate_expr(stmt->v.Assign.value, Load);
|
||||
break;
|
||||
case AugAssign_kind:
|
||||
ret = validate_expr(state, stmt->v.AugAssign.target, Store) &&
|
||||
validate_expr(state, stmt->v.AugAssign.value, Load);
|
||||
ret = validate_expr(stmt->v.AugAssign.target, Store) &&
|
||||
validate_expr(stmt->v.AugAssign.value, Load);
|
||||
break;
|
||||
case AnnAssign_kind:
|
||||
if (stmt->v.AnnAssign.target->kind != Name_kind &&
|
||||
|
@ -765,10 +753,10 @@ validate_stmt(struct validator *state, stmt_ty stmt)
|
|||
"AnnAssign with simple non-Name target");
|
||||
return 0;
|
||||
}
|
||||
ret = validate_expr(state, stmt->v.AnnAssign.target, Store) &&
|
||||
ret = validate_expr(stmt->v.AnnAssign.target, Store) &&
|
||||
(!stmt->v.AnnAssign.value ||
|
||||
validate_expr(state, stmt->v.AnnAssign.value, Load)) &&
|
||||
validate_expr(state, stmt->v.AnnAssign.annotation, Load);
|
||||
validate_expr(stmt->v.AnnAssign.value, Load)) &&
|
||||
validate_expr(stmt->v.AnnAssign.annotation, Load);
|
||||
break;
|
||||
case TypeAlias_kind:
|
||||
if (stmt->v.TypeAlias.name->kind != Name_kind) {
|
||||
|
@ -776,64 +764,64 @@ validate_stmt(struct validator *state, stmt_ty stmt)
|
|||
"TypeAlias with non-Name name");
|
||||
return 0;
|
||||
}
|
||||
ret = validate_expr(state, stmt->v.TypeAlias.name, Store) &&
|
||||
validate_type_params(state, stmt->v.TypeAlias.type_params) &&
|
||||
validate_expr(state, stmt->v.TypeAlias.value, Load);
|
||||
ret = validate_expr(stmt->v.TypeAlias.name, Store) &&
|
||||
validate_type_params(stmt->v.TypeAlias.type_params) &&
|
||||
validate_expr(stmt->v.TypeAlias.value, Load);
|
||||
break;
|
||||
case For_kind:
|
||||
ret = validate_expr(state, stmt->v.For.target, Store) &&
|
||||
validate_expr(state, stmt->v.For.iter, Load) &&
|
||||
validate_body(state, stmt->v.For.body, "For") &&
|
||||
validate_stmts(state, stmt->v.For.orelse);
|
||||
ret = validate_expr(stmt->v.For.target, Store) &&
|
||||
validate_expr(stmt->v.For.iter, Load) &&
|
||||
validate_body(stmt->v.For.body, "For") &&
|
||||
validate_stmts(stmt->v.For.orelse);
|
||||
break;
|
||||
case AsyncFor_kind:
|
||||
ret = validate_expr(state, stmt->v.AsyncFor.target, Store) &&
|
||||
validate_expr(state, stmt->v.AsyncFor.iter, Load) &&
|
||||
validate_body(state, stmt->v.AsyncFor.body, "AsyncFor") &&
|
||||
validate_stmts(state, stmt->v.AsyncFor.orelse);
|
||||
ret = validate_expr(stmt->v.AsyncFor.target, Store) &&
|
||||
validate_expr(stmt->v.AsyncFor.iter, Load) &&
|
||||
validate_body(stmt->v.AsyncFor.body, "AsyncFor") &&
|
||||
validate_stmts(stmt->v.AsyncFor.orelse);
|
||||
break;
|
||||
case While_kind:
|
||||
ret = validate_expr(state, stmt->v.While.test, Load) &&
|
||||
validate_body(state, stmt->v.While.body, "While") &&
|
||||
validate_stmts(state, stmt->v.While.orelse);
|
||||
ret = validate_expr(stmt->v.While.test, Load) &&
|
||||
validate_body(stmt->v.While.body, "While") &&
|
||||
validate_stmts(stmt->v.While.orelse);
|
||||
break;
|
||||
case If_kind:
|
||||
ret = validate_expr(state, stmt->v.If.test, Load) &&
|
||||
validate_body(state, stmt->v.If.body, "If") &&
|
||||
validate_stmts(state, stmt->v.If.orelse);
|
||||
ret = validate_expr(stmt->v.If.test, Load) &&
|
||||
validate_body(stmt->v.If.body, "If") &&
|
||||
validate_stmts(stmt->v.If.orelse);
|
||||
break;
|
||||
case With_kind:
|
||||
if (!validate_nonempty_seq(stmt->v.With.items, "items", "With"))
|
||||
return 0;
|
||||
for (Py_ssize_t i = 0; i < asdl_seq_LEN(stmt->v.With.items); i++) {
|
||||
withitem_ty item = asdl_seq_GET(stmt->v.With.items, i);
|
||||
if (!validate_expr(state, item->context_expr, Load) ||
|
||||
(item->optional_vars && !validate_expr(state, item->optional_vars, Store)))
|
||||
if (!validate_expr(item->context_expr, Load) ||
|
||||
(item->optional_vars && !validate_expr(item->optional_vars, Store)))
|
||||
return 0;
|
||||
}
|
||||
ret = validate_body(state, stmt->v.With.body, "With");
|
||||
ret = validate_body(stmt->v.With.body, "With");
|
||||
break;
|
||||
case AsyncWith_kind:
|
||||
if (!validate_nonempty_seq(stmt->v.AsyncWith.items, "items", "AsyncWith"))
|
||||
return 0;
|
||||
for (Py_ssize_t i = 0; i < asdl_seq_LEN(stmt->v.AsyncWith.items); i++) {
|
||||
withitem_ty item = asdl_seq_GET(stmt->v.AsyncWith.items, i);
|
||||
if (!validate_expr(state, item->context_expr, Load) ||
|
||||
(item->optional_vars && !validate_expr(state, item->optional_vars, Store)))
|
||||
if (!validate_expr(item->context_expr, Load) ||
|
||||
(item->optional_vars && !validate_expr(item->optional_vars, Store)))
|
||||
return 0;
|
||||
}
|
||||
ret = validate_body(state, stmt->v.AsyncWith.body, "AsyncWith");
|
||||
ret = validate_body(stmt->v.AsyncWith.body, "AsyncWith");
|
||||
break;
|
||||
case Match_kind:
|
||||
if (!validate_expr(state, stmt->v.Match.subject, Load)
|
||||
if (!validate_expr(stmt->v.Match.subject, Load)
|
||||
|| !validate_nonempty_seq(stmt->v.Match.cases, "cases", "Match")) {
|
||||
return 0;
|
||||
}
|
||||
for (Py_ssize_t i = 0; i < asdl_seq_LEN(stmt->v.Match.cases); i++) {
|
||||
match_case_ty m = asdl_seq_GET(stmt->v.Match.cases, i);
|
||||
if (!validate_pattern(state, m->pattern, /*star_ok=*/0)
|
||||
|| (m->guard && !validate_expr(state, m->guard, Load))
|
||||
|| !validate_body(state, m->body, "match_case")) {
|
||||
if (!validate_pattern(m->pattern, /*star_ok=*/0)
|
||||
|| (m->guard && !validate_expr(m->guard, Load))
|
||||
|| !validate_body(m->body, "match_case")) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -841,8 +829,8 @@ validate_stmt(struct validator *state, stmt_ty stmt)
|
|||
break;
|
||||
case Raise_kind:
|
||||
if (stmt->v.Raise.exc) {
|
||||
ret = validate_expr(state, stmt->v.Raise.exc, Load) &&
|
||||
(!stmt->v.Raise.cause || validate_expr(state, stmt->v.Raise.cause, Load));
|
||||
ret = validate_expr(stmt->v.Raise.exc, Load) &&
|
||||
(!stmt->v.Raise.cause || validate_expr(stmt->v.Raise.cause, Load));
|
||||
break;
|
||||
}
|
||||
if (stmt->v.Raise.cause) {
|
||||
|
@ -852,7 +840,7 @@ validate_stmt(struct validator *state, stmt_ty stmt)
|
|||
ret = 1;
|
||||
break;
|
||||
case Try_kind:
|
||||
if (!validate_body(state, stmt->v.Try.body, "Try"))
|
||||
if (!validate_body(stmt->v.Try.body, "Try"))
|
||||
return 0;
|
||||
if (!asdl_seq_LEN(stmt->v.Try.handlers) &&
|
||||
!asdl_seq_LEN(stmt->v.Try.finalbody)) {
|
||||
|
@ -868,17 +856,17 @@ validate_stmt(struct validator *state, stmt_ty stmt)
|
|||
excepthandler_ty handler = asdl_seq_GET(stmt->v.Try.handlers, i);
|
||||
VALIDATE_POSITIONS(handler);
|
||||
if ((handler->v.ExceptHandler.type &&
|
||||
!validate_expr(state, handler->v.ExceptHandler.type, Load)) ||
|
||||
!validate_body(state, handler->v.ExceptHandler.body, "ExceptHandler"))
|
||||
!validate_expr(handler->v.ExceptHandler.type, Load)) ||
|
||||
!validate_body(handler->v.ExceptHandler.body, "ExceptHandler"))
|
||||
return 0;
|
||||
}
|
||||
ret = (!asdl_seq_LEN(stmt->v.Try.finalbody) ||
|
||||
validate_stmts(state, stmt->v.Try.finalbody)) &&
|
||||
validate_stmts(stmt->v.Try.finalbody)) &&
|
||||
(!asdl_seq_LEN(stmt->v.Try.orelse) ||
|
||||
validate_stmts(state, stmt->v.Try.orelse));
|
||||
validate_stmts(stmt->v.Try.orelse));
|
||||
break;
|
||||
case TryStar_kind:
|
||||
if (!validate_body(state, stmt->v.TryStar.body, "TryStar"))
|
||||
if (!validate_body(stmt->v.TryStar.body, "TryStar"))
|
||||
return 0;
|
||||
if (!asdl_seq_LEN(stmt->v.TryStar.handlers) &&
|
||||
!asdl_seq_LEN(stmt->v.TryStar.finalbody)) {
|
||||
|
@ -893,18 +881,18 @@ validate_stmt(struct validator *state, stmt_ty stmt)
|
|||
for (Py_ssize_t i = 0; i < asdl_seq_LEN(stmt->v.TryStar.handlers); i++) {
|
||||
excepthandler_ty handler = asdl_seq_GET(stmt->v.TryStar.handlers, i);
|
||||
if ((handler->v.ExceptHandler.type &&
|
||||
!validate_expr(state, handler->v.ExceptHandler.type, Load)) ||
|
||||
!validate_body(state, handler->v.ExceptHandler.body, "ExceptHandler"))
|
||||
!validate_expr(handler->v.ExceptHandler.type, Load)) ||
|
||||
!validate_body(handler->v.ExceptHandler.body, "ExceptHandler"))
|
||||
return 0;
|
||||
}
|
||||
ret = (!asdl_seq_LEN(stmt->v.TryStar.finalbody) ||
|
||||
validate_stmts(state, stmt->v.TryStar.finalbody)) &&
|
||||
validate_stmts(stmt->v.TryStar.finalbody)) &&
|
||||
(!asdl_seq_LEN(stmt->v.TryStar.orelse) ||
|
||||
validate_stmts(state, stmt->v.TryStar.orelse));
|
||||
validate_stmts(stmt->v.TryStar.orelse));
|
||||
break;
|
||||
case Assert_kind:
|
||||
ret = validate_expr(state, stmt->v.Assert.test, Load) &&
|
||||
(!stmt->v.Assert.msg || validate_expr(state, stmt->v.Assert.msg, Load));
|
||||
ret = validate_expr(stmt->v.Assert.test, Load) &&
|
||||
(!stmt->v.Assert.msg || validate_expr(stmt->v.Assert.msg, Load));
|
||||
break;
|
||||
case Import_kind:
|
||||
ret = validate_nonempty_seq(stmt->v.Import.names, "names", "Import");
|
||||
|
@ -923,15 +911,15 @@ validate_stmt(struct validator *state, stmt_ty stmt)
|
|||
ret = validate_nonempty_seq(stmt->v.Nonlocal.names, "names", "Nonlocal");
|
||||
break;
|
||||
case Expr_kind:
|
||||
ret = validate_expr(state, stmt->v.Expr.value, Load);
|
||||
ret = validate_expr(stmt->v.Expr.value, Load);
|
||||
break;
|
||||
case AsyncFunctionDef_kind:
|
||||
ret = validate_body(state, stmt->v.AsyncFunctionDef.body, "AsyncFunctionDef") &&
|
||||
validate_type_params(state, stmt->v.AsyncFunctionDef.type_params) &&
|
||||
validate_arguments(state, stmt->v.AsyncFunctionDef.args) &&
|
||||
validate_exprs(state, stmt->v.AsyncFunctionDef.decorator_list, Load, 0) &&
|
||||
ret = validate_body(stmt->v.AsyncFunctionDef.body, "AsyncFunctionDef") &&
|
||||
validate_type_params(stmt->v.AsyncFunctionDef.type_params) &&
|
||||
validate_arguments(stmt->v.AsyncFunctionDef.args) &&
|
||||
validate_exprs(stmt->v.AsyncFunctionDef.decorator_list, Load, 0) &&
|
||||
(!stmt->v.AsyncFunctionDef.returns ||
|
||||
validate_expr(state, stmt->v.AsyncFunctionDef.returns, Load));
|
||||
validate_expr(stmt->v.AsyncFunctionDef.returns, Load));
|
||||
break;
|
||||
case Pass_kind:
|
||||
case Break_kind:
|
||||
|
@ -944,18 +932,18 @@ validate_stmt(struct validator *state, stmt_ty stmt)
|
|||
PyErr_SetString(PyExc_SystemError, "unexpected statement");
|
||||
ret = 0;
|
||||
}
|
||||
LEAVE_RECURSIVE(state);
|
||||
LEAVE_RECURSIVE();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
validate_stmts(struct validator *state, asdl_stmt_seq *seq)
|
||||
validate_stmts(asdl_stmt_seq *seq)
|
||||
{
|
||||
assert(!PyErr_Occurred());
|
||||
for (Py_ssize_t i = 0; i < asdl_seq_LEN(seq); i++) {
|
||||
stmt_ty stmt = asdl_seq_GET(seq, i);
|
||||
if (stmt) {
|
||||
if (!validate_stmt(state, stmt))
|
||||
if (!validate_stmt(stmt))
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
|
@ -968,13 +956,13 @@ validate_stmts(struct validator *state, asdl_stmt_seq *seq)
|
|||
}
|
||||
|
||||
static int
|
||||
validate_exprs(struct validator *state, asdl_expr_seq *exprs, expr_context_ty ctx, int null_ok)
|
||||
validate_exprs(asdl_expr_seq *exprs, expr_context_ty ctx, int null_ok)
|
||||
{
|
||||
assert(!PyErr_Occurred());
|
||||
for (Py_ssize_t i = 0; i < asdl_seq_LEN(exprs); i++) {
|
||||
expr_ty expr = asdl_seq_GET(exprs, i);
|
||||
if (expr) {
|
||||
if (!validate_expr(state, expr, ctx))
|
||||
if (!validate_expr(expr, ctx))
|
||||
return 0;
|
||||
}
|
||||
else if (!null_ok) {
|
||||
|
@ -988,12 +976,12 @@ validate_exprs(struct validator *state, asdl_expr_seq *exprs, expr_context_ty ct
|
|||
}
|
||||
|
||||
static int
|
||||
validate_patterns(struct validator *state, asdl_pattern_seq *patterns, int star_ok)
|
||||
validate_patterns(asdl_pattern_seq *patterns, int star_ok)
|
||||
{
|
||||
assert(!PyErr_Occurred());
|
||||
for (Py_ssize_t i = 0; i < asdl_seq_LEN(patterns); i++) {
|
||||
pattern_ty pattern = asdl_seq_GET(patterns, i);
|
||||
if (!validate_pattern(state, pattern, star_ok)) {
|
||||
if (!validate_pattern(pattern, star_ok)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -1001,7 +989,7 @@ validate_patterns(struct validator *state, asdl_pattern_seq *patterns, int star_
|
|||
}
|
||||
|
||||
static int
|
||||
validate_typeparam(struct validator *state, type_param_ty tp)
|
||||
validate_typeparam(type_param_ty tp)
|
||||
{
|
||||
VALIDATE_POSITIONS(tp);
|
||||
int ret = -1;
|
||||
|
@ -1009,32 +997,32 @@ validate_typeparam(struct validator *state, type_param_ty tp)
|
|||
case TypeVar_kind:
|
||||
ret = validate_name(tp->v.TypeVar.name) &&
|
||||
(!tp->v.TypeVar.bound ||
|
||||
validate_expr(state, tp->v.TypeVar.bound, Load)) &&
|
||||
validate_expr(tp->v.TypeVar.bound, Load)) &&
|
||||
(!tp->v.TypeVar.default_value ||
|
||||
validate_expr(state, tp->v.TypeVar.default_value, Load));
|
||||
validate_expr(tp->v.TypeVar.default_value, Load));
|
||||
break;
|
||||
case ParamSpec_kind:
|
||||
ret = validate_name(tp->v.ParamSpec.name) &&
|
||||
(!tp->v.ParamSpec.default_value ||
|
||||
validate_expr(state, tp->v.ParamSpec.default_value, Load));
|
||||
validate_expr(tp->v.ParamSpec.default_value, Load));
|
||||
break;
|
||||
case TypeVarTuple_kind:
|
||||
ret = validate_name(tp->v.TypeVarTuple.name) &&
|
||||
(!tp->v.TypeVarTuple.default_value ||
|
||||
validate_expr(state, tp->v.TypeVarTuple.default_value, Load));
|
||||
validate_expr(tp->v.TypeVarTuple.default_value, Load));
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
validate_type_params(struct validator *state, asdl_type_param_seq *tps)
|
||||
validate_type_params(asdl_type_param_seq *tps)
|
||||
{
|
||||
Py_ssize_t i;
|
||||
for (i = 0; i < asdl_seq_LEN(tps); i++) {
|
||||
type_param_ty tp = asdl_seq_GET(tps, i);
|
||||
if (tp) {
|
||||
if (!validate_typeparam(state, tp))
|
||||
if (!validate_typeparam(tp))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -1046,34 +1034,20 @@ _PyAST_Validate(mod_ty mod)
|
|||
{
|
||||
assert(!PyErr_Occurred());
|
||||
int res = -1;
|
||||
struct validator state;
|
||||
PyThreadState *tstate;
|
||||
int starting_recursion_depth;
|
||||
|
||||
/* Setup recursion depth check counters */
|
||||
tstate = _PyThreadState_GET();
|
||||
if (!tstate) {
|
||||
return 0;
|
||||
}
|
||||
/* Be careful here to prevent overflow. */
|
||||
int recursion_depth = Py_C_RECURSION_LIMIT - tstate->c_recursion_remaining;
|
||||
starting_recursion_depth = recursion_depth;
|
||||
state.recursion_depth = starting_recursion_depth;
|
||||
state.recursion_limit = Py_C_RECURSION_LIMIT;
|
||||
|
||||
switch (mod->kind) {
|
||||
case Module_kind:
|
||||
res = validate_stmts(&state, mod->v.Module.body);
|
||||
res = validate_stmts(mod->v.Module.body);
|
||||
break;
|
||||
case Interactive_kind:
|
||||
res = validate_stmts(&state, mod->v.Interactive.body);
|
||||
res = validate_stmts(mod->v.Interactive.body);
|
||||
break;
|
||||
case Expression_kind:
|
||||
res = validate_expr(&state, mod->v.Expression.body, Load);
|
||||
res = validate_expr(mod->v.Expression.body, Load);
|
||||
break;
|
||||
case FunctionType_kind:
|
||||
res = validate_exprs(&state, mod->v.FunctionType.argtypes, Load, /*null_ok=*/0) &&
|
||||
validate_expr(&state, mod->v.FunctionType.returns, Load);
|
||||
res = validate_exprs(mod->v.FunctionType.argtypes, Load, /*null_ok=*/0) &&
|
||||
validate_expr(mod->v.FunctionType.returns, Load);
|
||||
break;
|
||||
// No default case so compiler emits warning for unhandled cases
|
||||
}
|
||||
|
@ -1082,14 +1056,6 @@ _PyAST_Validate(mod_ty mod)
|
|||
PyErr_SetString(PyExc_SystemError, "impossible module node");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Check that the recursion depth counting balanced correctly */
|
||||
if (res && state.recursion_depth != starting_recursion_depth) {
|
||||
PyErr_Format(PyExc_SystemError,
|
||||
"AST validator recursion depth mismatch (before=%d, after=%d)",
|
||||
starting_recursion_depth, state.recursion_depth);
|
||||
return 0;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue