Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r624:65a7b2518219
Date: 2012-07-11 09:49 +0200
http://bitbucket.org/cffi/cffi/changeset/65a7b2518219/

Log:    ctypes support: structs or unions of size manually forced to 0.

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -2710,7 +2710,7 @@
         return NULL;
     }
 
-    maxsize = 1;
+    maxsize = 0;
     alignment = 1;
     offset = 0;
     nb_fields = PyList_GET_SIZE(fields);
@@ -2839,12 +2839,14 @@
         offset = maxsize;
     }
     else {
-        if (offset == 0)
-            offset = 1;
         offset = (offset + alignment - 1) & ~(alignment-1);
     }
-    if (totalsize < 0)
-        totalsize = offset;
+    /* Like C, if the size of this structure would be zero, we compute it
+       as 1 instead.  But for ctypes support, we allow the manually-
+       specified totalsize to be zero in this case. */
+    if (totalsize < 0) {
+        totalsize = (offset == 0 ? 1 : offset);
+    }
     else if (totalsize < offset) {
         PyErr_Format(PyExc_TypeError,
                      "%s cannot be of size %zd: there are fields at least "
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to