diff options
| author | Armin Rigo <arigo@tunes.org> | 2015-05-16 14:26:06 +0200 |
|---|---|---|
| committer | Armin Rigo <arigo@tunes.org> | 2015-05-16 14:26:06 +0200 |
| commit | 9dc5326eee9f2807473d03932b8d81a9d2b2fa7e (patch) | |
| tree | d68509059fe6574c10db3515cfce11705557d6ee /testing/cffi1/test_re_python.py | |
| parent | b1d9274f92a9dfada58e87545ec4e7254042e892 (diff) | |
| download | cffi-9dc5326eee9f2807473d03932b8d81a9d2b2fa7e.tar.gz | |
ffi.dlclose(). Global variables.
Diffstat (limited to 'testing/cffi1/test_re_python.py')
| -rw-r--r-- | testing/cffi1/test_re_python.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/testing/cffi1/test_re_python.py b/testing/cffi1/test_re_python.py index 64aaeb1..06b224a 100644 --- a/testing/cffi1/test_re_python.py +++ b/testing/cffi1/test_re_python.py @@ -12,6 +12,7 @@ def setup_module(mod): #define BIGPOS 420000000000L #define BIGNEG -420000000000L int add42(int x) { return x + 42; } + int globalvar42 = 1234; struct foo_s; typedef struct bar_s { int x; signed char a[]; } bar_t; enum foo_e { AA, BB, CC }; @@ -32,6 +33,7 @@ def setup_module(mod): #define BIGPOS 420000000000L #define BIGNEG -420000000000L int add42(int); + int globalvar42; struct foo_s; typedef struct bar_s { int x; signed char a[]; } bar_t; enum foo_e { AA, BB, CC }; @@ -54,9 +56,21 @@ def test_large_constant(): assert ffi.integer_const('BIGNEG') == -420000000000 def test_function(): + import _cffi_backend from re_python_pysrc import ffi lib = ffi.dlopen(extmod) assert lib.add42(-10) == 32 + assert type(lib.add42) is _cffi_backend.FFI.CData + +def test_dlclose(): + import _cffi_backend + from re_python_pysrc import ffi + lib = ffi.dlopen(extmod) + ffi.dlclose(lib) + e = py.test.raises(ffi.error, ffi.dlclose, lib) + assert str(e.value) == ( + "library '%s' is already closed or was not created with ffi.dlopen()" + % (extmod,)) def test_constant_via_lib(): from re_python_pysrc import ffi @@ -103,3 +117,13 @@ def test_include_1(): # p = ffi.new("bar_t *", [5, "foobar"]) assert p.a[4] == ord('a') + +def test_global_var(): + from re_python_pysrc import ffi + lib = ffi.dlopen(extmod) + assert lib.globalvar42 == 1234 + p = ffi.addressof(lib, 'globalvar42') + lib.globalvar42 += 5 + assert p[0] == 1239 + p[0] -= 1 + assert lib.globalvar42 == 1238 |
