mirror of
https://github.com/python/cpython.git
synced 2025-07-19 09:15:34 +00:00
bpo-33132: Fix reference counting issues in the compiler. (GH-6209)
This commit is contained in:
parent
4ca0739c9d
commit
a95d98607e
1 changed files with 12 additions and 19 deletions
|
@ -2909,9 +2909,7 @@ static int
|
||||||
compiler_from_import(struct compiler *c, stmt_ty s)
|
compiler_from_import(struct compiler *c, stmt_ty s)
|
||||||
{
|
{
|
||||||
Py_ssize_t i, n = asdl_seq_LEN(s->v.ImportFrom.names);
|
Py_ssize_t i, n = asdl_seq_LEN(s->v.ImportFrom.names);
|
||||||
|
PyObject *level, *names;
|
||||||
PyObject *names = PyTuple_New(n);
|
|
||||||
PyObject *level;
|
|
||||||
static PyObject *empty_string;
|
static PyObject *empty_string;
|
||||||
|
|
||||||
if (!empty_string) {
|
if (!empty_string) {
|
||||||
|
@ -2920,14 +2918,15 @@ compiler_from_import(struct compiler *c, stmt_ty s)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!names)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
level = PyLong_FromLong(s->v.ImportFrom.level);
|
level = PyLong_FromLong(s->v.ImportFrom.level);
|
||||||
if (!level) {
|
if (!level) {
|
||||||
Py_DECREF(names);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
ADDOP_N(c, LOAD_CONST, level, consts);
|
||||||
|
|
||||||
|
names = PyTuple_New(n);
|
||||||
|
if (!names)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* build up the names */
|
/* build up the names */
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
|
@ -2938,16 +2937,12 @@ compiler_from_import(struct compiler *c, stmt_ty s)
|
||||||
|
|
||||||
if (s->lineno > c->c_future->ff_lineno && s->v.ImportFrom.module &&
|
if (s->lineno > c->c_future->ff_lineno && s->v.ImportFrom.module &&
|
||||||
_PyUnicode_EqualToASCIIString(s->v.ImportFrom.module, "__future__")) {
|
_PyUnicode_EqualToASCIIString(s->v.ImportFrom.module, "__future__")) {
|
||||||
Py_DECREF(level);
|
|
||||||
Py_DECREF(names);
|
Py_DECREF(names);
|
||||||
return compiler_error(c, "from __future__ imports must occur "
|
return compiler_error(c, "from __future__ imports must occur "
|
||||||
"at the beginning of the file");
|
"at the beginning of the file");
|
||||||
}
|
}
|
||||||
|
ADDOP_N(c, LOAD_CONST, names, consts);
|
||||||
|
|
||||||
ADDOP_O(c, LOAD_CONST, level, consts);
|
|
||||||
Py_DECREF(level);
|
|
||||||
ADDOP_O(c, LOAD_CONST, names, consts);
|
|
||||||
Py_DECREF(names);
|
|
||||||
if (s->v.ImportFrom.module) {
|
if (s->v.ImportFrom.module) {
|
||||||
ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names);
|
ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names);
|
||||||
}
|
}
|
||||||
|
@ -2970,7 +2965,6 @@ compiler_from_import(struct compiler *c, stmt_ty s)
|
||||||
store_name = alias->asname;
|
store_name = alias->asname;
|
||||||
|
|
||||||
if (!compiler_nameop(c, store_name, Store)) {
|
if (!compiler_nameop(c, store_name, Store)) {
|
||||||
Py_DECREF(names);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4739,10 +4733,6 @@ compiler_annassign(struct compiler *c, stmt_ty s)
|
||||||
if (s->v.AnnAssign.simple &&
|
if (s->v.AnnAssign.simple &&
|
||||||
(c->u->u_scope_type == COMPILER_SCOPE_MODULE ||
|
(c->u->u_scope_type == COMPILER_SCOPE_MODULE ||
|
||||||
c->u->u_scope_type == COMPILER_SCOPE_CLASS)) {
|
c->u->u_scope_type == COMPILER_SCOPE_CLASS)) {
|
||||||
mangled = _Py_Mangle(c->u->u_private, targ->v.Name.id);
|
|
||||||
if (!mangled) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (c->c_future->ff_features & CO_FUTURE_ANNOTATIONS) {
|
if (c->c_future->ff_features & CO_FUTURE_ANNOTATIONS) {
|
||||||
VISIT(c, annexpr, s->v.AnnAssign.annotation)
|
VISIT(c, annexpr, s->v.AnnAssign.annotation)
|
||||||
}
|
}
|
||||||
|
@ -4750,8 +4740,11 @@ compiler_annassign(struct compiler *c, stmt_ty s)
|
||||||
VISIT(c, expr, s->v.AnnAssign.annotation);
|
VISIT(c, expr, s->v.AnnAssign.annotation);
|
||||||
}
|
}
|
||||||
ADDOP_NAME(c, LOAD_NAME, __annotations__, names);
|
ADDOP_NAME(c, LOAD_NAME, __annotations__, names);
|
||||||
ADDOP_O(c, LOAD_CONST, mangled, consts);
|
mangled = _Py_Mangle(c->u->u_private, targ->v.Name.id);
|
||||||
Py_DECREF(mangled);
|
if (!mangled) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ADDOP_N(c, LOAD_CONST, mangled, consts);
|
||||||
ADDOP(c, STORE_SUBSCR);
|
ADDOP(c, STORE_SUBSCR);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue