Skip to content

Commit 7d1f016

Browse files
committed
Update by review comments
1 parent 233303b commit 7d1f016

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

Lib/test/test_capi/test_misc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,11 +921,11 @@ def test_tp_bases_slot(self):
921921
self.assertEqual(cls.__bases__, (int,))
922922
self.assertEqual(cls.__base__, int)
923923

924-
def test_tp_bases_slot_invalid(self):
924+
def test_tp_bases_slot_none(self):
925925
self.assertRaisesRegex(
926926
SystemError,
927927
"Py_tp_bases is not a tuple",
928-
_testcapi.create_heapctype_with_invalid_bases_slot
928+
_testcapi.create_heapctype_with_none_bases_slot
929929
)
930930

931931

Modules/_testcapi/heaptype.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -543,23 +543,23 @@ pytype_getmodulebytoken(PyObject *self, PyObject *args)
543543
return PyType_GetModuleByToken((PyTypeObject *)type, token);
544544
}
545545

546-
static PyType_Slot HeapCTypeWithBasesSlotInvalid_slots[] = {
546+
static PyType_Slot HeapCTypeWithBasesSlotNone_slots[] = {
547547
{Py_tp_bases, NULL}, /* filled out with Py_None in runtime */
548548
{0, 0},
549549
};
550550

551-
static PyType_Spec HeapCTypeWithBasesSlotInvalid_spec = {
552-
.name = "_testcapi.HeapCTypeWithBasesSlotInvalid",
551+
static PyType_Spec HeapCTypeWithBasesSlotNone_spec = {
552+
.name = "_testcapi.HeapCTypeWithBasesSlotNone",
553553
.basicsize = sizeof(PyObject),
554554
.flags = Py_TPFLAGS_DEFAULT,
555-
.slots = HeapCTypeWithBasesSlotInvalid_slots
555+
.slots = HeapCTypeWithBasesSlotNone_slots
556556
};
557557

558558
static PyObject *
559-
create_heapctype_with_invalid_bases_slot(PyObject *self, PyObject *Py_UNUSED(ignored))
559+
create_heapctype_with_none_bases_slot(PyObject *self, PyObject *Py_UNUSED(ignored))
560560
{
561-
HeapCTypeWithBasesSlotInvalid_slots[0].pfunc = Py_None;
562-
return PyType_FromSpec(&HeapCTypeWithBasesSlotInvalid_spec);
561+
HeapCTypeWithBasesSlotNone_slots[0].pfunc = Py_None;
562+
return PyType_FromSpec(&HeapCTypeWithBasesSlotNone_spec);
563563
}
564564

565565

@@ -581,8 +581,8 @@ static PyMethodDef TestMethods[] = {
581581
{"pytype_getbasebytoken", pytype_getbasebytoken, METH_VARARGS},
582582
{"pytype_getmodulebydef", pytype_getmodulebydef, METH_O},
583583
{"pytype_getmodulebytoken", pytype_getmodulebytoken, METH_VARARGS},
584-
{"create_heapctype_with_invalid_bases_slot",
585-
create_heapctype_with_invalid_bases_slot, METH_NOARGS},
584+
{"create_heapctype_with_none_bases_slot",
585+
create_heapctype_with_none_bases_slot, METH_NOARGS},
586586
{NULL},
587587
};
588588

@@ -1472,6 +1472,9 @@ _PyTestCapi_Init_Heaptype(PyObject *m) {
14721472
HeapCTypeWithBasesSlot_slots[0].pfunc = bases;
14731473
PyObject *HeapCTypeWithBasesSlot = PyType_FromSpec(&HeapCTypeWithBasesSlot_spec);
14741474
Py_DECREF(bases);
1475+
if (HeapCTypeWithBasesSlot == NULL) {
1476+
return -1;
1477+
}
14751478
ADD("HeapCTypeWithBasesSlot", HeapCTypeWithBasesSlot);
14761479

14771480
ADD("Py_TP_USE_SPEC", PyLong_FromVoidPtr(Py_TP_USE_SPEC));

0 commit comments

Comments
 (0)