gh-95756: Lazily created cached co_* attrs (GH-97791)

This commit is contained in:
Ken Jin 2022-10-10 20:26:08 -07:00 committed by GitHub
parent f871e9a7bb
commit b399115ef1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 82 additions and 14 deletions

View file

@ -645,9 +645,12 @@ add_load_fast_null_checks(PyCodeObject *co)
}
i += _PyOpcode_Caches[_PyOpcode_Deopt[opcode]];
}
if (changed) {
if (changed && co->_co_cached != NULL) {
// invalidate cached co_code object
Py_CLEAR(co->_co_code);
Py_CLEAR(co->_co_cached->_co_code);
Py_CLEAR(co->_co_cached->_co_cellvars);
Py_CLEAR(co->_co_cached->_co_freevars);
Py_CLEAR(co->_co_cached->_co_varnames);
}
}