Skip to content
Snippets Groups Projects
Commit 7a4765db authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

tests: Add testcase for ffi callbacks.

parent b62371e8
Branches
No related tags found
No related merge requests found
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)
org string: bytearray(b'foobar')
qsort'ed: bytearray(b'abfoor')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment