extern int _Py_ext_module_loader_info_init_for_builtin(
struct _Py_ext_module_loader_info *p_info,
PyObject *name);
+#ifdef HAVE_DYNAMIC_LOADING
extern int _Py_ext_module_loader_info_init_from_spec(
struct _Py_ext_module_loader_info *info,
PyObject *spec);
+#endif
/* The result from running an extension module's init function. */
struct _Py_ext_module_loader_result {
/* The module init function. */
typedef PyObject *(*PyModInitFunction)(void);
+#ifdef HAVE_DYNAMIC_LOADING
extern PyModInitFunction _PyImport_GetModInitFunc(
struct _Py_ext_module_loader_info *info,
FILE *fp);
+#endif
extern int _PyImport_RunModInitFunc(
PyModInitFunction p0,
struct _Py_ext_module_loader_info *info,
Each item is a tuple (loader, suffixes).
"""
- if sys.platform in {"ios", "tvos", "watchos"}:
- extension_loaders = [(AppleFrameworkLoader, [
- suffix.replace(".so", ".fwork")
- for suffix in _imp.extension_suffixes()
- ])]
- else:
- extension_loaders = []
- extension_loaders.append((ExtensionFileLoader, _imp.extension_suffixes()))
+ extension_loaders = []
+ if hasattr(_imp, 'create_dynamic'):
+ if sys.platform in {"ios", "tvos", "watchos"}:
+ extension_loaders = [(AppleFrameworkLoader, [
+ suffix.replace(".so", ".fwork")
+ for suffix in _imp.extension_suffixes()
+ ])]
+ extension_loaders.append((ExtensionFileLoader, _imp.extension_suffixes()))
source = SourceFileLoader, SOURCE_SUFFIXES
bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES
return extension_loaders + [source, bytecode]
--- /dev/null
+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.)
#include "pycore_pystate.h"
#include "pycore_runtime.h"
+#include "pycore_importdl.h"
+
/* ./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
*/
#ifdef HAVE_DYNAMIC_LOADING
-#include "pycore_importdl.h"
-
#ifdef MS_WINDOWS
extern dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
const char *shortname,
const char *pathname, FILE *fp);
#endif
+#endif /* HAVE_DYNAMIC_LOADING */
+
/***********************************/
/* module info to use when loading */
return 0;
}
+#ifdef HAVE_DYNAMIC_LOADING
int
_Py_ext_module_loader_info_init_from_spec(
struct _Py_ext_module_loader_info *p_info,
Py_DECREF(filename);
return err;
}
+#endif /* HAVE_DYNAMIC_LOADING */
/********************************/
/* getting/running the module init function */
/********************************************/
+#ifdef HAVE_DYNAMIC_LOADING
PyModInitFunction
_PyImport_GetModInitFunc(struct _Py_ext_module_loader_info *info,
FILE *fp)
return (PyModInitFunction)exportfunc;
}
+#endif /* HAVE_DYNAMIC_LOADING */
int
_PyImport_RunModInitFunc(PyModInitFunction p0,
p_res->err = &p_res->_err;
return -1;
}
-
-#endif /* HAVE_DYNAMIC_LOADING */
import sys
import sysconfig
import warnings
+import _imp
from importlib._bootstrap import _load as bootstrap_load
from importlib.machinery import BuiltinImporter, ExtensionFileLoader, ModuleSpec
self.notavailable = []
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:
logger.debug("Checking '%s' (%s)", modinfo.name, self.get_location(modinfo))
if modinfo.state == ModuleState.DISABLED:
logger.error("%s failed to import: %s", modinfo.name, e)
raise
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)
raise