[pypy-commit] pypy py3.5: Use correct struct definitions for modules
rlamy
pypy.commits at gmail.com
Wed Mar 15 10:25:51 EDT 2017
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5
Changeset: r90705:4838a4613d1c
Date: 2017-03-15 14:25 +0000
http://bitbucket.org/pypy/pypy/changeset/4838a4613d1c/
Log: Use correct struct definitions for modules
diff --git a/pypy/module/cpyext/include/moduleobject.h b/pypy/module/cpyext/include/moduleobject.h
--- a/pypy/module/cpyext/include/moduleobject.h
+++ b/pypy/module/cpyext/include/moduleobject.h
@@ -6,31 +6,7 @@
extern "C" {
#endif
-typedef struct PyModuleDef_Base {
- PyObject_HEAD
- PyObject* (*m_init)(void);
- Py_ssize_t m_index;
- PyObject* m_copy;
-} PyModuleDef_Base;
-
-#define PyModuleDef_HEAD_INIT { \
- PyObject_HEAD_INIT(NULL) \
- NULL, /* m_init */ \
- 0, /* m_index */ \
- NULL, /* m_copy */ \
- }
-
-typedef struct PyModuleDef{
- PyModuleDef_Base m_base;
- const char* m_name;
- const char* m_doc;
- Py_ssize_t m_size;
- PyMethodDef *m_methods;
- inquiry m_reload;
- traverseproc m_traverse;
- inquiry m_clear;
- freefunc m_free;
-}PyModuleDef;
+#include "cpyext_moduleobject.h"
#ifdef __cplusplus
}
diff --git a/pypy/module/cpyext/modsupport.py b/pypy/module/cpyext/modsupport.py
--- a/pypy/module/cpyext/modsupport.py
+++ b/pypy/module/cpyext/modsupport.py
@@ -1,6 +1,7 @@
from rpython.rtyper.lltypesystem import rffi, lltype
-from pypy.module.cpyext.api import cpython_api, cpython_struct, \
- METH_STATIC, METH_CLASS, METH_COEXIST, CANNOT_FAIL, CONST_STRING
+from pypy.module.cpyext.api import (
+ cpython_api, METH_STATIC, METH_CLASS, METH_COEXIST, CANNOT_FAIL, cts,
+ parse_dir)
from pypy.module.cpyext.pyobject import PyObject, as_pyobj
from pypy.interpreter.module import Module
from pypy.module.cpyext.methodobject import (
@@ -10,18 +11,8 @@
from pypy.module.cpyext.state import State
from pypy.interpreter.error import oefmt
-PyModuleDef_BaseStruct = cpython_struct(
- 'PyModuleDef_Base',
- [])
-
-PyModuleDefStruct = cpython_struct(
- 'PyModuleDef',
- [('m_base', PyModuleDef_BaseStruct),
- ('m_name', rffi.CCHARP),
- ('m_doc', rffi.CCHARP),
- ('m_methods', lltype.Ptr(PyMethodDef)),
- ], level=2)
-PyModuleDef = lltype.Ptr(PyModuleDefStruct)
+cts.parse_header(parse_dir / 'cpyext_moduleobject.h')
+PyModuleDef = cts.gettype('PyModuleDef *')
@cpython_api([PyModuleDef, rffi.INT_real], PyObject)
def PyModule_Create2(space, module, api_version):
diff --git a/pypy/module/cpyext/parse/cpyext_moduleobject.h b/pypy/module/cpyext/parse/cpyext_moduleobject.h
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/parse/cpyext_moduleobject.h
@@ -0,0 +1,38 @@
+typedef struct PyModuleDef_Base {
+ PyObject_HEAD
+ PyObject* (*m_init)(void);
+ Py_ssize_t m_index;
+ PyObject* m_copy;
+} PyModuleDef_Base;
+
+#define PyModuleDef_HEAD_INIT { \
+ PyObject_HEAD_INIT(NULL) \
+ NULL, /* m_init */ \
+ 0, /* m_index */ \
+ NULL, /* m_copy */ \
+ }
+
+struct PyModuleDef_Slot;
+/* New in 3.5 */
+typedef struct PyModuleDef_Slot{
+ int slot;
+ void *value;
+} PyModuleDef_Slot;
+
+#define Py_mod_create 1
+#define Py_mod_exec 2
+
+#define _Py_mod_LAST_SLOT 2
+
+
+typedef struct PyModuleDef{
+ PyModuleDef_Base m_base;
+ const char* m_name;
+ const char* m_doc;
+ Py_ssize_t m_size;
+ PyMethodDef *m_methods;
+ struct PyModuleDef_Slot* m_slots;
+ traverseproc m_traverse;
+ inquiry m_clear;
+ freefunc m_free;
+} PyModuleDef;
More information about the pypy-commit
mailing list