Skip to content

Commit f07f6ed

Browse files
authored
Test Py_SET_TYPE() on limited C API (#210)
1 parent 1b6566a commit f07f6ed

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎docs/api.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,8 @@ PyObject
870870

871871
See `Py_SET_TYPE() documentation <https://docs.python.org/dev/c-api/structures.html#c.Py_SET_TYPE>`__.
872872

873+
Not available on Free Threading with limited C API 3.15 or newer (abi3t).
874+
873875
.. c:function:: void Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size)
874876

875877
See `Py_SET_SIZE() documentation <https://docs.python.org/dev/c-api/structures.html#c.Py_SET_SIZE>`__.

‎tests/test_pythoncapi_compat.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,15 @@ def run_tests(build_dir, module_name, std):
166166
if VERBOSE:
167167
empty_line = False
168168
for attr in ('__cplusplus', 'PY_VERSION', 'PY_VERSION_HEX',
169-
'PYPY_VERSION', 'PYPY_VERSION_NUM', 'Py_LIMITED_API'):
169+
'PYPY_VERSION', 'PYPY_VERSION_NUM', 'Py_LIMITED_API',
170+
'Py_TARGET_ABI3T'):
170171
try:
171172
value = getattr(testmod, attr)
172173
except AttributeError:
173174
pass
174175
else:
175-
if attr in ('PY_VERSION_HEX', 'Py_LIMITED_API', 'PYPY_VERSION_NUM'):
176+
if attr in ('PY_VERSION_HEX', 'Py_LIMITED_API',
177+
'PYPY_VERSION_NUM', 'Py_TARGET_ABI3T'):
176178
value = "0x%x" % value
177179
print("%s: %s" % (attr, value))
178180
empty_line = True

‎tests/test_pythoncapi_compat_cext.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ test_object(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
102102

103103
// Py_SET_REFCNT
104104
Py_SET_REFCNT(obj, Py_REFCNT(obj));
105-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 10)
106-
// Py_SET_TYPE
105+
// Py_SET_TYPE. Not implemented in the abi3t.
106+
#ifndef Py_TARGET_ABI3T
107107
Py_SET_TYPE(obj, Py_TYPE(obj));
108108
#endif
109109
// Py_SET_SIZE
@@ -315,7 +315,7 @@ test_thread_state(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
315315
static PyObject *
316316
test_interpreter(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
317317
{
318-
// On Windows,PyInterpreterState_Get() is not available in stable ABI 3.9,
318+
// On Windows, PyInterpreterState_Get() is not available in stable ABI 3.9,
319319
// only in stable ABI 3.10. Don't test it on limited C API 3.9 on Unix to
320320
// make the test simpler.
321321
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 10)
@@ -2802,6 +2802,11 @@ module_exec(PyObject *module)
28022802
return -1;
28032803
}
28042804
#endif
2805+
#ifdef Py_TARGET_ABI3T
2806+
if (PyModule_AddIntMacro(module, Py_TARGET_ABI3T)) {
2807+
return -1;
2808+
}
2809+
#endif
28052810
#if !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)
28062811
TryIncrefType.tp_name = "TryIncrefType";
28072812
TryIncrefType.tp_basicsize = sizeof(PyObject);

0 commit comments

Comments
 (0)