[pypy-commit] cffi default: Add this example from README.md.

arigo noreply at buildbot.pypy.org
Thu Jun 14 18:36:01 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r345:70864b447bcb
Date: 2012-06-14 18:35 +0200
http://bitbucket.org/cffi/cffi/changeset/70864b447bcb/

Log:	Add this example from README.md.

diff --git a/demo/pwuid.py b/demo/pwuid.py
new file mode 100644
--- /dev/null
+++ b/demo/pwuid.py
@@ -0,0 +1,14 @@
+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 str(C.getpwuid(0).pw_name)


More information about the pypy-commit mailing list