Author: Armin Rigo <[email protected]>
Branch: cffi-1.0
Changeset: r1829:60463383e5bc
Date: 2015-04-26 09:34 +0200
http://bitbucket.org/cffi/cffi/changeset/60463383e5bc/

Log:    test and fix

diff --git a/_cffi1/realize_c_type.c b/_cffi1/realize_c_type.c
--- a/_cffi1/realize_c_type.c
+++ b/_cffi1/realize_c_type.c
@@ -460,9 +460,13 @@
             }
 
             PyObject *args = NULL;
-            if (!PyErr_Occurred())
-                args = Py_BuildValue("(sOOO)", e->name, enumerators,
+            if (!PyErr_Occurred()) {
+                char *name = alloca(6 + strlen(e->name));
+                strcpy(name, "enum ");
+                strcat(name, e->name);
+                args = Py_BuildValue("(sOOO)", name, enumerators,
                                      enumvalues, basetd);
+            }
             Py_DECREF(enumerators);
             Py_DECREF(enumvalues);
             if (args == NULL)
diff --git a/_cffi1/test_recompiler.py b/_cffi1/test_recompiler.py
--- a/_cffi1/test_recompiler.py
+++ b/_cffi1/test_recompiler.py
@@ -282,6 +282,7 @@
     assert lib.B2 == 1
     assert ffi.sizeof("enum e1") == ffi.sizeof("long")
     assert ffi.sizeof("enum e2") == ffi.sizeof("int")
+    assert repr(ffi.cast("enum e1", 0)) == "<cdata 'enum e1' 0: A1>"
 
 def test_duplicate_enum():
     ffi = FFI()
@@ -348,6 +349,7 @@
            "typedef struct { long b; int hidden, a; } foo_t;")
     p = ffi.new("foo_t *", {'b': 42})
     assert p.b == 42
+    assert repr(p).startswith("<cdata 'struct $foo_t *' ")
 
 def test_verify_anonymous_struct_with_star_typedef():
     ffi = FFI()
@@ -364,6 +366,7 @@
                  "typedef enum { BB, CC, AA } e1;")
     assert lib.AA == 2
     assert ffi.sizeof("e1") == ffi.sizeof("int")
+    assert repr(ffi.cast("e1", 2)) == "<cdata 'enum $e1' 2: AA>"
     #
     ffi = FFI()
     ffi.cdef("typedef enum { AA=%d } e1;" % sys.maxint)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to