Skip to content

Commit 1f5eec3

Browse files
committed
apply victor's comment
1 parent dabfb67 commit 1f5eec3

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

Lib/test/test_capi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,9 @@ def test_heap_ctype_doc_and_text_signature(self):
405405
self.assertEqual(_testcapi.HeapDocCType.__doc__, "somedoc")
406406
self.assertEqual(_testcapi.HeapDocCType.__text_signature__, "(arg1, arg2)")
407407

408+
def test_null_type_doc(self):
409+
self.assertEqual(_testcapi.NullTpDocType.__doc__, None)
410+
408411
def test_subclass_of_heap_gc_ctype_with_tpdealloc_decrefs_once(self):
409412
class HeapGcCTypeSubclass(_testcapi.HeapGcCType):
410413
def __init__(self):
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
:c:func:`PyType_FromModuleAndSpec` can accept tp_doc=NULL.
1+
The :c:func:`PyType_FromModuleAndSpec` function now accepts NULL ``tp_doc``
2+
slot.

Modules/_lsprof.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,12 +490,14 @@ static PyStructSequence_Field profiler_subentry_fields[] = {
490490
static PyStructSequence_Desc profiler_entry_desc = {
491491
.name = "_lsprof.profiler_entry",
492492
.fields = profiler_entry_fields,
493+
.doc = NULL,
493494
.n_in_sequence = 6
494495
};
495496

496497
static PyStructSequence_Desc profiler_subentry_desc = {
497498
.name = "_lsprof.profiler_subentry",
498499
.fields = profiler_subentry_fields,
500+
.doc = NULL,
499501
.n_in_sequence = 5
500502
};
501503

Modules/_testcapimodule.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3990,21 +3990,6 @@ test_structseq_newtype_doesnt_leak(PyObject *Py_UNUSED(self),
39903990
Py_RETURN_NONE;
39913991
}
39923992

3993-
static PyType_Spec HeapDocCType_spec;
3994-
3995-
static PyObject *
3996-
test_PyType_FromSpec(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args))
3997-
{
3998-
void *tp_doc = HeapDocCType_spec.slots[0].pfunc;
3999-
HeapDocCType_spec.slots[0].pfunc = NULL;
4000-
PyObject *HeapDocCType = PyType_FromSpec(&HeapDocCType_spec);
4001-
assert(HeapDocCType != NULL);
4002-
HeapDocCType_spec.slots[0].pfunc = tp_doc;
4003-
Py_DECREF(HeapDocCType);
4004-
4005-
Py_RETURN_NONE;
4006-
}
4007-
40083993
static PyObject *
40093994
test_incref_decref_API(PyObject *ob, PyObject *Py_UNUSED(ignored))
40103995
{
@@ -5616,7 +5601,6 @@ static PyMethodDef TestMethods[] = {
56165601
{"test_decref_doesnt_leak", test_decref_doesnt_leak, METH_NOARGS},
56175602
{"test_structseq_newtype_doesnt_leak",
56185603
test_structseq_newtype_doesnt_leak, METH_NOARGS},
5619-
{"test_PyType_FromSpec", test_PyType_FromSpec, METH_NOARGS},
56205604
{"test_incref_decref_API", test_incref_decref_API, METH_NOARGS},
56215605
{"test_long_and_overflow", test_long_and_overflow, METH_NOARGS},
56225606
{"test_long_as_double", test_long_as_double, METH_NOARGS},
@@ -6524,6 +6508,23 @@ static PyType_Spec HeapDocCType_spec = {
65246508
HeapDocCType_slots
65256509
};
65266510

6511+
typedef struct {
6512+
PyObject_HEAD
6513+
} NullTpDocTypeObject;
6514+
6515+
static PyType_Slot NullTpDocType_slots[] = {
6516+
{Py_tp_doc, NULL},
6517+
{0, 0},
6518+
};
6519+
6520+
static PyType_Spec NullTpDocType_spec = {
6521+
"_testcapi.NullTpDocType",
6522+
sizeof(NullTpDocTypeObject),
6523+
0,
6524+
Py_TPFLAGS_DEFAULT,
6525+
NullTpDocType_slots
6526+
};
6527+
65276528

65286529
PyDoc_STRVAR(heapgctype__doc__,
65296530
"A heap type with GC, and with overridden dealloc.\n\n"
@@ -7199,6 +7200,12 @@ PyInit__testcapi(void)
71997200
}
72007201
PyModule_AddObject(m, "HeapDocCType", HeapDocCType);
72017202

7203+
PyObject *NullTpDocType = PyType_FromSpec(&NullTpDocType_spec);
7204+
if (NullTpDocType == NULL) {
7205+
return NULL;
7206+
}
7207+
PyModule_AddObject(m, "NullTpDocType", NullTpDocType);
7208+
72027209
PyObject *HeapGcCType = PyType_FromSpec(&HeapGcCType_spec);
72037210
if (HeapGcCType == NULL) {
72047211
return NULL;

0 commit comments

Comments
 (0)