[pypy-commit] cffi default: Add a third example using neither dlopen() nor verify().
arigo
noreply at buildbot.pypy.org
Thu Jun 14 18:49:20 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r347:37e97411d781
Date: 2012-06-14 18:49 +0200
http://bitbucket.org/cffi/cffi/changeset/37e97411d781/
Log: Add a third example using neither dlopen() nor verify().
diff --git a/README.md b/README.md
--- a/README.md
+++ b/README.md
@@ -45,8 +45,8 @@
hi there, world!
>>>
-Simple example (API level)
---------------------------
+Real example (API level)
+------------------------
from cffi import FFI
ffi = FFI()
@@ -64,8 +64,27 @@
assert str(C.getpwuid(0).pw_name) == 'root'
Note that the above example works independently of the exact layout of
-"struct passwd", but so far require a C compiler at runtime. (This will
-be improved with caching and distribution of the compiled code.)
+"struct passwd", but so far require a C compiler at runtime. (We plan
+to improve with caching and a way to distribute the compiled code.)
+
+Struct/Array Example
+--------------------
+
+ from cffi import FFI
+ ffi = FFI()
+ ffi.cdef("""
+ typedef struct {
+ unsigned char r, g, b;
+ } pixel_t;
+ """)
+ image = ffi.new("pixel_t[]", 800*600)
+ image[0].r = 255
+ image[0].g = 192
+ image[0].b = 128
+
+This can be used as a more flexible replacement of the struct_ and
+array_ modules. You could also call ``ffi.new("pixel_t[600][800]")``
+and get a two-dimensional array.
More documentation
More information about the pypy-commit
mailing list