8000 gh-89546: Clean up PyType_FromMetaclass by encukou · Pull Request #93686 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-89546: Clean up PyType_FromMetaclass #93686

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Jun 14, 2022
Merged
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
Move variable declarations out of switch cases
  • Loading branch information
encukou committed Jun 10, 2022
commit 763ea2dfa843dec2e0af779e6c797ac791955a3c
8 changes: 5 additions & 3 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3450,6 +3450,7 @@ PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module,
char *_ht_tpname = NULL;

int r;
size_t len;

/* Prepare slots that need special handling.
* Keep in mind that a slot can be given multiple times:
Expand Down Expand Up @@ -3513,7 +3514,7 @@ PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module,
tp_doc = NULL;
}
else {
size_t len = strlen(slot->pfunc)+1;
len = strlen(slot->pfunc)+1;
tp_doc = PyObject_Malloc(len);
if (tp_doc == NULL) {
PyErr_NoMemory();
Expand Down Expand Up @@ -3653,6 +3654,7 @@ PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module,
/* Copy all the ordinary slots */

for (slot = spec->slots; slot->slot; slot++) {
PySlot_Offset slotoffsets;
switch (slot->slot) {
case Py_tp_base:
case Py_tp_bases:
Expand All @@ -3661,13 +3663,13 @@ PyType_FromMetaclass(PyTypeObject *metaclass, PyObject *module,
break;
case Py_tp_members:
/* Move the slots to the heap type itself */
size_t len = Py_TYPE(type)->tp_itemsize * nmembers;
len = Py_TYPE(type)->tp_itemsize * nmembers;
memcpy(_PyHeapType_GET_MEMBERS(res), slot->pfunc, len);
type->tp_members = _PyHeapType_GET_MEMBERS(res);
break;
default:
/* Copy other slots directly */
PySlot_Offset slotoffsets = pyslot_offsets[slot->slot];
slotoffsets = pyslot_offsets[slot->slot];
slot_offset = slotoffsets.slot_offset;
if (slotoffsets.subslot_offset == -1) {
*(void**)((char*)res_start + slot_offset) = slot->pfunc;
Expand Down
0