_libc: Helper FFI module to find and load proper libc for the system.

It's needed because different LIBC implementation use different shared
library names, so this module abstracts operation of finding the correct
one.

Default search order:

1. libc.so. This is usually doesn't exist, but user can create such symlink,
and it will be used fast.
2. libc.so.0, as used by current uClibc versions.
3. libc.so.6, as used by current Glibc versions.

uClibc is tried first because system where it is used are usually
underpowered to do array of attempts.

User can also override default search names by calling _libc.set_names(),
(which should be called before importing any other modules).
pull/118/head^2
Paul Sokolovsky 2014-06-21 04:09:22 +03:00
rodzic 41e738f1b0
commit a6dee730f3
3 zmienionych plików z 49 dodań i 0 usunięć

24
_libc/_libc.py 100644
Wyświetl plik

@ -0,0 +1,24 @@
import ffi
_h = None
names = ('libc.so', 'libc.so.0', 'libc.so.6')
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

Wyświetl plik

@ -0,0 +1,7 @@
dist_name = libc
srctype = micropython-lib
type = module
version = 0.1
author = Paul Sokolovsky
desc = MicroPython FFI helper module
long_desc = MicroPython FFI helper module to interface with underlying libc

18
_libc/setup.py 100644
Wyświetl plik

@ -0,0 +1,18 @@
import sys
# Remove current dir from sys.path, otherwise setuptools will peek up our
# module instead of system.
sys.path.pop(0)
from setuptools import setup
setup(name='micropython-libc',
version='0.1',
description='MicroPython FFI helper module',
long_description='MicroPython FFI helper module to interface with underlying libc',
url='https://github.com/micropython/micropython/issues/405',
author='Paul Sokolovsky',
author_email='micro-python@googlegroups.com',
maintainer='MicroPython Developers',
maintainer_email='micro-python@googlegroups.com',
license='MIT',
py_modules=['_libc'])