Skip to content

Commit 4d8959b

Browse files
pythongh-101758: Add _PyState_AddModule() Back for the Stable ABI (pythongh-101956)
We're adding the function back, only for the stable ABI symbol and not as any form of API. I had removed it yesterday. This undocumented "private" function was added with the implementation for PEP 3121 (3.0, 2007) for internal use and later moved out of the limited API (3.6, 2016) and then into the internal API (3.9, 2019). I removed it completely yesterday, including from the stable ABI manifest (where it was added because the symbol happened to be exported). It's unlikely that anyone is using _PyState_AddModule(), especially any stable ABI extensions built against 3.2-3.5, but we're playing it safe. python#101758
1 parent a5024a2 commit 4d8959b

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

Include/internal/pycore_pystate.h

+6
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ extern void _PySignal_AfterFork(void);
152152
#endif
153153

154154

155+
PyAPI_FUNC(int) _PyState_AddModule(
156+
PyThreadState *tstate,
157+
PyObject* module,
158+
PyModuleDef* def);
159+
160+
155161
PyAPI_FUNC(int) _PyOS_InterruptOccurred(PyThreadState *tstate);
156162

157163
#define HEAD_LOCK(runtime) \

Lib/test/test_stable_abi_ctypes.py

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Misc/stable_abi.toml

+3
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,9 @@
16841684
[function._PyObject_NewVar]
16851685
added = '3.2'
16861686
abi_only = true
1687+
[function._PyState_AddModule]
1688+
added = '3.2'
1689+
abi_only = true
16871690
[function._PyThreadState_Init]
16881691
added = '3.2'
16891692
abi_only = true

PC/python3dll.c

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/import.c

+20
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,26 @@ PyState_FindModule(PyModuleDef* module)
487487
return _modules_by_index_get(interp, module);
488488
}
489489

490+
/* _PyState_AddModule() has been completely removed from the C-API
491+
(and was removed from the limited API in 3.6). However, we're
492+
playing it safe and keeping it around for any stable ABI extensions
493+
built against 3.2-3.5. */
494+
int
495+
_PyState_AddModule(PyThreadState *tstate, PyObject* module, PyModuleDef* def)
496+
{
497+
if (!def) {
498+
assert(_PyErr_Occurred(tstate));
499+
return -1;
500+
}
501+
if (def->m_slots) {
502+
_PyErr_SetString(tstate,
503+
PyExc_SystemError,
504+
"PyState_AddModule called on module with slots");
505+
return -1;
506+
}
507+
return _modules_by_index_set(tstate->interp, def, module);
508+
}
509+
490510
int
491511
PyState_AddModule(PyObject* module, PyModuleDef* def)
492512
{

0 commit comments

Comments
 (0)