Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: rffi-parser
Changeset: r89124:3ef445c0db43
Date: 2016-12-17 18:58 +0000
http://bitbucket.org/pypy/pypy/changeset/3ef445c0db43/

Log:    Handle function pointers and void

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -621,6 +621,8 @@
 } PyVarObject;
 
 typedef struct _typeobject PyTypeObject;
+
+typedef void (*freefunc)(void *);
 """)
 h.configure_types()
 
diff --git a/pypy/module/cpyext/cparser.py b/pypy/module/cpyext/cparser.py
--- a/pypy/module/cpyext/cparser.py
+++ b/pypy/module/cpyext/cparser.py
@@ -726,7 +726,18 @@
             self.structs[obj] = result
             return result
         elif isinstance(obj, model.PointerType):
-            return lltype.Ptr(self.convert_type(obj.totype))
+            TO = self.convert_type(obj.totype)
+            if TO is lltype.Void:
+                return rffi.VOIDP
+            return lltype.Ptr(TO)
+        elif isinstance(obj, model.FunctionPtrType):
+            if obj.ellipsis:
+                raise NotImplementedError
+            args = [self.convert_type(arg) for arg in obj.args]
+            res = self.convert_type(obj.result)
+            return lltype.Ptr(lltype.FuncType(args, res))
+        elif isinstance(obj, model.VoidType):
+            return lltype.Void
         else:
             raise NotImplementedError
 
diff --git a/pypy/module/cpyext/typeobjectdefs.py 
b/pypy/module/cpyext/typeobjectdefs.py
--- a/pypy/module/cpyext/typeobjectdefs.py
+++ b/pypy/module/cpyext/typeobjectdefs.py
@@ -5,13 +5,15 @@
     Py_TPFLAGS_READYING, Py_TPFLAGS_READY, Py_TPFLAGS_HEAPTYPE)
 from pypy.module.cpyext.pyobject import PyObject, make_ref, from_ref
 from pypy.module.cpyext.modsupport import PyMethodDef
-from pypy.module.cpyext.api import Py_bufferP
+from pypy.module.cpyext.api import Py_bufferP, h
 
 
 P, FT, PyO = Ptr, FuncType, PyObject
 PyOPtr = Ptr(lltype.Array(PyO, hints={'nolength': True}))
 
-freefunc = P(FT([rffi.VOIDP], Void))
+#freefunc = P(FT([rffi.VOIDP], Void))
+freefunc = h.definitions['freefunc']
+
 destructor = P(FT([PyO], Void))
 printfunc = P(FT([PyO, FILEP, rffi.INT_real], rffi.INT))
 getattrfunc = P(FT([PyO, rffi.CCHARP], PyO))
@@ -200,7 +202,7 @@
     ("tp_clear", inquiry),        #U
 
     # Assigned meaning in release 2.1
-    # rich comparisons 
+    # rich comparisons
     ("tp_richcompare", richcmpfunc), #N
 
     # weak reference enabler
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to