mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Last batch of ref leaks in new AST code.
Also converted a bunch of assert(0) to SystemError's. There are still printfs, etc that need to be cleaned up.
This commit is contained in:
parent
5040fee5c1
commit
4737b2348b
2 changed files with 58 additions and 29 deletions
|
@ -332,6 +332,7 @@ list2dict(PyObject *list)
|
||||||
Py_DECREF(dict);
|
Py_DECREF(dict);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Py_DECREF(k);
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
}
|
}
|
||||||
return dict;
|
return dict;
|
||||||
|
@ -511,7 +512,9 @@ fold_binops_on_constants(unsigned char *codestr, PyObject *consts)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* Called with an unknown opcode */
|
/* Called with an unknown opcode */
|
||||||
assert(0);
|
PyErr_Format(PyExc_SystemError,
|
||||||
|
"unexpected binary operation %d on a constant",
|
||||||
|
opcode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (newconst == NULL) {
|
if (newconst == NULL) {
|
||||||
|
@ -568,7 +571,9 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* Called with an unknown opcode */
|
/* Called with an unknown opcode */
|
||||||
assert(0);
|
PyErr_Format(PyExc_SystemError,
|
||||||
|
"unexpected unary operation %d on a constant",
|
||||||
|
opcode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (newconst == NULL) {
|
if (newconst == NULL) {
|
||||||
|
@ -1746,11 +1751,14 @@ compiler_mod(struct compiler *c, mod_ty mod)
|
||||||
addNone = 0;
|
addNone = 0;
|
||||||
break;
|
break;
|
||||||
case Suite_kind:
|
case Suite_kind:
|
||||||
assert(0); /* XXX: what should we do here? */
|
PyErr_SetString(PyExc_SystemError,
|
||||||
VISIT_SEQ_IN_SCOPE(c, stmt, mod->v.Suite.body);
|
"suite should not be possible");
|
||||||
break;
|
return 0;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
PyErr_Format(PyExc_SystemError,
|
||||||
|
"module kind %d should not be possible",
|
||||||
|
mod->kind);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
co = assemble(c, addNone);
|
co = assemble(c, addNone);
|
||||||
compiler_exit_scope(c);
|
compiler_exit_scope(c);
|
||||||
|
@ -1929,6 +1937,7 @@ compiler_function(struct compiler *c, stmt_ty s)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
compiler_make_closure(c, co, asdl_seq_LEN(args->defaults));
|
compiler_make_closure(c, co, asdl_seq_LEN(args->defaults));
|
||||||
|
Py_DECREF(co);
|
||||||
|
|
||||||
for (i = 0; i < asdl_seq_LEN(decos); i++) {
|
for (i = 0; i < asdl_seq_LEN(decos); i++) {
|
||||||
ADDOP_I(c, CALL_FUNCTION, 1);
|
ADDOP_I(c, CALL_FUNCTION, 1);
|
||||||
|
@ -1984,6 +1993,8 @@ compiler_class(struct compiler *c, stmt_ty s)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
compiler_make_closure(c, co, 0);
|
compiler_make_closure(c, co, 0);
|
||||||
|
Py_DECREF(co);
|
||||||
|
|
||||||
ADDOP_I(c, CALL_FUNCTION, 0);
|
ADDOP_I(c, CALL_FUNCTION, 0);
|
||||||
ADDOP(c, BUILD_CLASS);
|
ADDOP(c, BUILD_CLASS);
|
||||||
if (!compiler_nameop(c, s->v.ClassDef.name, Store))
|
if (!compiler_nameop(c, s->v.ClassDef.name, Store))
|
||||||
|
@ -2009,7 +2020,7 @@ compiler_lambda(struct compiler *c, expr_ty e)
|
||||||
VISIT_SEQ(c, expr, args->defaults);
|
VISIT_SEQ(c, expr, args->defaults);
|
||||||
if (!compiler_enter_scope(c, name, (void *)e, e->lineno))
|
if (!compiler_enter_scope(c, name, (void *)e, e->lineno))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* unpack nested arguments */
|
/* unpack nested arguments */
|
||||||
compiler_arguments(c, args);
|
compiler_arguments(c, args);
|
||||||
|
|
||||||
|
@ -2022,6 +2033,7 @@ compiler_lambda(struct compiler *c, expr_ty e)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
compiler_make_closure(c, co, asdl_seq_LEN(args->defaults));
|
compiler_make_closure(c, co, asdl_seq_LEN(args->defaults));
|
||||||
|
Py_DECREF(co);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -2734,7 +2746,9 @@ inplace_binop(struct compiler *c, operator_ty op)
|
||||||
case FloorDiv:
|
case FloorDiv:
|
||||||
return INPLACE_FLOOR_DIVIDE;
|
return INPLACE_FLOOR_DIVIDE;
|
||||||
}
|
}
|
||||||
assert(0);
|
PyErr_Format(PyExc_SystemError,
|
||||||
|
"inplace binary op %d should not be possible",
|
||||||
|
op);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2802,9 +2816,10 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
|
||||||
PyString_AS_STRING(name));
|
PyString_AS_STRING(name));
|
||||||
Py_DECREF(mangled);
|
Py_DECREF(mangled);
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
|
||||||
case Param:
|
case Param:
|
||||||
assert(0); /* impossible */
|
PyErr_SetString(PyExc_SystemError,
|
||||||
|
"param invalid for deref variable");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OP_FAST:
|
case OP_FAST:
|
||||||
|
@ -2816,7 +2831,9 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
|
||||||
case AugStore:
|
case AugStore:
|
||||||
break;
|
break;
|
||||||
case Param:
|
case Param:
|
||||||
assert(0); /* impossible */
|
PyErr_SetString(PyExc_SystemError,
|
||||||
|
"param invalid for local variable");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
ADDOP_O(c, op, mangled, varnames);
|
ADDOP_O(c, op, mangled, varnames);
|
||||||
Py_DECREF(mangled);
|
Py_DECREF(mangled);
|
||||||
|
@ -2830,7 +2847,9 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
|
||||||
case AugStore:
|
case AugStore:
|
||||||
break;
|
break;
|
||||||
case Param:
|
case Param:
|
||||||
assert(0); /* impossible */
|
PyErr_SetString(PyExc_SystemError,
|
||||||
|
"param invalid for global variable");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case OP_NAME:
|
case OP_NAME:
|
||||||
|
@ -2842,16 +2861,18 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
|
||||||
case AugStore:
|
case AugStore:
|
||||||
break;
|
break;
|
||||||
case Param:
|
case Param:
|
||||||
assert(0); /* impossible */
|
PyErr_SetString(PyExc_SystemError,
|
||||||
|
"param invalid for name variable");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(op);
|
assert(op);
|
||||||
arg = compiler_add_o(c, dict, mangled);
|
arg = compiler_add_o(c, dict, mangled);
|
||||||
|
Py_DECREF(mangled);
|
||||||
if (arg < 0)
|
if (arg < 0)
|
||||||
return 0;
|
return 0;
|
||||||
Py_DECREF(mangled);
|
|
||||||
return compiler_addop_i(c, op, arg);
|
return compiler_addop_i(c, op, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3196,6 +3217,8 @@ compiler_genexp(struct compiler *c, expr_ty e)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
compiler_make_closure(c, co, 0);
|
compiler_make_closure(c, co, 0);
|
||||||
|
Py_DECREF(co);
|
||||||
|
|
||||||
VISIT(c, expr, outermost_iter);
|
VISIT(c, expr, outermost_iter);
|
||||||
ADDOP(c, GET_ITER);
|
ADDOP(c, GET_ITER);
|
||||||
ADDOP_I(c, CALL_FUNCTION, 1);
|
ADDOP_I(c, CALL_FUNCTION, 1);
|
||||||
|
@ -3325,8 +3348,9 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
|
||||||
ADDOP_NAME(c, DELETE_ATTR, e->v.Attribute.attr, names);
|
ADDOP_NAME(c, DELETE_ATTR, e->v.Attribute.attr, names);
|
||||||
break;
|
break;
|
||||||
case Param:
|
case Param:
|
||||||
assert(0);
|
PyErr_SetString(PyExc_SystemError,
|
||||||
break;
|
"param invalid in attribute expression");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Subscript_kind:
|
case Subscript_kind:
|
||||||
|
@ -3351,8 +3375,9 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
|
||||||
VISIT_SLICE(c, e->v.Subscript.slice, Del);
|
VISIT_SLICE(c, e->v.Subscript.slice, Del);
|
||||||
break;
|
break;
|
||||||
case Param:
|
case Param:
|
||||||
assert(0);
|
PyErr_SetString(PyExc_SystemError,
|
||||||
break;
|
"param invalid in subscript expression");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Name_kind:
|
case Name_kind:
|
||||||
|
@ -3562,9 +3587,10 @@ compiler_simple_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
|
||||||
case AugStore:/* fall through to Store */
|
case AugStore:/* fall through to Store */
|
||||||
case Store: op = STORE_SLICE; break;
|
case Store: op = STORE_SLICE; break;
|
||||||
case Del: op = DELETE_SLICE; break;
|
case Del: op = DELETE_SLICE; break;
|
||||||
case Param: /* XXX impossible? */
|
case Param:
|
||||||
fprintf(stderr, "param invalid\n");
|
PyErr_SetString(PyExc_SystemError,
|
||||||
assert(0);
|
"param invalid in simple slice");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ADDOP(c, op + slice_offset);
|
ADDOP(c, op + slice_offset);
|
||||||
|
@ -3586,8 +3612,9 @@ compiler_visit_nested_slice(struct compiler *c, slice_ty s,
|
||||||
VISIT(c, expr, s->v.Index.value);
|
VISIT(c, expr, s->v.Index.value);
|
||||||
break;
|
break;
|
||||||
case ExtSlice_kind:
|
case ExtSlice_kind:
|
||||||
assert(0);
|
PyErr_SetString(PyExc_SystemError,
|
||||||
break;
|
"extended slice invalid in nested slice");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -3612,7 +3639,6 @@ compiler_visit_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
|
||||||
ADDOP(c, ROT_THREE);
|
ADDOP(c, ROT_THREE);
|
||||||
}
|
}
|
||||||
return compiler_handle_subscr(c, "slice", ctx);
|
return compiler_handle_subscr(c, "slice", ctx);
|
||||||
break;
|
|
||||||
case ExtSlice_kind: {
|
case ExtSlice_kind: {
|
||||||
int i, n = asdl_seq_LEN(s->v.ExtSlice.dims);
|
int i, n = asdl_seq_LEN(s->v.ExtSlice.dims);
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
|
@ -3622,7 +3648,6 @@ compiler_visit_slice(struct compiler *c, slice_ty s, expr_context_ty ctx)
|
||||||
}
|
}
|
||||||
ADDOP_I(c, BUILD_TUPLE, n);
|
ADDOP_I(c, BUILD_TUPLE, n);
|
||||||
return compiler_handle_subscr(c, "extended slice", ctx);
|
return compiler_handle_subscr(c, "extended slice", ctx);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case Index_kind:
|
case Index_kind:
|
||||||
if (ctx != AugStore)
|
if (ctx != AugStore)
|
||||||
|
|
|
@ -731,7 +731,6 @@ symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
|
||||||
if (st->st_cur) {
|
if (st->st_cur) {
|
||||||
prev = st->st_cur;
|
prev = st->st_cur;
|
||||||
if (PyList_Append(st->st_stack, (PyObject *)st->st_cur) < 0) {
|
if (PyList_Append(st->st_stack, (PyObject *)st->st_cur) < 0) {
|
||||||
Py_DECREF(st->st_cur);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Py_DECREF(st->st_cur);
|
Py_DECREF(st->st_cur);
|
||||||
|
@ -814,6 +813,7 @@ symtable_add_def(struct symtable *st, PyObject *name, int flag)
|
||||||
}
|
}
|
||||||
Py_DECREF(o);
|
Py_DECREF(o);
|
||||||
}
|
}
|
||||||
|
Py_DECREF(mangled);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -1087,9 +1087,10 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
|
||||||
|
|
||||||
PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
|
PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
|
||||||
++st->st_cur->ste_tmpname);
|
++st->st_cur->ste_tmpname);
|
||||||
tmp = PyString_FromString(tmpname);
|
tmp = PyString_InternFromString(tmpname);
|
||||||
if (!symtable_add_def(st, tmp, DEF_LOCAL))
|
if (!symtable_add_def(st, tmp, DEF_LOCAL))
|
||||||
return 0;
|
return 0;
|
||||||
|
Py_DECREF(tmp);
|
||||||
VISIT(st, expr, e->v.ListComp.elt);
|
VISIT(st, expr, e->v.ListComp.elt);
|
||||||
VISIT_SEQ(st, comprehension, e->v.ListComp.generators);
|
VISIT_SEQ(st, comprehension, e->v.ListComp.generators);
|
||||||
break;
|
break;
|
||||||
|
@ -1186,8 +1187,10 @@ symtable_visit_params(struct symtable *st, asdl_seq *args, int toplevel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* syntax error */
|
PyErr_SetString(PyExc_SyntaxError,
|
||||||
fprintf(stderr, "unexpected expr in parameter list\n");
|
"invalid expression in parameter list");
|
||||||
|
PyErr_SyntaxLocation(st->st_filename,
|
||||||
|
st->st_cur->ste_lineno);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1279,6 +1282,7 @@ symtable_visit_alias(struct symtable *st, alias_ty a)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
st->st_cur->ste_unoptimized |= OPT_IMPORT_STAR;
|
st->st_cur->ste_unoptimized |= OPT_IMPORT_STAR;
|
||||||
|
Py_DECREF(store_name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue