summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-02-16 21:05:31 (GMT)
committerGitHub <noreply@github.com>2023-02-16 21:05:31 (GMT)
commit4d8959b73ac194ca9a2f623dcb5c23680f7d8536 (patch)
tree6856f3c336d38f4531f3e926d121bf1613ce3bd2
parenta5024a261a75dafa4fb6613298dcb64a9603d9c7 (diff)
downloadcpython-4d8959b73ac194ca9a2f623dcb5c23680f7d8536.zip
cpython-4d8959b73ac194ca9a2f623dcb5c23680f7d8536.tar.gz
cpython-4d8959b73ac194ca9a2f623dcb5c23680f7d8536.tar.bz2
gh-101758: Add _PyState_AddModule() Back for the Stable ABI (gh-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. https://github.com/python/cpython/issues/101758
-rw-r--r--Include/internal/pycore_pystate.h6
-rw-r--r--Lib/test/test_stable_abi_ctypes.py1
-rw-r--r--Misc/stable_abi.toml3
-rwxr-xr-xPC/python3dll.c1
-rw-r--r--Python/import.c20
5 files changed, 31 insertions, 0 deletions
diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h
index 638b862..7046ec8 100644
--- a/Include/internal/pycore_pystate.h
+++ b/Include/internal/pycore_pystate.h
@@ -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) \
diff --git a/Lib/test/test_stable_abi_ctypes.py b/Lib/test/test_stable_abi_ctypes.py
index 7e50fbd..e77c1c8 100644
--- a/Lib/test/test_stable_abi_ctypes.py
+++ b/Lib/test/test_stable_abi_ctypes.py
@@ -864,6 +864,7 @@ SYMBOL_NAMES = (
"_PyObject_GC_Resize",
"_PyObject_New",
"_PyObject_NewVar",
+ "_PyState_AddModule",
"_PyThreadState_Init",
"_PyThreadState_Prealloc",
"_PyWeakref_CallableProxyType",
diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml
index c04a3a2..21ff961 100644
--- a/Misc/stable_abi.toml
+++ b/Misc/stable_abi.toml
@@ -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
diff --git a/PC/python3dll.c b/PC/python3dll.c
index 79f0903..e300819 100755
--- a/PC/python3dll.c
+++ b/PC/python3dll.c
@@ -34,6 +34,7 @@ EXPORT_FUNC(_PyObject_GC_NewVar)
EXPORT_FUNC(_PyObject_GC_Resize)
EXPORT_FUNC(_PyObject_New)
EXPORT_FUNC(_PyObject_NewVar)
+EXPORT_FUNC(_PyState_AddModule)
EXPORT_FUNC(_PyThreadState_Init)
EXPORT_FUNC(_PyThreadState_Prealloc)
EXPORT_FUNC(Py_AddPendingCall)
diff --git a/Python/import.c b/Python/import.c
index ec126f2..fabf03b 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -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)
{