From 5633db3aec8bcc4c7a68209f9379676aae2ce6d4 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 30 Aug 2015 03:15:37 +0300 Subject: [PATCH] upip: Drop _libc, add ffilib. --- upip/Makefile | 2 +- upip/upip__libc.py | 34 ---------------------------------- upip/upip_ffilib.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 35 deletions(-) delete mode 100644 upip/upip__libc.py create mode 100644 upip/upip_ffilib.py diff --git a/upip/Makefile b/upip/Makefile index 5137336a..802f8cbf 100644 --- a/upip/Makefile +++ b/upip/Makefile @@ -2,7 +2,7 @@ all: # This target prepares snapshot of all dependency modules, for # self-contained install -deps: upip__libc.py upip_os.py upip_os_path.py upip_errno.py upip_gzip.py upip_stat.py upip_utarfile.py +deps: upip_ffilib.py upip_os.py upip_os_path.py upip_errno.py upip_gzip.py upip_stat.py upip_utarfile.py upip_ffilib.py: ../ffilib/ffilib.py cp $^ $@ diff --git a/upip/upip__libc.py b/upip/upip__libc.py deleted file mode 100644 index a930cbf7..00000000 --- a/upip/upip__libc.py +++ /dev/null @@ -1,34 +0,0 @@ -import ffi -import sys - - -_h = None - -names = ('libc.so', 'libc.so.0', 'libc.so.6', 'libc.dylib') - -def get(): - global _h - if _h: - return _h - err = None - for n in names: - try: - _h = ffi.open(n) - return _h - except OSError as e: - err = e - raise err - - -def set_names(n): - global names - names = n - -# Find out bitness of the platform, even if long ints are not supported -# TODO: All bitness differences should be removed from micropython-lib, and -# this snippet too. -bitness = 1 -v = sys.maxsize -while v: - bitness += 1 - v >>= 1 diff --git a/upip/upip_ffilib.py b/upip/upip_ffilib.py new file mode 100644 index 00000000..72ceedaf --- /dev/null +++ b/upip/upip_ffilib.py @@ -0,0 +1,41 @@ +import sys +import ffi + +_cache = {} + +def open(name, maxver=10, extra=()): + try: + return _cache[name] + except KeyError: + pass + def libs(): + if sys.platform == "linux": + yield '%s.so' % name + for i in range(maxver, -1, -1): + yield '%s.so.%u' % (name, i) + else: + for ext in ('dylib', 'dll'): + yield '%s.%s' % (name, ext) + for n in extra: + yield n + err = None + for n in libs(): + try: + l = ffi.open(n) + _cache[name] = l + return l + except OSError as e: + err = e + raise err + +def libc(): + return open("libc", 6) + +# Find out bitness of the platform, even if long ints are not supported +# TODO: All bitness differences should be removed from micropython-lib, and +# this snippet too. +bitness = 1 +v = sys.maxsize +while v: + bitness += 1 + v >>= 1