Skip to content

Commit 4bbf340

Browse files
add multiple slotdefs check
1 parent 6932c3e commit 4bbf340

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

Objects/typeobject.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11768,11 +11768,27 @@ update_one_slot(PyTypeObject *type, pytype_slotdef *p, pytype_slotdef **next_p,
1176811768
((PyWrapperDescrObject *)descr)->d_base->name_strobj == p->name_strobj) {
1176911769
void **tptr;
1177011770
size_t index = (p - slotdefs);
11771-
if (slotdefs_name_counts[index] == 1) {
11772-
tptr = slotptr(type, p->offset);
11771+
if (slotdefs_name_counts[index] > 1) {
11772+
/* If multiple slotdefs have the same name,
11773+
* if we need to check that only one of them has the slot filled
11774+
* and return that, else return NULL.
11775+
*/
11776+
tptr = NULL;
11777+
for (pytype_slotdef *q = slotdefs; q->name_strobj; q++) {
11778+
if (q->name_strobj != p->name_strobj)
11779+
continue;
11780+
void **qptr = slotptr(type, q->offset);
11781+
if (qptr == NULL || *qptr == NULL)
11782+
continue;
11783+
if (tptr != NULL) {
11784+
tptr = NULL;
11785+
break;
11786+
}
11787+
tptr = qptr;
11788+
}
1177311789
}
1177411790
else {
11775-
tptr = NULL;
11791+
tptr = slotptr(type, p->offset);
1177611792
}
1177711793

1177811794
if (tptr == NULL || tptr == ptr)

0 commit comments

Comments
 (0)