Skip to content

Commit 4f7bccb

Browse files
committed
test_cext: Define PyInit_* function which asserts that it wasn't called
1 parent dab2207 commit 4f7bccb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Lib/test/test_cext/extension.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,17 @@ FUNC_NAME(MODULE_NAME)(void)
111111
{
112112
return _testcext_slots;
113113
}
114+
115+
// Also define the soft-deprecated entrypoint to ensure it isn't called
116+
117+
#define _INITFUNC_NAME(NAME) PyInit_ ## NAME
118+
#define INITFUNC_NAME(NAME) _INITFUNC_NAME(NAME)
119+
120+
PyMODINIT_FUNC
121+
INITFUNC_NAME(MODULE_NAME)(void)
122+
{
123+
PyErr_SetString(
124+
PyExc_AssertionError,
125+
"PyInit_* function called while a PyModExport_* one is available");
126+
return NULL;
127+
}

0 commit comments

Comments
 (0)