# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from pycopy import const import sys import ffilib import uarray as array pcre = ffilib.open("libpcre") # pcre *pcre_compile(const char *pattern, int options, # const char **errptr, int *erroffset, # const unsigned char *tableptr); pcre_compile = pcre.func("p", "pcre_compile", "sipps") # int pcre_exec(const pcre *code, const pcre_extra *extra, # const char *subject, int length, int startoffset, # int options, int *ovector, int ovecsize); pcre_exec = pcre.func("i", "pcre_exec", "PPsiiipi") # int pcre_fullinfo(const pcre *code, const pcre_extra *extra, # int what, void *where); pcre_fullinfo = pcre.func("i", "pcre_fullinfo", "PPip")
# vim:ts=4:sw=4:sts=4:et:ai:fdm=marker # (c) 2014-2018 Paul Sokolovsky. MIT license. import sys import ffilib import uerrno PTR_SZ = 8 if ffilib.bitness > 32 else 4 sq3 = ffilib.open("libsqlite3") sqlite3_open = sq3.func("i", "sqlite3_open", "sp") #int sqlite3_close(sqlite3*); sqlite3_close = sq3.func("i", "sqlite3_close", "p") #int sqlite3_prepare( # sqlite3 *db, /* Database handle */ # const char *zSql, /* SQL statement, UTF-8 encoded */ # int nByte, /* Maximum length of zSql in bytes. */ # sqlite3_stmt **ppStmt, /* OUT: Statement handle */ # const char **pzTail /* OUT: Pointer to unused portion of zSql */ #); sqlite3_prepare = sq3.func("i", "sqlite3_prepare", "psipp") #int sqlite3_finalize(sqlite3_stmt *pStmt); sqlite3_finalize = sq3.func("i", "sqlite3_finalize", "p") #int sqlite3_step(sqlite3_stmt*); sqlite3_step = sq3.func("i", "sqlite3_step", "p") #int sqlite3_column_count(sqlite3_stmt *pStmt); sqlite3_column_count = sq3.func("i", "sqlite3_column_count", "p") #int sqlite3_column_type(sqlite3_stmt*, int iCol); sqlite3_column_type = sq3.func("i", "sqlite3_column_type", "pi") sqlite3_column_int = sq3.func("i", "sqlite3_column_int", "pi")
https://github.com/micropython/micropython-lib/blob/master/machine/machine/timer.py https://github.com/micropython/micropython/blob/master/unix/modffi.c#L101 http://man7.org/linux/man-pages/man2/timer_settime.2.html ''' import os import uos import errno import utime import array import ffilib import uctypes from signal import * libc = ffilib.libc() librt = ffilib.open("librt") _ONE_SHOT = const(0) _PERIODIC = const(1) _CLOCK_REALTIME = const(0) _CLOCK_MONOTONIC = const(1) _SIGEV_SIGNAL = const(0) _MILISECOND = const(1000000) sigval_t = { "sival_int": uctypes.INT32 | 0, "sival_ptr": (uctypes.PTR | 0, uctypes.UINT8), }
_BEEP_DEV = '/dev/input/by-path/platform-sound-event' # stuff from linux/input.h and linux/input-event-codes.h _EV_SND = 0x12 _SND_TONE = 0x02 _input_event = { 'time': UINT64 | 0, # struct timeval 'type': UINT16 | 8, 'code': UINT16 | 10, 'value': INT32 | 12, } # libsndfile _libsndfile = ffilib.open('libsndfile') _sf_count_t = UINT64 _SF_INFO = { 'frames': _sf_count_t | 0, 'samplerate': INT32 | 8, 'channels': INT32 | 12, 'format': INT32 | 16, 'sections': INT32 | 20, 'seekable': INT32 | 24, } _SMF_READ = 0x10 # FIXME: micropython does not have 64-bit integer, using double for now
import sys import ffilib sq3 = ffilib.open("libsqlite3") sqlite3_open = sq3.func("i", "sqlite3_open", "sp") #int sqlite3_close(sqlite3*); sqlite3_close = sq3.func("i", "sqlite3_close", "p") #int sqlite3_prepare( # sqlite3 *db, /* Database handle */ # const char *zSql, /* SQL statement, UTF-8 encoded */ # int nByte, /* Maximum length of zSql in bytes. */ # sqlite3_stmt **ppStmt, /* OUT: Statement handle */ # const char **pzTail /* OUT: Pointer to unused portion of zSql */ #); sqlite3_prepare = sq3.func("i", "sqlite3_prepare", "psipp") #int sqlite3_finalize(sqlite3_stmt *pStmt); sqlite3_finalize = sq3.func("i", "sqlite3_finalize", "p") #int sqlite3_step(sqlite3_stmt*); sqlite3_step = sq3.func("i", "sqlite3_step", "p") #int sqlite3_column_count(sqlite3_stmt *pStmt); sqlite3_column_count = sq3.func("i", "sqlite3_column_count", "p") #int sqlite3_column_type(sqlite3_stmt*, int iCol); sqlite3_column_type = sq3.func("i", "sqlite3_column_type", "pi") sqlite3_column_int = sq3.func("i", "sqlite3_column_int", "pi") # using "d" return type gives wrong results sqlite3_column_double = sq3.func("d", "sqlite3_column_double", "pi") sqlite3_column_text = sq3.func("s", "sqlite3_column_text", "pi") #sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); # TODO: should return long int
# The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. from uzlib import * import ffilib import uctypes libz = ffilib.open("libz") libc = ffilib.libc() malloc_ = libc.func("p", "malloc", "L") free_ = libc.func("v", "free", "p") compressBound_ = libz.func("L", "compressBound", "L") compress2_ = libz.func("i", "compress2", "ppPLi") def compress(data, level=-1): dest_buf_sz = compressBound_(len(data)) buf = malloc_(dest_buf_sz) assert buf is not None dest_sz_ref = ffilib.makeref("L", dest_buf_sz) res = compress2_(buf, dest_sz_ref, data, len(data), level) assert res == 0
from errno import EPIPE from struct import calcsize from struct import unpack import ffilib from uctypes import addressof from uev3dev.util import debug_print _alsa = ffilib.open('libasound') _strerror = _alsa.func('s', 'snd_strerror', 'i') def _check_error(err): if err < 0: raise AlsaError(_strerror(err)) class AlsaError(Exception): def __init__(self, message): super(AlsaError, self).__init__(message) class Mixer(): _open = _alsa.func('i', 'snd_mixer_open', 'pi') _close = _alsa.func('i', 'snd_mixer_close', 'p') _attach = _alsa.func('i', 'snd_mixer_attach', 'ps') _load = _alsa.func('i', 'snd_mixer_load', 'p') _selem_register = _alsa.func('i', 'snd_mixer_selem_register', 'ppp')
import ffilib import array pcre = ffilib.open("libpcre") # pcre *pcre_compile(const char *pattern, int options, # const char **errptr, int *erroffset, # const unsigned char *tableptr); pcre_compile = pcre.func("p", "pcre_compile", "sipps") # int pcre_exec(const pcre *code, const pcre_extra *extra, # const char *subject, int length, int startoffset, # int options, int *ovector, int ovecsize); pcre_exec = pcre.func("i", "pcre_exec", "PPsiiipi") # int pcre_fullinfo(const pcre *code, const pcre_extra *extra, # int what, void *where); pcre_fullinfo = pcre.func("i", "pcre_fullinfo", "PPip") IGNORECASE = I = 1 MULTILINE = M = 2 DOTALL = S = 4 VERBOSE = X = 8 PCRE_ANCHORED = 0x10 # TODO. Note that Python3 has unicode by default ASCII = A = 0 UNICODE = U = 0
import ffilib import uctypes import array import uos import os import utime from signal import * libc = ffilib.libc() librt = ffilib.open("librt") CLOCK_REALTIME = 0 CLOCK_MONOTONIC = 1 SIGEV_SIGNAL = 0 sigval_t = {"sival_int": uctypes.INT32 | 0, "sival_ptr": (uctypes.PTR | 0, uctypes.UINT8)} sigevent_t = {"sigev_value": (0, sigval_t), "sigev_signo": uctypes.INT32 | 8, "sigev_notify": uctypes.INT32 | 12} timespec_t = {"tv_sec": uctypes.INT32 | 0, "tv_nsec": uctypes.INT64 | 8} itimerspec_t = {"it_interval": (0, timespec_t), "it_value": (16, timespec_t)} __libc_current_sigrtmin = libc.func("i", "__libc_current_sigrtmin", "") SIGRTMIN = __libc_current_sigrtmin() timer_create_ = librt.func("i", "timer_create", "ipp") timer_settime_ = librt.func("i", "timer_settime", "PiPp")
"""Wrapper around libmagickwand """ import ffilib from struct import calcsize from struct import unpack from uctypes import bytearray_at _wand = ffilib.open('libMagickWand-6.Q16') _genisis = _wand.func('v', 'MagickWandGenesis', '') _terminus = _wand.func('v', 'MagickWandTerminus', '') _new = _wand.func('p', 'NewMagickWand', '') _destroy = _wand.func('p', 'DestroyMagickWand', 'p') _clear_exception = _wand.func('i', 'MagickClearException', 'p') _get_exception = _wand.func('p', 'MagickGetException', 'pp') # _get_exception_type = _wand.func('I', 'MagickGetExceptionType', 'p') _relinquish_memory = _wand.func('p', 'MagickRelinquishMemory', 'p') _read_image = _wand.func('I', 'MagickReadImage', 'pP') _write_image = _wand.func('I', 'MagickWriteImage', 'pP') _export_image_pixels = _wand.func('i', 'MagickExportImagePixels', 'pPPPPPIp') _reset_iterator = _wand.func('v', 'MagickResetIterator', 'p') _border_image = _wand.func('i', 'MagickBorderImage', 'pPPPI') _extent_image = _wand.func('i', 'MagickExtentImage', 'pPPPP') _get_image_width = _wand.func('p', 'MagickGetImageWidth', 'p') _get_image_height = _wand.func('p', 'MagickGetImageHeight', 'p') _get_image_depth = _wand.func('p', 'MagickGetImageDepth', 'p') _set_image_depth = _wand.func('i', 'MagickSetImageDepth', 'pP') _get_image_format = _wand.func('s', 'MagickGetImageFormat', 'p') _set_image_format = _wand.func('i', 'MagickSetImageFormat', 'pP')