diff options
author | 2021-02-05 13:00:44 +0200 | |
---|---|---|
committer | 2021-02-05 13:00:44 +0200 | |
commit | 7e09ffe3a7c9b93970073ca35fa7aa3ef9df0a1c (patch) | |
tree | 47b392b2b4c45cb9cce12d3126faabd954da5d5a | |
parent | use low-level interface where applicable, add at least a minimal hypothesis t... (diff) | |
download | pypy-7e09ffe3a7c9b93970073ca35fa7aa3ef9df0a1c.tar.gz pypy-7e09ffe3a7c9b93970073ca35fa7aa3ef9df0a1c.tar.bz2 pypy-7e09ffe3a7c9b93970073ca35fa7aa3ef9df0a1c.zip |
backport changes from py3.7-big-sur-dyld-cache to default
-rw-r--r-- | lib-python/2.7/ctypes/macholib/dyld.py | 13 | ||||
-rw-r--r-- | lib-python/2.7/ctypes/test/test_macholib.py | 14 | ||||
-rw-r--r-- | lib_pypy/_ctypes/__init__.py | 21 | ||||
-rw-r--r-- | lib_pypy/pypy_tools/build_cffi_imports.py | 28 |
4 files changed, 53 insertions, 23 deletions
diff --git a/lib-python/2.7/ctypes/macholib/dyld.py b/lib-python/2.7/ctypes/macholib/dyld.py index 1fdf8d648f..9aede10e8b 100644 --- a/lib-python/2.7/ctypes/macholib/dyld.py +++ b/lib-python/2.7/ctypes/macholib/dyld.py @@ -7,6 +7,12 @@ from framework import framework_info from dylib import dylib_info from itertools import * +try: + from _ctypes import _dyld_shared_cache_contains_path +except ImportError: + def _dyld_shared_cache_contains_path(*args): + raise NotImplementedError + __all__ = [ 'dyld_find', 'framework_find', 'framework_info', 'dylib_info', @@ -130,8 +136,15 @@ def dyld_find(name, executable_path=None, env=None): dyld_executable_path_search(name, executable_path), dyld_default_search(name, env), ), env): + if os.path.isfile(path): return path + try: + if _dyld_shared_cache_contains_path(path): + return path + except NotImplementedError: + pass + raise ValueError("dylib %s could not be found" % (name,)) def framework_find(fn, executable_path=None, env=None): diff --git a/lib-python/2.7/ctypes/test/test_macholib.py b/lib-python/2.7/ctypes/test/test_macholib.py index 9779b2f3f4..97dfa9b6d8 100644 --- a/lib-python/2.7/ctypes/test/test_macholib.py +++ b/lib-python/2.7/ctypes/test/test_macholib.py @@ -48,18 +48,22 @@ class MachOTest(unittest.TestCase): @unittest.skipUnless(sys.platform == "darwin", 'OSX-specific test') def test_find(self): - self.assertEqual(find_lib('pthread'), - '/usr/lib/libSystem.B.dylib') + # On Mac OS 11, system dylibs are only present in the shared cache, + # so symlinks like libpthread.dylib -> libSystem.B.dylib will not + # be resolved by dyld_find + self.assertIn(find_lib('pthread'), + ('/usr/lib/libSystem.B.dylib', '/usr/lib/libpthread.dylib')) result = find_lib('z') # Issue #21093: dyld default search path includes $HOME/lib and # /usr/local/lib before /usr/lib, which caused test failures if # a local copy of libz exists in one of them. Now ignore the head # of the path. - self.assertRegexpMatches(result, r".*/lib/libz\..*.*\.dylib") + self.assertRegexpMatches(result, r".*/lib/libz\.*\.dylib") - self.assertEqual(find_lib('IOKit'), - '/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit') + self.assertIn(find_lib('IOKit'), + ('/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit', + '/System/Library/Frameworks/IOKit.framework/IOKit')) if __name__ == "__main__": unittest.main() diff --git a/lib_pypy/_ctypes/__init__.py b/lib_pypy/_ctypes/__init__.py index da30f5f6d9..6a0de8d703 100644 --- a/lib_pypy/_ctypes/__init__.py +++ b/lib_pypy/_ctypes/__init__.py @@ -13,15 +13,15 @@ from _ctypes.builtin import ( _string_at_addr, _wstring_at_addr, set_conversion_mode) from _ctypes.union import Union +try: from __pypy__ import builtinify +except ImportError: builtinify = lambda f: f + import os as _os if _os.name in ("nt", "ce"): from _rawffi import FormatError from _rawffi import check_HRESULT as _check_HRESULT - try: from __pypy__ import builtinify - except ImportError: builtinify = lambda f: f - @builtinify def CopyComPointer(src, dst): from ctypes import c_void_p, cast @@ -32,8 +32,6 @@ if _os.name in ("nt", "ce"): dst[0] = cast(src, c_void_p).value return 0 - del builtinify - LoadLibrary = dlopen from _rawffi import FUNCFLAG_STDCALL, FUNCFLAG_CDECL, FUNCFLAG_PYTHONAPI @@ -43,6 +41,19 @@ from _ctypes.builtin import get_errno, set_errno if _os.name in ("nt", "ce"): from _ctypes.builtin import get_last_error, set_last_error +import sys as _sys +if _sys.platform == 'darwin': + try: + from ._ctypes_cffi import lib as _lib + if hasattr(_lib, 'dyld_shared_cache_contains_path'): + @builtinify + def _dyld_shared_cache_contains_path(path): + return _lib.dyld_shared_cache_contains_path(path.encode()) + except ImportError: + pass + +del builtinify + __version__ = '1.1.0' #XXX platform dependant? RTLD_LOCAL = 0 diff --git a/lib_pypy/pypy_tools/build_cffi_imports.py b/lib_pypy/pypy_tools/build_cffi_imports.py index 12e791d695..47b3559310 100644 --- a/lib_pypy/pypy_tools/build_cffi_imports.py +++ b/lib_pypy/pypy_tools/build_cffi_imports.py @@ -1,5 +1,5 @@ from __future__ import print_function -import sys, shutil, os, tempfile, hashlib +import sys, shutil, os, tempfile, hashlib, collections import sysconfig from os.path import join @@ -22,18 +22,20 @@ class MissingDependenciesError(Exception): pass -cffi_build_scripts = { - "_ssl": "_ssl_build.py", - "sqlite3": "_sqlite3_build.py", - "audioop": "_audioop_build.py", - "_tkinter": "_tkinter/tklib_build.py", - "curses": "_curses_build.py" if sys.platform != "win32" else None, - "syslog": "_syslog_build.py" if sys.platform != "win32" else None, - "gdbm": "_gdbm_build.py" if sys.platform != "win32" else None, - "grp": "_pwdgrp_build.py" if sys.platform != "win32" else None, - "resource": "_resource_build.py" if sys.platform != "win32" else None, - "xx": None, # for testing: 'None' should be completely ignored - } +cffi_build_scripts = collections.OrderedDict({ + ("_ctypes._ctypes_cffi", + "_ctypes/_ctypes_build.py" if sys.platform == 'darwin' else None), + ("_ssl": "_ssl_build.py"), + ("sqlite3": "_sqlite3_build.py"), + ("audioop": "_audioop_build.py"), + ("_tkinter": "_tkinter/tklib_build.py"), + ("curses": "_curses_build.py" if sys.platform != "win32" else None), + ("syslog": "_syslog_build.py" if sys.platform != "win32" else None), + ("gdbm": "_gdbm_build.py" if sys.platform != "win32" else None), + ("grp": "_pwdgrp_build.py" if sys.platform != "win32" else None), + ("resource": "_resource_build.py" if sys.platform != "win32" else None), + ("xx": None), # for testing: 'None' should be completely ignored + }) # for distribution, we may want to fetch dependencies not provided by # the OS, such as a recent openssl/libressl. |