Skip to content

Commit 856dac3

Browse files
committed
Fix PyModule_AddType()
1 parent d0b1d63 commit 856dac3

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

‎pythoncapi_compat.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ PyModule_AddObjectRef(PyObject *module, const char *name, PyObject *value)
439439

440440

441441
// bpo-40024 added PyModule_AddType() to Python 3.9.0a5
442-
#if PY_VERSION_HEX < 0x030900A5
442+
// On Windows, PyModule_AddType() was added to limited C API 3.10.
443+
#if PY_VERSION_HEX < 0x030900A5 && !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000)
443444
static inline int PyModule_AddType(PyObject *module, PyTypeObject *type)
444445
{
445446
#ifndef Py_LIMITED_API

‎tests/test_pythoncapi_compat_cext.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ check_module_attr(PyObject *module, const char *name, PyObject *expected)
430430
static int
431431
test_module_add_type(PyObject *module)
432432
{
433+
#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000)
433434
PyTypeObject *type = &PyUnicode_Type;
434435
const char *type_name = "str";
435436
#ifdef CHECK_REFCNT
@@ -447,6 +448,7 @@ test_module_add_type(PyObject *module)
447448
return -1;
448449
}
449450
ASSERT_REFCNT(Py_REFCNT(_PyObject_CAST(type)) == refcnt);
451+
#endif // !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000)
450452
return 0;
451453
}
452454

0 commit comments

Comments
 (0)