|
37 | 37 | #endif |
38 | 38 |
|
39 | 39 | static struct PyModuleDef _testcapimodule; |
| 40 | +static PyType_Spec HeapTypeNameType_Spec; |
40 | 41 |
|
41 | 42 | static PyObject *TestError; /* set to exception object in init */ |
42 | 43 |
|
@@ -1134,6 +1135,30 @@ test_get_statictype_slots(PyObject *self, PyObject *Py_UNUSED(ignored)) |
1134 | 1135 | } |
1135 | 1136 |
|
1136 | 1137 |
|
| 1138 | +static PyObject * |
| 1139 | +test_get_type_name(PyObject *self, PyObject *Py_UNUSED(ignored)) |
| 1140 | +{ |
| 1141 | + PyObject *tp_name = PyType_GetName(&PyLong_Type); |
| 1142 | + assert(strcmp(PyUnicode_AsUTF8(tp_name), "int") == 0); |
| 1143 | + Py_DECREF(tp_name); |
| 1144 | + |
| 1145 | + tp_name = PyType_GetName(&PyModule_Type); |
| 1146 | + assert(strcmp(PyUnicode_AsUTF8(tp_name), "module") == 0); |
| 1147 | + Py_DECREF(tp_name); |
| 1148 | + |
| 1149 | + PyObject *HeapTypeNameType = PyType_FromSpec(&HeapTypeNameType_Spec); |
| 1150 | + if (HeapTypeNameType == NULL) { |
| 1151 | + Py_RETURN_NONE; |
| 1152 | + } |
| 1153 | + tp_name = PyType_GetName((PyTypeObject *)HeapTypeNameType); |
| 1154 | + assert(strcmp(PyUnicode_AsUTF8(tp_name), "HeapTypeNameType") == 0); |
| 1155 | + Py_DECREF(tp_name); |
| 1156 | + |
| 1157 | + Py_DECREF(HeapTypeNameType); |
| 1158 | + Py_RETURN_NONE; |
| 1159 | +} |
| 1160 | + |
| 1161 | + |
1137 | 1162 | static PyObject * |
1138 | 1163 | get_args(PyObject *self, PyObject *args) |
1139 | 1164 | { |
@@ -5624,6 +5649,7 @@ static PyMethodDef TestMethods[] = { |
5624 | 5649 | {"test_buildvalue_issue38913", test_buildvalue_issue38913, METH_NOARGS}, |
5625 | 5650 | {"get_args", get_args, METH_VARARGS}, |
5626 | 5651 | {"test_get_statictype_slots", test_get_statictype_slots, METH_NOARGS}, |
| 5652 | + {"test_get_type_name", test_get_type_name, METH_NOARGS}, |
5627 | 5653 | {"get_kwargs", (PyCFunction)(void(*)(void))get_kwargs, |
5628 | 5654 | METH_VARARGS|METH_KEYWORDS}, |
5629 | 5655 | {"getargs_tuple", getargs_tuple, METH_VARARGS}, |
@@ -6512,6 +6538,21 @@ static PyType_Spec HeapDocCType_spec = { |
6512 | 6538 | HeapDocCType_slots |
6513 | 6539 | }; |
6514 | 6540 |
|
| 6541 | +typedef struct { |
| 6542 | + PyObject_HEAD |
| 6543 | +} HeapTypeNameObject; |
| 6544 | + |
| 6545 | +static PyType_Slot HeapTypeNameType_slots[] = { |
| 6546 | + {0}, |
| 6547 | +}; |
| 6548 | + |
| 6549 | +static PyType_Spec HeapTypeNameType_Spec = { |
| 6550 | + .name = "_testcapi.HeapTypeNameType", |
| 6551 | + .basicsize = sizeof(HeapTypeNameObject), |
| 6552 | + .flags = Py_TPFLAGS_DEFAULT, |
| 6553 | + .slots = HeapTypeNameType_slots, |
| 6554 | +}; |
| 6555 | + |
6515 | 6556 | typedef struct { |
6516 | 6557 | PyObject_HEAD |
6517 | 6558 | } NullTpDocTypeObject; |
|
0 commit comments