Author: Armin Rigo <ar...@tunes.org>
Branch: cffi-1.0
Changeset: r1857:107bf9987254
Date: 2015-04-27 18:34 +0200
http://bitbucket.org/cffi/cffi/changeset/107bf9987254/

Log:    Move the "size" field to the end of the structure and use 0 to mean
        "unknown"

diff --git a/_cffi1/lib_obj.c b/_cffi1/lib_obj.c
--- a/_cffi1/lib_obj.c
+++ b/_cffi1/lib_obj.c
@@ -197,8 +197,7 @@
                             _CFFI_GETARG(g->type_op));
         if (ct == NULL)
             return NULL;
-        if (g->size != ct->ct_size &&
-                g->size != (size_t)-1 && ct->ct_size != -1) {
+        if (g->size != ct->ct_size && g->size != 0 && ct->ct_size > 0) {
             PyErr_Format(FFIError,
                          "global variable '%.200s' should be %zd bytes "
                          "according to the cdef, but is actually %zd",
diff --git a/_cffi1/parse_c_type.h b/_cffi1/parse_c_type.h
--- a/_cffi1/parse_c_type.h
+++ b/_cffi1/parse_c_type.h
@@ -63,8 +63,8 @@
 struct _cffi_global_s {
     const char *name;
     void *address;
-    size_t size;             // -1 if unknown
     _cffi_opcode_t type_op;
+    size_t size;             // 0 if unknown
 };
 
 struct _cffi_struct_union_s {
diff --git a/_cffi1/recompiler.py b/_cffi1/recompiler.py
--- a/_cffi1/recompiler.py
+++ b/_cffi1/recompiler.py
@@ -418,8 +418,7 @@
         else:
             meth_kind = 'V'   # 'METH_VARARGS'
         self._lsts["global"].append(
-            '  { "%s", _cffi_f_%s, (size_t)-1, '
-            '_CFFI_OP(_CFFI_OP_CPYTHON_BLTN_%s, %d) },'
+            '  { "%s", _cffi_f_%s, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_%s, %d), 0 
},'
             % (name, name, meth_kind, type_index))
 
     # ----------
@@ -632,8 +631,7 @@
             type_index = self._typesdict[tp]
             type_op = '_CFFI_OP(_CFFI_OP_CONSTANT, %d)' % type_index
         self._lsts["global"].append(
-            '  { "%s", _cffi_const_%s, (size_t)-1, %s },' % 
-            (name, name, type_op))
+            '  { "%s", _cffi_const_%s, %s, 0 },' % (name, name, type_op))
 
     # ----------
     # enums
@@ -650,7 +648,7 @@
         type_op = '_CFFI_OP(_CFFI_OP_ENUM, -1)'
         for enumerator in tp.enumerators:
             self._lsts["global"].append(
-                '  { "%s", _cffi_const_%s, (size_t)-1, %s },' %
+                '  { "%s", _cffi_const_%s, %s, 0 },' %
                 (enumerator, enumerator, type_op))
         #
         if cname is not None and '$' not in cname:
@@ -681,9 +679,8 @@
 
     def _generate_cpy_macro_ctx(self, tp, name):
         self._lsts["global"].append(
-            '  { "%s", _cffi_const_%s, (size_t)-1,'
-            ' _CFFI_OP(_CFFI_OP_CONSTANT_INT, 0) },' %
-            (name, name))
+            '  { "%s", _cffi_const_%s,'
+            ' _CFFI_OP(_CFFI_OP_CONSTANT_INT, 0), 0 },' % (name, name))
 
     # ----------
     # global variables
@@ -706,10 +703,10 @@
         if tp.sizeof_enabled():
             size = "sizeof(%s)" % (name,)
         else:
-            size = "(size_t)-1"
+            size = "0"
         self._lsts["global"].append(
-            '  { "%s", &%s, %s, _CFFI_OP(_CFFI_OP_GLOBAL_VAR, %d)},'
-            % (name, name, size, type_index))
+            '  { "%s", &%s, _CFFI_OP(_CFFI_OP_GLOBAL_VAR, %d), %s },'
+            % (name, name, type_index, size))
 
     # ----------
     # emitting the opcodes for individual types
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to