https://github.com/python/cpython/commit/799326b0a93ae6375f153d5a6607e7dc5e0690b2
commit: 799326b0a93ae6375f153d5a6607e7dc5e0690b2
branch: main
author: Petr Viktorin <[email protected]>
committer: encukou <[email protected]>
date: 2025-11-11T13:52:13+01:00
summary:
gh-141169: Re-raise exception from findfuncptr (GH-141349)
files:
M Include/internal/pycore_importdl.h
M Python/importdl.c
diff --git a/Include/internal/pycore_importdl.h
b/Include/internal/pycore_importdl.h
index 12a32a5f70e51f..f60c5510d20075 100644
--- a/Include/internal/pycore_importdl.h
+++ b/Include/internal/pycore_importdl.h
@@ -14,6 +14,34 @@ extern "C" {
extern const char *_PyImport_DynLoadFiletab[];
+#ifdef HAVE_DYNAMIC_LOADING
+/* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is
+ supported on this platform. configure will then compile and link in one
+ of the dynload_*.c files, as appropriate. We will call a function in
+ those modules to get a function pointer to the module's init function.
+
+ The function should return:
+ - The function pointer on success
+ - NULL with exception set if the library cannot be loaded
+ - NULL *without* an extension set if the library could be loaded but the
+ function cannot be found in it.
+*/
+#ifdef MS_WINDOWS
+#include <windows.h>
+typedef FARPROC dl_funcptr;
+extern dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
+ const char *shortname,
+ PyObject *pathname,
+ FILE *fp);
+#else
+typedef void (*dl_funcptr)(void);
+extern dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix,
+ const char *shortname,
+ const char *pathname, FILE *fp);
+#endif
+
+#endif /* HAVE_DYNAMIC_LOADING */
+
typedef enum ext_module_kind {
_Py_ext_module_kind_UNKNOWN = 0,
@@ -112,8 +140,6 @@ extern int _PyImport_RunModInitFunc(
#define MAXSUFFIXSIZE 12
#ifdef MS_WINDOWS
-#include <windows.h>
-typedef FARPROC dl_funcptr;
#ifdef Py_DEBUG
# define PYD_DEBUG_SUFFIX "_d"
@@ -136,8 +162,6 @@ typedef FARPROC dl_funcptr;
#define PYD_TAGGED_SUFFIX PYD_DEBUG_SUFFIX "." PYD_SOABI ".pyd"
#define PYD_UNTAGGED_SUFFIX PYD_DEBUG_SUFFIX ".pyd"
-#else
-typedef void (*dl_funcptr)(void);
#endif
diff --git a/Python/importdl.c b/Python/importdl.c
index 23a55c39677100..61a9cdaf3754c9 100644
--- a/Python/importdl.c
+++ b/Python/importdl.c
@@ -10,27 +10,6 @@
#include "pycore_runtime.h" // _Py_ID()
-/* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is
- supported on this platform. configure will then compile and link in one
- of the dynload_*.c files, as appropriate. We will call a function in
- those modules to get a function pointer to the module's init function.
-*/
-#ifdef HAVE_DYNAMIC_LOADING
-
-#ifdef MS_WINDOWS
-extern dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
- const char *shortname,
- PyObject *pathname,
- FILE *fp);
-#else
-extern dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix,
- const char *shortname,
- const char *pathname, FILE *fp);
-#endif
-
-#endif /* HAVE_DYNAMIC_LOADING */
-
-
/***********************************/
/* module info to use when loading */
/***********************************/
@@ -414,6 +393,9 @@ _PyImport_GetModuleExportHooks(
*modexport = (PyModExportFunction)exportfunc;
return 2;
}
+ if (PyErr_Occurred()) {
+ return -1;
+ }
exportfunc = findfuncptr(
info->hook_prefixes->init_prefix,
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]