Skip to content

Commit

Permalink
gh-101758: Add _PyState_AddModule() Back for the Stable ABI (gh-101956)
Browse files Browse the repository at this point in the history
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.

#101758
  • Loading branch information
ericsnowcurrently authored Feb 16, 2023
1 parent a5024a2 commit 4d8959b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ extern void _PySignal_AfterFork(void);
#endif


PyAPI_FUNC(int) _PyState_AddModule(
PyThreadState *tstate,
PyObject* module,
PyModuleDef* def);


PyAPI_FUNC(int) _PyOS_InterruptOccurred(PyThreadState *tstate);

#define HEAD_LOCK(runtime) \
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_stable_abi_ctypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Misc/stable_abi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,9 @@
[function._PyObject_NewVar]
added = '3.2'
abi_only = true
[function._PyState_AddModule]
added = '3.2'
abi_only = true
[function._PyThreadState_Init]
added = '3.2'
abi_only = true
Expand Down
1 change: 1 addition & 0 deletions PC/python3dll.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,26 @@ PyState_FindModule(PyModuleDef* module)
return _modules_by_index_get(interp, module);
}

/* _PyState_AddModule() has been completely removed from the C-API
(and was removed from the limited API in 3.6). However, we're
playing it safe and keeping it around for any stable ABI extensions
built against 3.2-3.5. */
int
_PyState_AddModule(PyThreadState *tstate, PyObject* module, PyModuleDef* def)
{
if (!def) {
assert(_PyErr_Occurred(tstate));
return -1;
}
if (def->m_slots) {
_PyErr_SetString(tstate,
PyExc_SystemError,
"PyState_AddModule called on module with slots");
return -1;
}
return _modules_by_index_set(tstate->interp, def, module);
}

int
PyState_AddModule(PyObject* module, PyModuleDef* def)
{
Expand Down

0 comments on commit 4d8959b

Please sign in to comment.