Example #1
0
def test_nonopaque_struct():
    from re_python_pysrc import ffi
    for p in [ffi.new("struct bar_s *", [5, b"foobar"]),
              ffi.new("bar_t *", [5, b"foobar"])]:
        assert p.x == 5
        assert p.a[0] == ord('f')
        assert p.a[5] == ord('r')
Example #2
0
 def test_include_1(self):
     from re_py_subsrc import ffi
     assert ffi.integer_const('FOOBAR') == -42
     assert ffi.integer_const('FOOBAZ') == -43
     assert ffi.integer_const('k2') == 121212
     lib = ffi.dlopen(self.extmod)     # <- a random unrelated library would be fine
     assert lib.FOOBAR == -42
     assert lib.FOOBAZ == -43
     assert lib.k2 == 121212
     #
     p = ffi.new("bar_t *", [5, b"foobar"])
     assert p.a[4] == ord('a')
Example #3
0
 def test_include_1(self):
     self.fix_path()
     from re_py_subsrc import ffi
     assert ffi.integer_const('FOOBAR') == -42
     assert ffi.integer_const('FOOBAZ') == -43
     assert ffi.integer_const('k2') == 121212
     lib = ffi.dlopen(self.extmod)     # <- a random unrelated library would be fine
     assert lib.FOOBAR == -42
     assert lib.FOOBAZ == -43
     assert lib.k2 == 121212
     #
     p = ffi.new("bar_t *", [5, b"foobar"])
     assert p.a[4] == ord('a')
Example #4
0
def test_anonymous_union_inside_struct():
    # based on issue #357
    from re_python_pysrc import ffi
    INT = ffi.sizeof("int")
    assert ffi.offsetof("struct with_union", "a") == 0
    assert ffi.offsetof("struct with_union", "b") == 0
    assert ffi.sizeof("struct with_union") == INT
    #
    assert ffi.offsetof("union with_struct", "a") == 0
    assert ffi.offsetof("union with_struct", "b") == INT
    assert ffi.sizeof("union with_struct") >= INT + 1
    #
    assert ffi.sizeof("struct with_struct_with_union") == INT
    p = ffi.new("struct with_struct_with_union *")
    assert p.cp.x == 0
    #
    FLOAT = ffi.sizeof("float")
    assert ffi.sizeof("struct NVGcolor") == FLOAT * 4
    assert ffi.offsetof("struct NVGcolor", "rgba") == 0
    assert ffi.offsetof("struct NVGcolor", "r") == 0
    assert ffi.offsetof("struct NVGcolor", "g") == FLOAT
    assert ffi.offsetof("struct NVGcolor", "b") == FLOAT * 2
    assert ffi.offsetof("struct NVGcolor", "a") == FLOAT * 3
Example #5
0
def test_include_1():
    sub_ffi = FFI()
    sub_ffi.cdef("static const int k2 = 121212;")
    sub_ffi.include(original_ffi)
    assert 'macro FOOBAR' in original_ffi._parser._declarations
    assert 'macro FOOBAZ' in original_ffi._parser._declarations
    sub_ffi.set_source('re_python_pysrc', None)
    sub_ffi.emit_python_code(str(tmpdir.join('_re_include_1.py')))
    #
    if sys.version_info[:2] >= (3, 3):
        import importlib
        importlib.invalidate_caches()  # issue 197 (but can't reproduce myself)
    #
    from _re_include_1 import ffi
    assert ffi.integer_const('FOOBAR') == -42
    assert ffi.integer_const('FOOBAZ') == -43
    assert ffi.integer_const('k2') == 121212
    lib = ffi.dlopen(extmod)     # <- a random unrelated library would be fine
    assert lib.FOOBAR == -42
    assert lib.FOOBAZ == -43
    assert lib.k2 == 121212
    #
    p = ffi.new("bar_t *", [5, b"foobar"])
    assert p.a[4] == ord('a')
Example #6
0
 def test_selfref(self):
     # based on cffi issue #429
     self.fix_path()
     from re_python_pysrc import ffi
     ffi.new("selfref_ptr_t")
Example #7
0
def test_selfref():
    # based on issue #429
    from re_python_pysrc import ffi
    ffi.new("selfref_ptr_t")