[pypy-commit] cffi cffi-1.0: typenames

arigo noreply at buildbot.pypy.org
Mon May 11 19:31:56 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1978:6a5911a15fca
Date: 2015-05-11 19:32 +0200
http://bitbucket.org/cffi/cffi/changeset/6a5911a15fca/

Log:	typenames

diff --git a/_cffi1/cdlopen.c b/_cffi1/cdlopen.c
--- a/_cffi1/cdlopen.c
+++ b/_cffi1/cdlopen.c
@@ -305,6 +305,30 @@
         building = NULL;
     }
 
+    if (typenames != NULL) {
+        /* unpack a tuple of strings, each of which describes one typename_s
+           entry */
+        struct _cffi_typename_s *ntypenames;
+        Py_ssize_t i, n = PyTuple_GET_SIZE(typenames);
+
+        i = n * sizeof(struct _cffi_typename_s);
+        building = PyMem_Malloc(i);
+        if (building == NULL)
+            goto error;
+        memset(building, 0, i);
+        ntypenames = (struct _cffi_typename_s *)building;
+
+        for (i = 0; i < n; i++) {
+            char *t = PyString_AS_STRING(PyTuple_GET_ITEM(typenames, i));
+            /* 't' is a string describing the typename */
+            ntypenames[i].type_index = cdl_4bytes(t); t += 4;
+            ntypenames[i].name = t;
+        }
+        ffi->types_builder.ctx.typenames = ntypenames;
+        ffi->types_builder.ctx.num_typenames = n;
+        building = NULL;
+    }
+
     /* Above, we took directly some "char *" strings out of the strings,
        typically from somewhere inside tuples.  Keep them alive by
        incref'ing the whole input arguments. */
diff --git a/_cffi1/manual2.py b/_cffi1/manual2.py
--- a/_cffi1/manual2.py
+++ b/_cffi1/manual2.py
@@ -25,5 +25,6 @@
 print ffi.offsetof("struct point_s", "y")
 
 print ffi.cast("enum myenum_e", 2)
+print ffi.cast("myint_t", -2)
 
 del ffi, lib


More information about the pypy-commit mailing list