Skip to content

Commit 24499ff

Browse files
committed
gh-162752: Assert that the slotdefs of a slot share a function
The slotdefs that fill the same slot all name the same generic function, since that function has to dispatch to every one of their special methods. The check that lets a special method assignment skip the stop-the-world depends on it: it compares a slot with the function of the slotdef for the assigned name, while update_one_slot() stores that of whichever slotdef it handled last. If they ever differed, slots that are up to date could fail the comparison and stop the world on every assignment. Assert it when the slotdefs are initialized. Co-authored with Claude Fable 5.2
1 parent d935e60 commit 24499ff

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎Objects/typeobject.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12482,6 +12482,18 @@ _PyType_InitSlotDefs(PyInterpreterState *interp)
1248212482
}
1248312483
init_slotname_table();
1248412484

12485+
#ifndef NDEBUG
12486+
/* The slotdefs of a slot (they are adjacent) share one generic function,
12487+
which dispatches to all of their names. slots_are_generic() compares
12488+
a slot with the function of the slotdef for the assigned name, while
12489+
update_one_slot() stores that of whichever slotdef it handled last.
12490+
If they differed, that comparison could fail for up to date slots. */
12491+
for (pytype_slotdef *p = slotdefs + 1; p->name != NULL; p++) {
12492+
assert(p->offset != (p - 1)->offset
12493+
|| p->function == (p - 1)->function);
12494+
}
12495+
#endif
12496+
1248512497
/* Group the slotdefs by name: slotdefs_dups[i] lists the indices of
1248612498
all slotdefs with the same name as slotdefs[i], in slotdefs order. */
1248712499
memset(slotdefs_dups, 0, sizeof(slotdefs_dups));

0 commit comments

Comments
 (0)