diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2021-09-28 21:12:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-28 21:12:50 (GMT) |
commit | ec4e2ec241acb3bf4e04a351c06c0b05a1e4b7d2 (patch) | |
tree | 6f5915e6de6bf4614397386dc36268dec97395f5 | |
parent | 8f9d398b46e5e932118094854110584f465a8179 (diff) | |
download | cpython-ec4e2ec241acb3bf4e04a351c06c0b05a1e4b7d2.zip cpython-ec4e2ec241acb3bf4e04a351c06c0b05a1e4b7d2.tar.gz cpython-ec4e2ec241acb3bf4e04a351c06c0b05a1e4b7d2.tar.bz2 |
[3.10] bpo-45307: Restore private C API function _PyImport_FindExtensionObject() (GH-28594)
py2exe and PyOxidizer rely on this API.
It will be removed in Python 3.11.
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
-rw-r--r-- | Include/cpython/import.h | 3 | ||||
-rw-r--r-- | Misc/NEWS.d/next/C API/2021-09-28-12-00-55.bpo-45307.3ETFfX.rst | 2 | ||||
-rw-r--r-- | Python/import.c | 17 |
3 files changed, 22 insertions, 0 deletions
diff --git a/Include/cpython/import.h b/Include/cpython/import.h index bad68f0..dd5bbdb 100644 --- a/Include/cpython/import.h +++ b/Include/cpython/import.h @@ -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 index 0000000..aa2bd7a --- /dev/null +++ b/Misc/NEWS.d/next/C API/2021-09-28-12-00-55.bpo-45307.3ETFfX.rst @@ -0,0 +1,2 @@ +Restore the private C API function :func:`_PyImport_FindExtensionObject`. It +will be removed in Python 3.11. diff --git a/Python/import.c b/Python/import.c index 7301fcc..f2b30af 100644 --- a/Python/import.c +++ b/Python/import.c @@ -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, |