mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-117266: Fix crashes on user-created AST subclasses (GH-117276)
Fix crashes on user-created AST subclasses
This commit is contained in:
parent
8cb7d7ff86
commit
4c71d51a4b
4 changed files with 69 additions and 4 deletions
15
Python/Python-ast.c
generated
15
Python/Python-ast.c
generated
|
@ -5119,11 +5119,22 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
|
|||
Py_ssize_t size = PySet_Size(remaining_fields);
|
||||
PyObject *field_types = NULL, *remaining_list = NULL;
|
||||
if (size > 0) {
|
||||
if (!PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), &_Py_ID(_field_types),
|
||||
&field_types)) {
|
||||
if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), &_Py_ID(_field_types),
|
||||
&field_types) < 0) {
|
||||
res = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
if (field_types == NULL) {
|
||||
if (PyErr_WarnFormat(
|
||||
PyExc_DeprecationWarning, 1,
|
||||
"%.400s provides _fields but not _field_types. "
|
||||
"This will become an error in Python 3.15.",
|
||||
Py_TYPE(self)->tp_name
|
||||
) < 0) {
|
||||
res = -1;
|
||||
}
|
||||
goto cleanup;
|
||||
}
|
||||
remaining_list = PySequence_List(remaining_fields);
|
||||
if (!remaining_list) {
|
||||
goto set_remaining_cleanup;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue