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.
This commit is contained in:
Eric Snow 2024-08-13 14:44:57 -06:00 committed by GitHub
parent 5f68511522
commit ee1b8ce26e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 32 additions and 12 deletions

View File

@ -56,9 +56,11 @@ extern int _Py_ext_module_loader_info_init_for_core(
extern int _Py_ext_module_loader_info_init_for_builtin( extern int _Py_ext_module_loader_info_init_for_builtin(
struct _Py_ext_module_loader_info *p_info, struct _Py_ext_module_loader_info *p_info,
PyObject *name); PyObject *name);
#ifdef HAVE_DYNAMIC_LOADING
extern int _Py_ext_module_loader_info_init_from_spec( extern int _Py_ext_module_loader_info_init_from_spec(
struct _Py_ext_module_loader_info *info, struct _Py_ext_module_loader_info *info,
PyObject *spec); PyObject *spec);
#endif
/* The result from running an extension module's init function. */ /* The result from running an extension module's init function. */
struct _Py_ext_module_loader_result { struct _Py_ext_module_loader_result {
@ -87,9 +89,11 @@ extern void _Py_ext_module_loader_result_apply_error(
/* The module init function. */ /* The module init function. */
typedef PyObject *(*PyModInitFunction)(void); typedef PyObject *(*PyModInitFunction)(void);
#ifdef HAVE_DYNAMIC_LOADING
extern PyModInitFunction _PyImport_GetModInitFunc( extern PyModInitFunction _PyImport_GetModInitFunc(
struct _Py_ext_module_loader_info *info, struct _Py_ext_module_loader_info *info,
FILE *fp); FILE *fp);
#endif
extern int _PyImport_RunModInitFunc( extern int _PyImport_RunModInitFunc(
PyModInitFunction p0, PyModInitFunction p0,
struct _Py_ext_module_loader_info *info, struct _Py_ext_module_loader_info *info,

View File

@ -1523,14 +1523,14 @@ def _get_supported_file_loaders():
Each item is a tuple (loader, suffixes). Each item is a tuple (loader, suffixes).
""" """
if sys.platform in {"ios", "tvos", "watchos"}: extension_loaders = []
extension_loaders = [(AppleFrameworkLoader, [ if hasattr(_imp, 'create_dynamic'):
suffix.replace(".so", ".fwork") if sys.platform in {"ios", "tvos", "watchos"}:
for suffix in _imp.extension_suffixes() extension_loaders = [(AppleFrameworkLoader, [
])] suffix.replace(".so", ".fwork")
else: for suffix in _imp.extension_suffixes()
extension_loaders = [] ])]
extension_loaders.append((ExtensionFileLoader, _imp.extension_suffixes())) extension_loaders.append((ExtensionFileLoader, _imp.extension_suffixes()))
source = SourceFileLoader, SOURCE_SUFFIXES source = SourceFileLoader, SOURCE_SUFFIXES
bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES
return extension_loaders + [source, bytecode] return extension_loaders + [source, bytecode]

View File

@ -0,0 +1,3 @@
Building with ``HAVE_DYNAMIC_LOADING`` now works as well as it did in 3.12.
Existing deficiences will be addressed separately.
(See https://github.com/python/cpython/issues/122950.)

View File

@ -8,6 +8,8 @@
#include "pycore_pystate.h" #include "pycore_pystate.h"
#include "pycore_runtime.h" #include "pycore_runtime.h"
#include "pycore_importdl.h"
/* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is /* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is
supported on this platform. configure will then compile and link in one 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 of the dynload_*.c files, as appropriate. We will call a function in
@ -15,8 +17,6 @@
*/ */
#ifdef HAVE_DYNAMIC_LOADING #ifdef HAVE_DYNAMIC_LOADING
#include "pycore_importdl.h"
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
extern dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, extern dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
const char *shortname, const char *shortname,
@ -28,6 +28,8 @@ extern dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix,
const char *pathname, FILE *fp); const char *pathname, FILE *fp);
#endif #endif
#endif /* HAVE_DYNAMIC_LOADING */
/***********************************/ /***********************************/
/* module info to use when loading */ /* module info to use when loading */
@ -205,6 +207,7 @@ _Py_ext_module_loader_info_init_for_core(
return 0; return 0;
} }
#ifdef HAVE_DYNAMIC_LOADING
int int
_Py_ext_module_loader_info_init_from_spec( _Py_ext_module_loader_info_init_from_spec(
struct _Py_ext_module_loader_info *p_info, struct _Py_ext_module_loader_info *p_info,
@ -226,6 +229,7 @@ _Py_ext_module_loader_info_init_from_spec(
Py_DECREF(filename); Py_DECREF(filename);
return err; return err;
} }
#endif /* HAVE_DYNAMIC_LOADING */
/********************************/ /********************************/
@ -372,6 +376,7 @@ _Py_ext_module_loader_result_apply_error(
/* getting/running the module init function */ /* getting/running the module init function */
/********************************************/ /********************************************/
#ifdef HAVE_DYNAMIC_LOADING
PyModInitFunction PyModInitFunction
_PyImport_GetModInitFunc(struct _Py_ext_module_loader_info *info, _PyImport_GetModInitFunc(struct _Py_ext_module_loader_info *info,
FILE *fp) FILE *fp)
@ -406,6 +411,7 @@ _PyImport_GetModInitFunc(struct _Py_ext_module_loader_info *info,
return (PyModInitFunction)exportfunc; return (PyModInitFunction)exportfunc;
} }
#endif /* HAVE_DYNAMIC_LOADING */
int int
_PyImport_RunModInitFunc(PyModInitFunction p0, _PyImport_RunModInitFunc(PyModInitFunction p0,
@ -513,5 +519,3 @@ error:
p_res->err = &p_res->_err; p_res->err = &p_res->_err;
return -1; return -1;
} }
#endif /* HAVE_DYNAMIC_LOADING */

View File

@ -27,6 +27,7 @@ import re
import sys import sys
import sysconfig import sysconfig
import warnings import warnings
import _imp
from importlib._bootstrap import _load as bootstrap_load from importlib._bootstrap import _load as bootstrap_load
from importlib.machinery import BuiltinImporter, ExtensionFileLoader, ModuleSpec from importlib.machinery import BuiltinImporter, ExtensionFileLoader, ModuleSpec
@ -153,6 +154,11 @@ class ModuleChecker:
self.notavailable = [] self.notavailable = []
def check(self): def check(self):
if not hasattr(_imp, 'create_dynamic'):
logger.warning(
('Dynamic extensions not supported '
'(HAVE_DYNAMIC_LOADING not defined)'),
)
for modinfo in self.modules: for modinfo in self.modules:
logger.debug("Checking '%s' (%s)", modinfo.name, self.get_location(modinfo)) logger.debug("Checking '%s' (%s)", modinfo.name, self.get_location(modinfo))
if modinfo.state == ModuleState.DISABLED: if modinfo.state == ModuleState.DISABLED:
@ -414,6 +420,9 @@ class ModuleChecker:
logger.error("%s failed to import: %s", modinfo.name, e) logger.error("%s failed to import: %s", modinfo.name, e)
raise raise
except Exception as e: except Exception as e:
if not hasattr(_imp, 'create_dynamic'):
logger.warning("Dynamic extension '%s' ignored", modinfo.name)
return
logger.exception("Importing extension '%s' failed!", modinfo.name) logger.exception("Importing extension '%s' failed!", modinfo.name)
raise raise