Skip to content

Commit 8cb34fa

Browse files
authored
[3.14] gh-161185: Fix test_cext: replace PyType_FromSlots() with PyType_FromSpec() (#161373)
gh-161185: Fix test_cext: replace PyType_FromSlots() with PyType_FromSpec() Replace PyType_FromSlots() with PyType_FromSpec(), and replace PySlot with PyType_Spec. Python 3.14 doesn't support PyType_FromSlots(), it has been added to Python 3.15.
1 parent d0eff57 commit 8cb34fa

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

‎Lib/test/test_cext/extension.c‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,26 +172,32 @@ xsetref_strict_aliasing(PyTypeObject **a, PyTypeObject **b,
172172
Py_XSETREF(*b, second);
173173
}
174174

175+
static PyType_Slot empty_type_slots[] = {
176+
{0, 0},
177+
};
178+
179+
static PyType_Spec setref_type_spec = {
180+
STR(MODULE_NAME) ".setref_type", // .name
181+
0, // .basicsize
182+
0, // .itemsize
183+
Py_TPFLAGS_DEFAULT, // .flags
184+
empty_type_slots, // .slots
185+
};
175186

176187
// gh-161185: Test that Py_SETREF(), Py_XSETREF() and Py_CLEAR() macros
177188
// have no strict aliasing issue
178189
static PyObject *
179190
test_setref_strict_aliasing(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
180191
{
181-
PySlot slots[] = {
182-
PySlot_PTR_STATIC(Py_tp_name, STR(MODULE_NAME) ".setref_type"),
183-
PySlot_PTR_STATIC(Py_tp_flags, Py_TPFLAGS_DEFAULT),
184-
PySlot_END
185-
};
186192
PyObject *first, *second;
187193
Py_ssize_t first_refcnt, second_refcnt;
188194
PyTypeObject *slot = NULL;
189195

190-
first = PyType_FromSlots(slots);
196+
first = PyType_FromSpec(&setref_type_spec);
191197
if (first == NULL) {
192198
return NULL;
193199
}
194-
second = PyType_FromSlots(slots);
200+
second = PyType_FromSpec(&setref_type_spec);
195201
if (second == NULL) {
196202
Py_DECREF(first);
197203
return NULL;

0 commit comments

Comments
 (0)