Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-132835: Add defensive NULL checks in mro resolution#134763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
emmatyping wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
fromemmatyping:check-mro-lookup-not-null
Open
Changes from2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletionsObjects/typeobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1641,7 +1641,7 @@ static int recurse_down_subclasses(PyTypeObject *type, PyObject *name,
update_callback callback, void *data);

static int
mro_hierarchy(PyTypeObject *type, PyObject *temp)
mro_hierarchy_for_complete_type(PyTypeObject *type, PyObject *temp)
{
ASSERT_TYPE_LOCK_HELD();

Expand All@@ -1652,6 +1652,7 @@ mro_hierarchy(PyTypeObject *type, PyObject *temp)
return res;
}
PyObject *new_mro = lookup_tp_mro(type);
assert(new_mro != NULL);

PyObject *tuple;
if (old_mro != NULL) {
Expand DownExpand Up@@ -1696,7 +1697,7 @@ mro_hierarchy(PyTypeObject *type, PyObject *temp)
Py_ssize_t n = PyList_GET_SIZE(subclasses);
for (Py_ssize_t i = 0; i < n; i++) {
PyTypeObject *subclass = _PyType_CAST(PyList_GET_ITEM(subclasses, i));
res =mro_hierarchy(subclass, temp);
res =mro_hierarchy_for_complete_type(subclass, temp);
if (res < 0) {
break;
}
Expand DownExpand Up@@ -1778,7 +1779,7 @@ type_set_bases_unlocked(PyTypeObject *type, PyObject *new_bases)
if (temp == NULL) {
goto bail;
}
if (mro_hierarchy(type, temp) < 0) {
if (mro_hierarchy_for_complete_type(type, temp) < 0) {
goto undo;
}
Py_DECREF(temp);
Expand DownExpand Up@@ -3274,6 +3275,7 @@ mro_implementation_unlocked(PyTypeObject *type)
*/
PyTypeObject *base = _PyType_CAST(PyTuple_GET_ITEM(bases, 0));
PyObject *base_mro = lookup_tp_mro(base);
assert(base_mro != NULL);
Py_ssize_t k = PyTuple_GET_SIZE(base_mro);
PyObject *result = PyTuple_New(k + 1);
if (result == NULL) {
Expand DownExpand Up@@ -3308,9 +3310,12 @@ mro_implementation_unlocked(PyTypeObject *type)
return NULL;
}

PyObject *mro_to_merge;
for (Py_ssize_t i = 0; i < n; i++) {
PyTypeObject *base = _PyType_CAST(PyTuple_GET_ITEM(bases, i));
to_merge[i] = lookup_tp_mro(base);
mro_to_merge = lookup_tp_mro(base);
assert(mro_to_merge != NULL);
to_merge[i] = mro_to_merge;
}
to_merge[n] = bases;

Expand DownExpand Up@@ -8598,6 +8603,7 @@ type_ready_inherit(PyTypeObject *type)

// Inherit slots
PyObject *mro = lookup_tp_mro(type);
assert(mro != NULL);
Py_ssize_t n = PyTuple_GET_SIZE(mro);
for (Py_ssize_t i = 1; i < n; i++) {
PyObject *b = PyTuple_GET_ITEM(mro, i);
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp