Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
You can now compile Python on MacOS < 11.0 and
:meth:`ctypes.util.find_library` will still work on MacOS >= 11.0.
29 changes: 26 additions & 3 deletions Modules/_ctypes/callproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1442,14 +1442,37 @@ copy_com_pointer(PyObject *self, PyObject *args)
return r;
}
#else

#ifdef __APPLE__
#ifdef HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH
#define HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH_RUNTIME \
__builtin_available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
#else
// Support the deprecated case of compiling on an older MacOS version
static void *libsystem_b_handle;
static bool (*_dyld_shared_cache_contains_path)(const char *path);

__attribute__((constructor)) void load_dyld_shared_cache_contains_path(void) {
libsystem_b_handle = dlopen("/usr/lib/libSystem.B.dylib", RTLD_LAZY);
if (libsystem_b_handle != NULL) {
_dyld_shared_cache_contains_path = dlsym(libsystem_b_handle, "_dyld_shared_cache_contains_path");
}
}

__attribute__((destructor)) void unload_dyld_shared_cache_contains_path(void) {
if (libsystem_b_handle != NULL) {
dlclose(libsystem_b_handle);
}
}
#define HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH_RUNTIME \
_dyld_shared_cache_contains_path != NULL
#endif

static PyObject *py_dyld_shared_cache_contains_path(PyObject *self, PyObject *args)
{
PyObject *name, *name2;
char *name_str;

if (__builtin_available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)) {
if (HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH_RUNTIME) {
int r;

if (!PyArg_ParseTuple(args, "O", &name))
Expand Down Expand Up @@ -1992,7 +2015,7 @@ PyMethodDef _ctypes_module_methods[] = {
{"dlclose", py_dl_close, METH_VARARGS, "dlclose a library"},
{"dlsym", py_dl_sym, METH_VARARGS, "find symbol in shared library"},
#endif
#ifdef HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH
#ifdef __APPLE__
{"_dyld_shared_cache_contains_path", py_dyld_shared_cache_contains_path, METH_VARARGS, "check if path is in the shared cache"},
#endif
{"alignment", align_func, METH_O, alignment_doc},
Expand Down