diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-12-15 02:18:12 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-12-15 02:18:54 +0200 |
commit | 7a4765dbeb1176efc2679aeb66ce8b21a8e1fd08 (patch) | |
tree | 5e45ba46f3f50d0b83ae57e78b15e07c3a9aca72 /tests/unix/ffi_callback.py | |
parent | b62371e8fb0b3f8123920eb82270f42bab3ce657 (diff) |
tests: Add testcase for ffi callbacks.
Diffstat (limited to 'tests/unix/ffi_callback.py')
-rw-r--r-- | tests/unix/ffi_callback.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/unix/ffi_callback.py b/tests/unix/ffi_callback.py new file mode 100644 index 000000000..1d610365c --- /dev/null +++ b/tests/unix/ffi_callback.py @@ -0,0 +1,23 @@ +import sys +try: + import ffi +except ImportError: + print("SKIP") + sys.exit() + +libc = ffi.open("libc.so.6") + +qsort = libc.func("v", "qsort", "piip") + +def cmp(pa, pb): + a = ffi.as_bytearray(pa, 1) + b = ffi.as_bytearray(pb, 1) + #print("cmp:", a, b) + return a[0] - b[0] + +cmp_c = ffi.callback("i", cmp, "pp") + +s = bytearray(b"foobar") +print("org string:", s) +qsort(s, len(s), 1, cmp_c) +print("qsort'ed:", s) |