summaryrefslogtreecommitdiff
path: root/examples/unix/ffi_example.py
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2018-02-27 22:03:52 -0500
committerGitHub <noreply@github.com>2018-02-27 22:03:52 -0500
commit568c04e6afa8016062f685b2198c0209f62827f4 (patch)
treed07b76119f715add462983b335797adf64b61249 /examples/unix/ffi_example.py
parent6a2379fd0bfe10017d8abc5c36ef1d470c0d9b27 (diff)
parentea633117d01d94e8d56ed94344e4b3e46b4eef03 (diff)
Merge pull request #650 from tannewt/merge_2x3.0.0-alpha.2
Merge in commits from 2.x branch.
Diffstat (limited to 'examples/unix/ffi_example.py')
-rw-r--r--examples/unix/ffi_example.py38
1 files changed, 0 insertions, 38 deletions
diff --git a/examples/unix/ffi_example.py b/examples/unix/ffi_example.py
deleted file mode 100644
index f650e3370..000000000
--- a/examples/unix/ffi_example.py
+++ /dev/null
@@ -1,38 +0,0 @@
-import ffi
-
-libc = ffi.open("libc.so.6")
-print("libc:", libc)
-print()
-
-# Declare few functions
-perror = libc.func("v", "perror", "s")
-time = libc.func("i", "time", "p")
-open = libc.func("i", "open", "si")
-qsort = libc.func("v", "qsort", "piip")
-# And one variable
-errno = libc.var("i", "errno")
-
-print("time:", time)
-print("UNIX time is:", time(None))
-print()
-
-perror("ffi before error")
-open("somethingnonexistent__", 0)
-print("errno object:", errno)
-print("errno value:", errno.get())
-perror("ffi after error")
-print()
-
-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")
-print("callback:", cmp_c)
-
-s = bytearray(b"foobar")
-print("org string:", s)
-qsort(s, len(s), 1, cmp_c)
-print("qsort'ed string:", s)