[pypy-commit] pypy hpy-ctypespace: move more types into cts
antocuni
pypy.commits at gmail.com
Fri Nov 22 11:26:40 EST 2019
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: hpy-ctypespace
Changeset: r98139:86cbe337bc16
Date: 2019-11-22 11:21 +0100
http://bitbucket.org/pypy/pypy/changeset/86cbe337bc16/
Log: move more types into cts
diff --git a/pypy/module/hpy_universal/interp_extfunc.py b/pypy/module/hpy_universal/interp_extfunc.py
--- a/pypy/module/hpy_universal/interp_extfunc.py
+++ b/pypy/module/hpy_universal/interp_extfunc.py
@@ -19,10 +19,9 @@
# fetch the real HPy function pointer, by calling ml_meth, which
# is a function that returns it and also the CPython-only trampoline
with lltype.scoped_alloc(
- rffi.CArray(llapi._HPyCFunctionPtr), 1) as funcptr:
+ rffi.CArray(llapi._HPyCFunction), 1) as funcptr:
with lltype.scoped_alloc(
- rffi.CArray(llapi._HPy_CPyCFunctionPtr), 1) \
- as ignored_trampoline:
+ rffi.CArray(llapi._HPyCPyCFunction), 1) as ignored_trampoline:
ml.c_ml_meth(funcptr, ignored_trampoline)
self.cfuncptr = funcptr[0]
diff --git a/pypy/module/hpy_universal/llapi.py b/pypy/module/hpy_universal/llapi.py
--- a/pypy/module/hpy_universal/llapi.py
+++ b/pypy/module/hpy_universal/llapi.py
@@ -70,6 +70,29 @@
typedef struct _HPyContext_s *HPyContext;
typedef HPy (*HPyInitFunc)(HPyContext ctx);
+
+typedef HPy (*_HPyCFunction)(HPyContext ctx, HPy self, HPy args);
+typedef void *_HPyCPyCFunction; // not used here
+typedef void (*_HPyMethodPairFunc)(_HPyCFunction *out_func,
+ _HPyCPyCFunction *out_trampoline);
+
+
+typedef struct {
+ const char *ml_name;
+ _HPyMethodPairFunc ml_meth;
+ int ml_flags;
+ const char *ml_doc;
+} HPyMethodDef;
+
+typedef struct {
+ void *dummy; // this is needed because we put a comma after HPyModuleDef_HEAD_INIT :(
+ const char* m_name;
+ const char* m_doc;
+ HPy_ssize_t m_size;
+ HPyMethodDef *m_methods;
+} HPyModuleDef;
+
+
""")
HPy_ssize_t = cts.gettype('HPy_ssize_t')
@@ -84,37 +107,19 @@
HPy = cts.gettype('HPy')
_HPy_real = cts.gettype('_HPy_real')
-
HPyInitFunc = cts.gettype('HPyInitFunc')
-
-_HPyCFunctionPtr = lltype.Ptr(lltype.FuncType([HPyContext, HPy, HPy], HPy))
-_HPy_CPyCFunctionPtr = rffi.VOIDP # not used here
+_HPyCFunction = cts.gettype('_HPyCFunction')
+_HPyCPyCFunction = cts.gettype('_HPyCPyCFunction')
HPyMeth_VarArgs = lltype.Ptr(
lltype.FuncType([HPyContext, HPy, lltype.Ptr(rffi.CArray(HPy)), HPy_ssize_t], HPy))
-
-_HPyMethodPairFuncPtr = lltype.Ptr(lltype.FuncType([
- rffi.CArrayPtr(_HPyCFunctionPtr),
- rffi.CArrayPtr(_HPy_CPyCFunctionPtr)],
- lltype.Void))
-
-HPyMethodDef = rffi.CStruct('HPyMethodDef',
- ('ml_name', rffi.CCHARP),
- ('ml_meth', _HPyMethodPairFuncPtr),
- ('ml_flags', rffi.INT_real),
- ('ml_doc', rffi.CCHARP),
- hints={'eci': eci, 'typedef': True},
-)
-
-HPyModuleDef = rffi.CStruct('HPyModuleDef',
- ('dummy', rffi.VOIDP),
- ('m_name', rffi.CCHARP),
- ('m_doc', rffi.CCHARP),
- ('m_size', lltype.Signed),
- ('m_methods', rffi.CArrayPtr(HPyMethodDef)),
- hints={'eci': eci, 'typedef': True},
-)
+HPyMethodDef = cts.gettype('HPyMethodDef')
+HPyModuleDef = cts.gettype('HPyModuleDef')
+# CTypeSpace converts "HPyMethodDef*" into lltype.Ptr(HPyMethodDef), but we
+# want a CArrayPtr instead, so that we can index the items inside
+# HPyModule_Create
+HPyModuleDef._flds['c_m_methods'] = rffi.CArrayPtr(HPyMethodDef)
METH_VARARGS = 0x0001
METH_KEYWORDS = 0x0002
More information about the pypy-commit
mailing list