]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-101758: Add _PyState_AddModule() Back for the Stable ABI (gh-101956)
authorEric Snow <ericsnowcurrently@gmail.com>
Thu, 16 Feb 2023 21:05:31 +0000 (14:05 -0700)
committerGitHub <noreply@github.com>
Thu, 16 Feb 2023 21:05:31 +0000 (14:05 -0700)
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

Include/internal/pycore_pystate.h
Lib/test/test_stable_abi_ctypes.py
Misc/stable_abi.toml
PC/python3dll.c
Python/import.c

index 638b86253879ea01dfa44cfb92c99238f433f073..7046ec8d9adaaf3453089aa7cd90ec53101ab965 100644 (file)
@@ -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) \
index 7e50fbda2c07cbc5d3b43a18058fa9a48d175d68..e77c1c8409880d008ae7a2a4c00205569f3db46d 100644 (file)
@@ -864,6 +864,7 @@ SYMBOL_NAMES = (
     "_PyObject_GC_Resize",
     "_PyObject_New",
     "_PyObject_NewVar",
+    "_PyState_AddModule",
     "_PyThreadState_Init",
     "_PyThreadState_Prealloc",
     "_PyWeakref_CallableProxyType",
index c04a3a228caf567c55f88d29a7aa1d93f42e0973..21ff9616133445c46771a68dab641194d1d1ba11 100644 (file)
 [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
index 79f09037282f54e28e476b6fc6c4a9e9ec9cb0cb..e300819365756ef4e1a9c92915cf4a2c83ef494a 100755 (executable)
@@ -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)
index ec126f28b858169adcf02828ece77d8de26206f1..fabf03b1c5d6982917ab4b6407b20f9a8a1ab4fd 100644 (file)
@@ -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)
 {