[pypy-commit] cffi default: Tests, and fix for enums.

arigo noreply at buildbot.pypy.org
Wed Jul 11 12:34:12 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r628:33c9c674e910
Date: 2012-07-11 12:33 +0200
http://bitbucket.org/cffi/cffi/changeset/33c9c674e910/

Log:	Tests, and fix for enums.

diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -174,6 +174,10 @@
             extraarg = ', _cffi_type(%d)' % self.gettypenum(tp)
             errvalue = 'NULL'
         #
+        elif isinstance(tp, model.EnumType):
+            converter = '_cffi_to_c_int'
+            errvalue = '-1'
+        #
         else:
             raise NotImplementedError(tp)
         #
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -638,3 +638,22 @@
             int compar(const void *, const void *));
     """)
     ffi.verify("#include <stdlib.h>")
+
+def test_array_as_argument():
+    ffi = FFI()
+    ffi.cdef("""
+        int strlen(char string[]);
+    """)
+    ffi.verify("#include <string.h>")
+
+def test_enum_as_argument():
+    ffi = FFI()
+    ffi.cdef("""
+        enum foo_e { AA, BB, ... };
+        int foo_func(enum foo_e);
+    """)
+    lib = ffi.verify("""
+        enum foo_e { AA, CC, BB };
+        int foo_func(enum foo_e e) { return e; }
+    """)
+    assert lib.foo_func(lib.BB) == 2


More information about the pypy-commit mailing list