diff options
author | mattip <matti.picus@gmail.com> | 2015-11-24 21:50:04 +0200 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2015-11-24 21:50:04 +0200 |
commit | 68840c846ca7ffff6a99ae9b5d3f156c8623a373 (patch) | |
tree | cb275e08d6357d4a28e3a29b3f6a5a239247a0bd /demo/pwuid.py | |
parent | 5043f478b1ff4b3a1d03d0b9869ea32fbb4c61c5 (diff) | |
download | cffi-68840c846ca7ffff6a99ae9b5d3f156c8623a373.tar.gz |
update and cleanup more demos
Diffstat (limited to 'demo/pwuid.py')
-rw-r--r-- | demo/pwuid.py | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/demo/pwuid.py b/demo/pwuid.py index c4d7201..650b9da 100644 --- a/demo/pwuid.py +++ b/demo/pwuid.py @@ -1,14 +1,18 @@ -from cffi import FFI -ffi = FFI() -ffi.cdef(""" // some declarations from the man page - struct passwd { - char *pw_name; - ...; - }; - struct passwd *getpwuid(int uid); -""") -C = ffi.verify(""" // passed to the real C compiler -#include <sys/types.h> -#include <pwd.h> -""") -print ffi.string(C.getpwuid(0).pw_name) +import sys, os + +# If the build script was run immediately before this script, the cffi module +# ends up in the current directory. Make sure we can import it. +sys.path.append('.') + +try: + from _pwuid import ffi, lib +except ImportError: + print 'run pwuid_build first, then make sure the shared object is on sys.path' + sys.exit(-1) + +# ffi "knows" about the declared variables and functions from the +# cdef parts of the module xclient_build created, +# lib "knows" how to call the functions from the set_source parts +# of the module. + +print ffi.string(lib.getpwuid(0).pw_name) |