]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] bpo-45307: Restore private C API function _PyImport_FindExtensionObject()...
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 28 Sep 2021 21:12:50 +0000 (00:12 +0300)
committerPablo Galindo <pablogsal@gmail.com>
Wed, 29 Sep 2021 11:27:08 +0000 (12:27 +0100)
py2exe and PyOxidizer rely on this API.
It will be removed in Python 3.11.

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Include/cpython/import.h
Misc/NEWS.d/next/C API/2021-09-28-12-00-55.bpo-45307.3ETFfX.rst [new file with mode: 0644]
Python/import.c

index bad68f0e0980d5fbea76710a216bd92fa537ea25..dd5bbdbad78cb75a703d95211fbafe1827d00c0b 100644 (file)
@@ -13,6 +13,9 @@ PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module);
 PyAPI_FUNC(void) _PyImport_AcquireLock(void);
 PyAPI_FUNC(int) _PyImport_ReleaseLock(void);
 
+/* Obsolete since 3.5, will be removed in 3.11. */
+Py_DEPRECATED(3.10) PyAPI_FUNC(PyObject *) _PyImport_FindExtensionObject(PyObject *, PyObject *);
+
 PyAPI_FUNC(int) _PyImport_FixupBuiltin(
     PyObject *mod,
     const char *name,            /* UTF-8 encoded string */
diff --git a/Misc/NEWS.d/next/C API/2021-09-28-12-00-55.bpo-45307.3ETFfX.rst b/Misc/NEWS.d/next/C API/2021-09-28-12-00-55.bpo-45307.3ETFfX.rst
new file mode 100644 (file)
index 0000000..aa2bd7a
--- /dev/null
@@ -0,0 +1,2 @@
+Restore the private C API function :func:`_PyImport_FindExtensionObject`. It
+will be removed in Python 3.11.
index 7301fccb9fac0ca6fcb45ee99b1b02b79fa0f94c..f2b30afe3f2284d55839e47d3f05b50a3d72a453 100644 (file)
@@ -556,6 +556,23 @@ import_find_extension(PyThreadState *tstate, PyObject *name,
     return mod;
 }
 
+PyObject *
+_PyImport_FindExtensionObject(PyObject *name, PyObject *filename)
+{
+    PyThreadState *tstate = _PyThreadState_GET();
+    PyObject *mod = import_find_extension(tstate, name, filename);
+    if (mod) {
+        PyObject *ref = PyWeakref_NewRef(mod, NULL);
+        Py_DECREF(mod);
+        if (ref == NULL) {
+            return NULL;
+        }
+        mod = PyWeakref_GetObject(ref);
+        Py_DECREF(ref);
+    }
+    return mod; /* borrowed reference */
+}
+
 
 /* Get the module object corresponding to a module name.
    First check the modules dictionary if there's one there,