How to use the cffi.FFIError 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 JarryShaw / f2format / vendor / pypy / extra_tests / cffi_tests / cffi0 / test_verify.py View on Github external
def test_implicit_unicode_on_windows():
    if sys.platform != 'win32':
        py.test.skip("win32-only test")
    ffi = FFI()
    e = py.test.raises(FFIError, ffi.cdef, "int foo(LPTSTR);")
    assert str(e.value) == ("The Windows type 'LPTSTR' is only available after"
                            " you call ffi.set_unicode()")
    for with_unicode in [True, False]:
        ffi = FFI()
        ffi.set_unicode(with_unicode)
        ffi.cdef("""
            DWORD GetModuleFileName(HMODULE hModule, LPTSTR lpFilename,
                                    DWORD nSize);
        """)
        lib = ffi.verify("""
            #include 
        """, libraries=['Kernel32'])
        outbuf = ffi.new("TCHAR[]", 200)
        n = lib.GetModuleFileName(ffi.NULL, outbuf, 500)
        assert 0 < n < 500
        for i in range(n):
github holzschu / python3_ios / extraPackages / cffi-1.11.5 / testing / cffi0 / test_verify.py View on Github external
def test_implicit_unicode_on_windows():
    if sys.platform != 'win32':
        py.test.skip("win32-only test")
    ffi = FFI()
    e = py.test.raises(FFIError, ffi.cdef, "int foo(LPTSTR);")
    assert str(e.value) == ("The Windows type 'LPTSTR' is only available after"
                            " you call ffi.set_unicode()")
    for with_unicode in [True, False]:
        ffi = FFI()
        ffi.set_unicode(with_unicode)
        ffi.cdef("""
            DWORD GetModuleFileName(HMODULE hModule, LPTSTR lpFilename,
                                    DWORD nSize);
        """)
        lib = ffi.verify("""
            #include 
        """, libraries=['Kernel32'])
        outbuf = ffi.new("TCHAR[]", 200)
        n = lib.GetModuleFileName(ffi.NULL, outbuf, 500)
        assert 0 < n < 500
        for i in range(n):
github holzschu / python3_ios / extraPackages / cffi-1.11.5 / testing / cffi0 / test_parsing.py View on Github external
def test_override():
    ffi = FFI(backend=FakeBackend())
    needs_dlopen_none()
    C = ffi.dlopen(None)
    ffi.cdef("int foo(void);")
    py.test.raises(FFIError, ffi.cdef, "long foo(void);")
    assert C.foo.BType == ', False>'
    ffi.cdef("long foo(void);", override=True)
    assert C.foo.BType == ', False>'
github JarryShaw / f2format / vendor / pypy / extra_tests / cffi_tests / cffi1 / test_verify1.py View on Github external
def test_implicit_unicode_on_windows():
    from cffi import FFIError
    if sys.platform != 'win32':
        py.test.skip("win32-only test")
    ffi = FFI()
    e = py.test.raises(FFIError, ffi.cdef, "int foo(LPTSTR);")
    assert str(e.value) == ("The Windows type 'LPTSTR' is only available after"
                            " you call ffi.set_unicode()")
    for with_unicode in [True, False]:
        ffi = FFI()
        ffi.set_unicode(with_unicode)
        ffi.cdef("""
            DWORD GetModuleFileName(HMODULE hModule, LPTSTR lpFilename,
                                    DWORD nSize);
        """)
        lib = ffi.verify("""
            #include 
        """, libraries=['Kernel32'])
        outbuf = ffi.new("TCHAR[]", 200)
        n = lib.GetModuleFileName(ffi.NULL, outbuf, 500)
        assert 0 < n < 500
        for i in range(n):
github holzschu / python3_ios / extraPackages / cffi-1.11.5 / testing / cffi1 / test_verify1.py View on Github external
def test_unsupported_some_primitive_types():
    ffi = FFI()
    py.test.raises((FFIError,      # with pycparser <= 2.17
                    CDefError),    # with pycparser >= 2.18
                   ffi.cdef, """typedef void... foo_t;""")
    #
    ffi.cdef("typedef int... foo_t;")
    py.test.raises(VerificationError, ffi.verify, "typedef float foo_t;")
github holzschu / python3_ios / extraPackages / cffi-1.11.5 / testing / cffi1 / test_recompiler.py View on Github external
def test_some_float_invalid_1():
    ffi = FFI()
    py.test.raises((FFIError,      # with pycparser <= 2.17
                    CDefError),    # with pycparser >= 2.18
                   ffi.cdef, "typedef long double... foo_t;")
github mozillazg / pypy / extra_tests / cffi_tests / cffi1 / test_recompiler.py View on Github external
def test_some_float_invalid_1():
    ffi = FFI()
    py.test.raises((FFIError,      # with pycparser <= 2.17
                    CDefError),    # with pycparser >= 2.18
                   ffi.cdef, "typedef long double... foo_t;")
github holzschu / python3_ios / extraPackages / cffi-1.11.5 / testing / cffi1 / test_verify1.py View on Github external
def test_implicit_unicode_on_windows():
    from cffi import FFIError
    if sys.platform != 'win32':
        py.test.skip("win32-only test")
    ffi = FFI()
    e = py.test.raises(FFIError, ffi.cdef, "int foo(LPTSTR);")
    assert str(e.value) == ("The Windows type 'LPTSTR' is only available after"
                            " you call ffi.set_unicode()")
    for with_unicode in [True, False]:
        ffi = FFI()
        ffi.set_unicode(with_unicode)
        ffi.cdef("""
            DWORD GetModuleFileName(HMODULE hModule, LPTSTR lpFilename,
                                    DWORD nSize);
        """)
        lib = ffi.verify("""
            #include 
        """, libraries=['Kernel32'])
        outbuf = ffi.new("TCHAR[]", 200)
        n = lib.GetModuleFileName(ffi.NULL, outbuf, 500)
        assert 0 < n < 500
        for i in range(n):
github JarryShaw / f2format / vendor / pypy / extra_tests / cffi_tests / cffi1 / test_recompiler.py View on Github external
def test_some_float_invalid_1():
    ffi = FFI()
    py.test.raises((FFIError,      # with pycparser <= 2.17
                    CDefError),    # with pycparser >= 2.18
                   ffi.cdef, "typedef long double... foo_t;")
github OpenBXI / bxibase / packaged / lib / bxi / ffi.py View on Github external
"""

import cffi
import cffi.api

__FFI__ = cffi.FFI()


# C helper functions
try:
    __FFI__.cdef('''FILE *fmemopen(void *, size_t, const char*);
                 int fclose(FILE*);
                 void free(void *ptr);
                 ''')
except cffi.FFIError:
    # only once is needed
    pass


def add_cdef_for_type(ctype, cdef, packed=False):
    '''
    Define the given cdef, only if given ctype isn't defined yet.

    Warning: this doesn't work for function ctype !

    @return None
    '''
    try:
        __FFI__.getctype(ctype)
    except cffi.api.CDefError:
        __FFI__.cdef(cdef, packed)