[pypy-commit] creflect default: ffi.NULL

arigo noreply at buildbot.pypy.org
Fri Dec 5 16:56:00 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r165:64bdd79c09b5
Date: 2014-12-05 16:47 +0100
http://bitbucket.org/cffi/creflect/changeset/64bdd79c09b5/

Log:	ffi.NULL

diff --git a/zeffir/builder.c b/zeffir/builder.c
--- a/zeffir/builder.c
+++ b/zeffir/builder.c
@@ -6,7 +6,6 @@
     _crx_builder_t cb;
     ZefLibObject *lib;
     PyObject *l_dict;
-    ZefFFIObject *ffi;
     PyObject *types_dict;
 } zeffir_builder_t;
 
@@ -837,7 +836,6 @@
         },
         lib,              /* lib */
         lib->l_dict,      /* l_dict */
-        ffi,              /* ffi */
         ffi->types_dict,  /* types_dict */
     };
     crxmain(&builder.cb);
@@ -845,7 +843,7 @@
     return PyErr_Occurred() ? -1 : 0;
 }
 
-static CTypeDescrObject *parse_c_decl(ZefFFIObject *ffi, const char *str)
+static CTypeDescrObject *parse_c_decl(PyObject *types_dict, const char *str)
 {
     zeffir_builder_t builder = {
         {
@@ -875,8 +873,7 @@
         },
         NULL,             /* lib */
         NULL,             /* l_dict */
-        ffi,              /* ffi */
-        ffi->types_dict,  /* types_dict */
+        types_dict,       /* types_dict */
     };
 
     _crx_qual_type result;
diff --git a/zeffir/ffi_obj.c b/zeffir/ffi_obj.c
--- a/zeffir/ffi_obj.c
+++ b/zeffir/ffi_obj.c
@@ -126,7 +126,8 @@
         if (x != NULL && CTypeDescr_Check(x))
             return (CTypeDescrObject *)x;
 
-        CTypeDescrObject *ct = parse_c_decl(ffi, PyText_AS_UTF8(arg));
+        CTypeDescrObject *ct = parse_c_decl(ffi->types_dict,
+                                            PyText_AS_UTF8(arg));
         if (ct == NULL)
             return NULL;
 
diff --git a/zeffir/test/test_basic.py b/zeffir/test/test_basic.py
--- a/zeffir/test/test_basic.py
+++ b/zeffir/test/test_basic.py
@@ -31,3 +31,8 @@
 def test_types():
     ffi = support.new_ffi()
     assert ffi.types == {}
+
+def test_NULL():
+    ffi = support.new_ffi()
+    assert repr(ffi.NULL) == "<cdata 'void *' NULL>"
+    assert repr(type(ffi).NULL) == "<cdata 'void *' NULL>"
diff --git a/zeffir/test/test_struct.py b/zeffir/test/test_struct.py
--- a/zeffir/test/test_struct.py
+++ b/zeffir/test/test_struct.py
@@ -1,3 +1,4 @@
+import py
 import support
 
 
@@ -8,3 +9,9 @@
     assert p.b == 0x600112233
     p.b += 1
     assert p.b == 0x600112234
+
+def test_addressof():
+    py.test.skip("in-progress")
+    ffi, lib = support.compile_and_open('struct')
+    p = ffi.new('mystruct_t *')
+    ffi.addressof(p[0], 'a')
diff --git a/zeffir/zeffir.c b/zeffir/zeffir.c
--- a/zeffir/zeffir.c
+++ b/zeffir/zeffir.c
@@ -70,6 +70,24 @@
     if (PyModule_AddObject(m, "error", ZefError) < 0)
         return;
 
+    {
+        CTypeDescrObject *ctvoidp;
+        PyObject *cdnull;
+        PyObject *d1 = PyDict_New();
+        if (d1 == NULL)
+            return;
+
+        ctvoidp = parse_c_decl(d1, "void*");
+        if (ctvoidp) {
+            cdnull = new_simple_cdata(NULL, ctvoidp);
+            if (cdnull)
+                PyDict_SetItemString(ZefFFI_Type.tp_dict, "NULL", cdnull);
+        }
+        Py_DECREF(d1);
+        if (PyErr_Occurred())
+            return;
+    }
+
     if (PyDict_SetItemString(ZefFFI_Type.tp_dict, "error", ZefError) < 0)
         return;
 }
diff --git a/zeffir/zeffir.h b/zeffir/zeffir.h
--- a/zeffir/zeffir.h
+++ b/zeffir/zeffir.h
@@ -15,7 +15,7 @@
 
 static int lib_close(ZefLibObject *);
 static int load_creflect_main(ZefFFIObject *, ZefLibObject *);
-static CTypeDescrObject *parse_c_decl(ZefFFIObject *ffi, const char *str);
+static CTypeDescrObject *parse_c_decl(PyObject *types_dict, const char *str);
 
 static int convert_from_object(char *, CTypeDescrObject *, PyObject *);
 static int convert_from_object_bitfield(char *, CFieldObject *, PyObject *);


More information about the pypy-commit mailing list