8000 [3.13] gh-122907: Fix Builds Without HAVE_DYNAMIC_LOADING Set (gh-122… · python/cpython@dddea7c · GitHub
[go: up one dir, main page]

Skip to content

Commit dddea7c

Browse files
[3.13] gh-122907: Fix Builds Without HAVE_DYNAMIC_LOADING Set (gh-122952) (#122984)
gh-122907: Fix Builds Without HAVE_DYNAMIC_LOADING Set (gh-122952) As of 529a160 (gh-118204), building with HAVE_DYNAMIC_LOADING stopped working. This is a minimal fix just to get builds working again. There are actually a number of long-standing deficiencies with HAVE_DYNAMIC_LOADING builds that need to be resolved separately. (cherry picked from commit ee1b8ce) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
1 parent ae3f347 commit dddea7c

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

Include/internal/pycore_importdl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ extern int _Py_ext_module_loader_info_init_for_core(
5656
extern int _Py_ext_module_loader_info_init_for_builtin(
5757
struct _Py_ext_module_loader_info *p_info,
5858
PyObject *name);
59+
#ifdef HAVE_DYNAMIC_LOADING
5960
extern int _Py_ext_module_loader_info_init_from_spec(
6061
struct _Py_ext_module_loader_info *info,
6162
PyObject *spec);
63+
#endif
6264

6365
/* The result from running an extension module's init function. */
6466
struct _Py_ext_module_loader_result {
@@ -87,9 +89,11 @@ extern void _Py_ext_module_loader_result_apply_error(
8789

8890
/* The module init function. */
8991
typedef PyObject *(*PyModInitFunction)(void);
92+
#ifdef HAVE_DYNAMIC_LOADING
9093
extern PyModInitFunction _PyImport_GetModInitFunc(
9194
struct _Py_ext_module_loader_info *info,
9295
FILE *fp);
96+
#endif
9397
extern int _PyImport_RunModInitFunc(
9498
PyModInitFunction p0,
9599
struct _Py_ext_module_loader_info *info,

Lib/importlib/_bootstrap_external.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,14 +1797,14 @@ def _get_supported_file_loaders():
17971797
17981798
Each item is a tuple (loader, suffixes).
17991799
"""
1800-
if sys.platform in {"ios", "tvos", "watchos"}:
1801-
extension_loaders = [(AppleFrameworkLoader, [
1802-
suffix.replace(".so", ".fwork")
1803-
for suffix in _imp.extension_suffixes()
1804-
])]
1805-
else:
1806-
extension_loaders = []
1807-
extension_loaders.append((ExtensionFileLoader, _imp.extension_suffixes()))
1800+
extension_loaders = []
1801+
if hasattr(_imp, 'create_dynamic'):
1802+
if sys.platform in {"ios", "tvos", "watchos"}:
1803+
extension_loaders = [(AppleFrameworkLoader, [
1804+
suffix.replace(".so", ".fwork")
1805+
for suffix in _imp.extension_suffixes()
1806+
])]
1807+
extension_loaders.append((ExtensionFileLoader, _imp.extension_suffixes()))
18081808
source = SourceFileLoader, SOURCE_SUFFIXES
18091809
bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES
18101810
return extension_loaders + [source, bytecode]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Building with ``HAVE_DYNAMIC_LOADING`` now works as well as it did in 3.12.
2+
Existing deficiences will be addressed separately.
3+
(See https://github.com/python/cpython/issues/122950.)

Python/importdl.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
#include "pycore_pystate.h"
99
#include "pycore_runtime.h"
1010

11+
#include "pycore_importdl.h"
12+
1113
/* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is
1214
supported on this platform. configure will then compile and link in one
1315
of the dynload_*.c files, as appropriate. We will call a function in
1416
those modules to get a function pointer to the module's init function.
1517
*/
1618
#ifdef HAVE_DYNAMIC_LOADING
1719

18-
#include "pycore_importdl.h"
19-
2020
#ifdef MS_WINDOWS
2121
extern dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
2222
const char *shortname,
@@ -28,6 +28,8 @@ extern dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix,
2828
const char *pathname, FILE *fp);
2929
#endif
3030

31+
#endif /* HAVE_DYNAMIC_LOADING */
32+
3133

3234
/***********************************/
3335
/* module info to use when loading */
@@ -205,6 +207,7 @@ _Py_ext_module_loader_info_init_for_core(
205207
return 0;
206208
}
207209

210+
#ifdef HAVE_DYNAMIC_LOADING
208211
int
209212
_Py_ext_module_loader_info_init_from_spec(
210213
struct _Py_ext_module_loader_info *p_info,
@@ -226,6 +229,7 @@ _Py_ext_module_loader_info_init_from_spec(
226229
Py_DECREF(filename);
227230
return err;
228231
}
232+
#endif /* HAVE_DYNAMIC_LOADING */
229233

230234

231235
/********************************/
@@ -372,6 +376,7 @@ _Py_ext_module_loader_result_apply_error(
372376
/* getting/running the module init function */
373377
/********************************************/
374378

379+
#ifdef HAVE_DYNAMIC_LOADING
375380
PyModInitFunction
376381
_PyImport_GetModInitFunc(struct _Py_ext_module_loader_info *info,
377382
FILE *fp)
@@ -406,6 +411,7 @@ _PyImport_GetModInitFunc(struct _Py_ext_module_loader_info *info,
406411

407412
return (PyModInitFunction)exportfunc;
408413
}
414+
#endif /* HAVE_DYNAMIC_LOADING */
409415

410416
int
411417
_PyImport_RunModInitFunc(PyModInitFunction p0,
@@ -513,5 +519,3 @@ _PyImport_RunModInitFunc(PyModInitFunction p0,
513519
p_res->err = &p_res->_err;
514520
return -1;
515521
}
516-
517-
#endif /* HAVE_DYNAMIC_LOADING */

Tools/build/check_extension_modules.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import sys
2828
import sysconfig
2929
import warnings
30+
import _imp
3031

3132
from importlib._bootstrap import _load as bootstrap_load
3233
from importlib.machinery import BuiltinImporter, ExtensionFileLoader, ModuleSpec
@@ -154,6 +155,11 @@ def __init__(self, cross_compiling: bool = False, strict: bool = False):
154155
self.notavailable = []
155156

156157
def check(self):
158+
if not hasattr(_imp, 'create_dynamic'):
159+
logger.warning(
160+
('Dynamic extensions not supported '
161+
'(HAVE_DYNAMIC_LOADING not defined)'),
162+
)
157163
for modinfo in self.modules:
158164
logger.debug("Checking '%s' (%s)", modinfo.name, self.get_location(modinfo))
159165
if modinfo.state == ModuleState.DISABLED:
@@ -415,6 +421,9 @@ def check_module_import(self, modinfo: ModuleInfo):
415421
logger.error("%s failed to import: %s", modinfo.name, e)
416422
raise
417423
except Exception as e:
424+
if not hasattr(_imp, 'create_dynamic'):
425+
logger.warning("Dynamic extension '%s' ignored", modinfo.name)
426+
return
418427
logger.exception("Importing extension '%s' failed!", modinfo.name)
419428
raise
420429

0 commit comments

Comments
 (0)
0