Skip to content

Commit d0b1d63

Browse files
committed
Fix test_gc() on limited C API 3.9 on Windows
PyObject_GC_IsTracked() and PyObject_GC_IsFinalized() are only added to limited C API 3.10 on Windows.
1 parent 7b008ef commit d0b1d63

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎docs/api.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,13 +809,13 @@ GC protocol
809809

810810
See `PyObject_GC_IsTracked() documentation <https://docs.python.org/dev/c-api/gcsupport.html#c.PyObject_GC_IsTracked>`__.
811811

812-
Not available on PyPy nor on limited C API 3.8 and older.
812+
Not available on PyPy nor on limited C API 3.9 and older.
813813

814814
.. c:function:: int PyObject_GC_IsFinalized(PyObject *obj)
815815

816816
See `PyObject_GC_IsFinalized() documentation <https://docs.python.org/dev/c-api/gcsupport.html#c.PyObject_GC_IsFinalized>`__.
817817

818-
Availability: Python 3.4. Not available on PyPy nor on limited C API 3.8 and
818+
Availability: Python 3.4. Not available on PyPy nor on limited C API 3.9 and
819819
older.
820820

821821
Module helper

‎pythoncapi_compat.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ static inline int PyModule_AddType(PyObject *module, PyTypeObject *type)
487487

488488
// bpo-40241 added PyObject_GC_IsTracked() to Python 3.9.0a6.
489489
// bpo-4688 added _PyObject_GC_IS_TRACKED() to Python 2.7.0a2.
490+
// On Windows, PyObject_GC_IsTracked() was only added to limited C API 3.10.
490491
#if PY_VERSION_HEX < 0x030900A6 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)
491492
static inline int PyObject_GC_IsTracked(PyObject* obj)
492493
{
@@ -496,6 +497,7 @@ static inline int PyObject_GC_IsTracked(PyObject* obj)
496497

497498
// bpo-40241 added PyObject_GC_IsFinalized() to Python 3.9.0a6.
498499
// bpo-18112 added _PyGCHead_FINALIZED() to Python 3.4.0 final.
500+
// On Windows, PyObject_GC_IsFinalized() was only added to limited C API 3.10.
499501
#if PY_VERSION_HEX < 0x030900A6 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)
500502
static inline int PyObject_GC_IsFinalized(PyObject *obj)
501503
{

‎tests/test_pythoncapi_compat_cext.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ test_calls(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
386386
}
387387

388388

389+
#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000) && !defined(PYPY_VERSION)
389390
static PyObject *
390391
test_gc(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
391392
{
@@ -394,21 +395,18 @@ test_gc(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
394395
return NULL;
395396
}
396397

397-
#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030900A6) && !defined(PYPY_VERSION)
398398
// test PyObject_GC_IsTracked()
399399
int tracked = PyObject_GC_IsTracked(tuple);
400400
assert(tracked);
401-
#endif
402401

403-
#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030900A6) && !defined(PYPY_VERSION)
404402
// test PyObject_GC_IsFinalized()
405403
int finalized = PyObject_GC_IsFinalized(tuple);
406404
assert(!finalized);
407-
#endif
408405

409406
Py_DECREF(tuple);
410407
Py_RETURN_NONE;
411408
}
409+
#endif
412410

413411

414412
static int
@@ -2547,7 +2545,9 @@ static struct PyMethodDef methods[] = {
25472545
#endif
25482546
{"test_interpreter", test_interpreter, METH_NOARGS, _Py_NULL},
25492547
{"test_calls", test_calls, METH_NOARGS, _Py_NULL},
2548+
#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000) && !defined(PYPY_VERSION)
25502549
{"test_gc", test_gc, METH_NOARGS, _Py_NULL},
2550+
#endif
25512551
{"test_module", test_module, METH_NOARGS, _Py_NULL},
25522552
#if ((PY_VERSION_HEX <= 0x030B00A1 || 0x030B00A7 <= PY_VERSION_HEX) \
25532553
&& !defined(PYPY_VERSION) && !defined(Py_LIMITED_API))

0 commit comments

Comments
 (0)