Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a memory regression for classes that have both ``__slots__`` and
``__dict__``.
14 changes: 13 additions & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -4621,7 +4621,19 @@ type_new_descriptors(const type_new_ctx *ctx, PyTypeObject *type)
}

type->tp_basicsize = slotoffset;
type->tp_itemsize = ctx->base->tp_itemsize;

// Only inherit tp_itemsize if this type defines its own __slots__
// Classes that don't define __slots__ but inherit from __slots__ classes
// should not inherit tp_itemsize as they don't use variable-size items
if (et->ht_slots != NULL && PyTuple_GET_SIZE(et->ht_slots) > 0) {
// This type defines its own __slots__, inherit tp_itemsize
type->tp_itemsize = ctx->base->tp_itemsize;
}
else {
// This type doesn't define __slots__, don't inherit tp_itemsize
type->tp_itemsize = 0;
}

type->tp_members = _PyHeapType_GET_MEMBERS(et);
return 0;
}
Expand Down
Loading