How to use the cffi.verifier function in cffi

To help you get started, we’ve selected a few cffi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github holzschu / python3_ios / extraPackages / cffi-1.11.5 / testing / cffi0 / test_verify.py View on Github external
def test_module_type():
    import cffi.verifier
    ffi = FFI()
    lib = ffi.verify()
    if hasattr(lib, '_cffi_python_module'):
        print('verify got a PYTHON module')
    if hasattr(lib, '_cffi_generic_module'):
        print('verify got a GENERIC module')
    expected_generic = (cffi.verifier._FORCE_GENERIC_ENGINE or
                        '__pypy__' in sys.builtin_module_names)
    assert hasattr(lib, '_cffi_python_module') == (not expected_generic)
    assert hasattr(lib, '_cffi_generic_module') == expected_generic
github JarryShaw / f2format / vendor / pypy / extra_tests / cffi_tests / cffi0 / test_verify.py View on Github external
def setup_module():
    import cffi.verifier
    cffi.verifier.cleanup_tmpdir()
    #
    # check that no $ sign is produced in the C file; it used to be the
    # case that anonymous enums would produce '$enum_$1', which was
    # used as part of a function name.  GCC accepts such names, but it's
    # apparently non-standard.
    _r_comment = re.compile(r"/\*.*?\*/|//.*?$", re.DOTALL | re.MULTILINE)
    _r_string = re.compile(r'\".*?\"')
    def _write_source_and_check(self, file=None):
        base_write_source(self, file)
        if file is None:
            f = open(self.sourcefilename)
            data = f.read()
            f.close()
            data = _r_comment.sub(' ', data)
            data = _r_string.sub('"skipped"', data)
            assert '$' not in data
github neovim / pynvim / neovim / ui / tickit_ui.py View on Github external
void tickit_term_set_output_buffer(TickitTerm *tt, size_t len);
void tickit_term_flush(TickitTerm *tt);
void tickit_pen_set_colour_attr(TickitPen *pen, TickitPenAttr attr, int val);
void tickit_pen_set_bool_attr(TickitPen *pen, TickitPenAttr attr, bool val);
void tickit_term_printn(TickitTerm *tt, const char *str, size_t len);
int  tickit_term_goto(TickitTerm *tt, int line, int col);
void tickit_term_get_size(TickitTerm *tt, int *lines, int *cols);
void tickit_term_set_size(TickitTerm *tt, int lines, int cols);
void tickit_term_refresh_size(TickitTerm *tt);
void tickit_term_clear(TickitTerm *tt);
int tickit_term_bind_event(TickitTerm *tt, TickitEventType ev,
                           TickitTermEventFn *fn, void *user);
'''


class TickitVerifier(cffi.verifier.Verifier):
    def get_extension(self, *args, **kwargs):
        # Executed only the first time the native extension needs to be built
        from subprocess import check_output
        try:
            inc_dir = check_output(['pkg-config', '--cflags',
                                    'tickit']).strip()[2:]
            lib_dir = check_output(['pkg-config', '--libs', '--libs-only-L',
                                    'tickit']).strip()[2:]
            if os.path.isdir(inc_dir):
                self.kwds['include_dirs'] = [inc_dir]
            if os.path.isdir(lib_dir):
                link_flags = '-Wl,-rpath={0}'.format(lib_dir)
                self.kwds['library_dirs'] = [lib_dir]
                self.kwds['extra_link_args'] = [link_flags]
        except OSError as e:
            if e.errno != os.errno.ENOENT:
github pyca / pynacl / src / nacl / c / _lib.py View on Github external
int crypto_hash_sha512(unsigned char *out, const unsigned char *in, unsigned long long inlen);
    """

    # Secure Random
    """
        void randombytes(unsigned char * const buf, const unsigned long long buf_len);
    """

    # Low Level - Scalar Multiplication
    """
        int crypto_scalarmult_curve25519_base(unsigned char *q, const unsigned char *n);
    """
)


ffi.verifier = cffi.verifier.Verifier(ffi,
    "#include ",

    # We need to link to the sodium library
    libraries=["sodium"],

    # Our ext_package is nacl so look for it
    ext_package="nacl",
)


# This works around a bug in PyPy where CFFI exposed functions do not have a
# __name__ attribute. See https://bugs.pypy.org/issue1452
def wraps(wrapped):
    def inner(func):
        if hasattr(wrapped, "__name__"):
            return functools.wraps(wrapped)(func)