Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
implement suggestion
  • Loading branch information
kumaraditya303 committed Mar 30, 2026
commit 13645606e21e520aeaa34b70b2d45677d57c03a9
19 changes: 7 additions & 12 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -11601,7 +11601,7 @@ static pytype_slotdef slotdefs[] = {
/* Stores the number of times where slotdefs has elements with same name.
This counter precalculated by _PyType_InitSlotDefs() when the main
interpreter starts. */
static uint8_t slotdefs_name_counts[Py_ARRAY_LENGTH(slotdefs)];
static uint8_t slotdefs_dups[Py_ARRAY_LENGTH(slotdefs)][1 + MAX_EQUIV];

/* Given a type pointer and an offset gotten from a slotdef entry, return a
pointer to the actual slot. This is not quite the same as simply adding
Expand Down Expand Up @@ -11768,15 +11768,10 @@ update_one_slot(PyTypeObject *type, pytype_slotdef *p, pytype_slotdef **next_p,
((PyWrapperDescrObject *)descr)->d_base->name_strobj == p->name_strobj) {
void **tptr;
size_t index = (p - slotdefs);
if (slotdefs_name_counts[index] > 1) {
/* If multiple slotdefs have the same name,
* if we need to check that only one of them has the slot filled
* and return that, else return NULL.
*/
if (slotdefs_dups[index][0] > 1) {
tptr = NULL;
for (pytype_slotdef *q = slotdefs; q->name_strobj; q++) {
if (q->name_strobj != p->name_strobj)
continue;
for (size_t i = 0; i < slotdefs_dups[index][0]; i++) {
pytype_slotdef *q = &slotdefs[slotdefs_dups[index][i + 1]];
void **qptr = slotptr(type, q->offset);
if (qptr == NULL || *qptr == NULL)
continue;
Expand All @@ -11788,7 +11783,7 @@ update_one_slot(PyTypeObject *type, pytype_slotdef *p, pytype_slotdef **next_p,
}
}
else {
tptr = slotptr(type, p->offset);
tptr = slotptr(type, offset);
}

if (tptr == NULL || tptr == ptr)
Expand Down Expand Up @@ -12050,7 +12045,7 @@ _PyType_InitSlotDefs(PyInterpreterState *interp)
Py_CLEAR(bytearray);
}

memset(slotdefs_name_counts, 0, sizeof(slotdefs_name_counts));
memset(slotdefs_dups, -1, sizeof(slotdefs_dups));

Py_ssize_t pos = 0;
PyObject *key = NULL;
Expand All @@ -12060,7 +12055,7 @@ _PyType_InitSlotDefs(PyInterpreterState *interp)
uint8_t n = data[0];
for (uint8_t i = 0; i < n; i++) {
uint8_t idx = data[i + 1];
slotdefs_name_counts[idx] = n;
memcpy(&slotdefs_dups[idx], data, sizeof(uint8_t) * (n + 1));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tools/c-analyzer/cpython/ignored.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ Objects/obmalloc.c - obmalloc_state_initialized -
Objects/typeobject.c - name_op -
Objects/typeobject.c - slotdefs -
# It initialized only once when main interpeter starts
Objects/typeobject.c - slotdefs_name_counts -
Objects/typeobject.c - slotdefs_dups -
Objects/unicodeobject.c - stripfuncnames -
Objects/unicodeobject.c - utf7_category -
Objects/unicodeobject.c unicode_decode_call_errorhandler_wchar argparse -
Expand Down
Loading