diff options
Diffstat (limited to 'examples/unix')
-rw-r--r-- | examples/unix/ffi_example.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/examples/unix/ffi_example.py b/examples/unix/ffi_example.py index bc3919d40a..f650e33708 100644 --- a/examples/unix/ffi_example.py +++ b/examples/unix/ffi_example.py @@ -5,9 +5,9 @@ print("libc:", libc) print() # Declare few functions -perror = libc.func("v", "perror", ["s"]) +perror = libc.func("v", "perror", "s") time = libc.func("i", "time", "p") -open = libc.func("i", "open", ["s", "i"]) +open = libc.func("i", "open", "si") qsort = libc.func("v", "qsort", "piip") # And one variable errno = libc.var("i", "errno") @@ -18,8 +18,8 @@ print() perror("ffi before error") open("somethingnonexistent__", 0) -print(errno) -print(errno.get()) +print("errno object:", errno) +print("errno value:", errno.get()) perror("ffi after error") print() @@ -32,8 +32,7 @@ def cmp(pa, pb): cmp_c = ffi.callback("i", cmp, "pp") print("callback:", cmp_c) -# TODO: violates Py semantics, pass bytearray -s = "foobar" +s = bytearray(b"foobar") print("org string:", s) qsort(s, len(s), 1, cmp_c) -print("qsort'ed:", s) +print("qsort'ed string:", s) |