Commits

Armin Rigo committed 65a7b25

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

  • Participants
  • Parent commits 8deb16b

Comments (0)

Files changed (1)

c/_cffi_backend.c

         return NULL;
     }
 
-    maxsize = 1;
+    maxsize = 0;
     alignment = 1;
     offset = 0;
     nb_fields = PyList_GET_SIZE(fields);
         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 "