mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
[3.13] gh-128632: fix segfault on nested __classdict__ type param (GH-128744) (#132085)
(cherry picked from commit 891c61c1fa)
Co-authored-by: Tomasz Pytel <tompytel@gmail.com>
This commit is contained in:
parent
d8986b7f5e
commit
900dc2b034
4 changed files with 53 additions and 13 deletions
|
|
@ -503,7 +503,7 @@ compute_localsplus_info(_PyCompile_CodeUnitMetadata *umd, int nlocalsplus,
|
|||
int nlocals = (int)PyDict_GET_SIZE(umd->u_varnames);
|
||||
|
||||
// This counter mirrors the fix done in fix_cell_offsets().
|
||||
int numdropped = 0;
|
||||
int numdropped = 0, cellvar_offset = -1;
|
||||
pos = 0;
|
||||
while (PyDict_Next(umd->u_cellvars, &pos, &k, &v)) {
|
||||
int has_name = PyDict_Contains(umd->u_varnames, k);
|
||||
|
|
@ -514,14 +514,14 @@ compute_localsplus_info(_PyCompile_CodeUnitMetadata *umd, int nlocalsplus,
|
|||
continue;
|
||||
}
|
||||
|
||||
int offset = PyLong_AsInt(v);
|
||||
if (offset == -1 && PyErr_Occurred()) {
|
||||
cellvar_offset = PyLong_AsInt(v);
|
||||
if (cellvar_offset == -1 && PyErr_Occurred()) {
|
||||
return ERROR;
|
||||
}
|
||||
assert(offset >= 0);
|
||||
offset += nlocals - numdropped;
|
||||
assert(offset < nlocalsplus);
|
||||
_Py_set_localsplus_info(offset, k, CO_FAST_CELL, names, kinds);
|
||||
assert(cellvar_offset >= 0);
|
||||
cellvar_offset += nlocals - numdropped;
|
||||
assert(cellvar_offset < nlocalsplus);
|
||||
_Py_set_localsplus_info(cellvar_offset, k, CO_FAST_CELL, names, kinds);
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
|
|
@ -533,6 +533,10 @@ compute_localsplus_info(_PyCompile_CodeUnitMetadata *umd, int nlocalsplus,
|
|||
assert(offset >= 0);
|
||||
offset += nlocals - numdropped;
|
||||
assert(offset < nlocalsplus);
|
||||
/* XXX If the assertion below fails it is most likely because a freevar
|
||||
was added to u_freevars with the wrong index due to not taking into
|
||||
account cellvars already present, see gh-128632. */
|
||||
assert(offset > cellvar_offset);
|
||||
_Py_set_localsplus_info(offset, k, CO_FAST_FREE, names, kinds);
|
||||
}
|
||||
return SUCCESS;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue