Skip to content

Commit 799326b

Browse files
authored
gh-141169: Re-raise exception from findfuncptr (GH-141349)
1 parent d694474 commit 799326b

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

Include/internal/pycore_importdl.h

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,34 @@ extern "C" {
1414

1515
extern const char *_PyImport_DynLoadFiletab[];
1616

17+
#ifdef HAVE_DYNAMIC_LOADING
18+
/* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is
19+
supported on this platform. configure will then compile and link in one
20+
of the dynload_*.c files, as appropriate. We will call a function in
21+
those modules to get a function pointer to the module's init function.
22+
23+
The function should return:
24+
- The function pointer on success
25+
- NULL with exception set if the library cannot be loaded
26+
- NULL *without* an extension set if the library could be loaded but the
27+
function cannot be found in it.
28+
*/
29+
#ifdef MS_WINDOWS
30+
#include <windows.h>
31+
typedef FARPROC dl_funcptr;
32+
extern dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
33+
const char *shortname,
34+
PyObject *pathname,
35+
FILE *fp);
36+
#else
37+
typedef void (*dl_funcptr)(void);
38+
extern dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix,
39+
const char *shortname,
40+
const char *pathname, FILE *fp);
41+
#endif
42+
43+
#endif /* HAVE_DYNAMIC_LOADING */
44+
1745

1846
typedef enum ext_module_kind {
1947
_Py_ext_module_kind_UNKNOWN = 0,
@@ -112,8 +140,6 @@ extern int _PyImport_RunModInitFunc(
112140
#define MAXSUFFIXSIZE 12
113141

114142
#ifdef MS_WINDOWS
115-
#include <windows.h>
116-
typedef FARPROC dl_funcptr;
117143

118144
#ifdef Py_DEBUG
119145
# define PYD_DEBUG_SUFFIX "_d"
@@ -136,8 +162,6 @@ typedef FARPROC dl_funcptr;
136162
#define PYD_TAGGED_SUFFIX PYD_DEBUG_SUFFIX "." PYD_SOABI ".pyd"
137163
#define PYD_UNTAGGED_SUFFIX PYD_DEBUG_SUFFIX ".pyd"
138164

139-
#else
140-
typedef void (*dl_funcptr)(void);
141165
#endif
142166

143167

Python/importdl.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,6 @@
1010
#include "pycore_runtime.h" // _Py_ID()
1111

1212

13-
/* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is
14-
supported on this platform. configure will then compile and link in one
15-
of the dynload_*.c files, as appropriate. We will call a function in
16-
those modules to get a function pointer to the module's init function.
17-
*/
18-
#ifdef HAVE_DYNAMIC_LOADING
19-
20-
#ifdef MS_WINDOWS
21-
extern dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
22-
const char *shortname,
23-
PyObject *pathname,
24-
FILE *fp);
25-
#else
26-
extern dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix,
27-
const char *shortname,
28-
const char *pathname, FILE *fp);
29-
#endif
30-
31-
#endif /* HAVE_DYNAMIC_LOADING */
32-
33-
3413
/***********************************/
3514
/* module info to use when loading */
3615
/***********************************/
@@ -414,6 +393,9 @@ _PyImport_GetModuleExportHooks(
414393
*modexport = (PyModExportFunction)exportfunc;
415394
return 2;
416395
}
396+
if (PyErr_Occurred()) {
397+
return -1;
398+
}
417399

418400
exportfunc = findfuncptr(
419401
info->hook_prefixes->init_prefix,

0 commit comments

Comments
 (0)