Author: Ronan Lamy <[email protected]>
Branch: rffi-parser-2
Changeset: r89509:7b3731d591e4
Date: 2016-12-18 03:40 +0000
http://bitbucket.org/pypy/pypy/changeset/7b3731d591e4/
Log: Add missing declarations needed by PyTypeObject
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
@@ -840,11 +840,47 @@
releasebufferproc bf_releasebuffer;
} PyBufferProcs;
+/* from descrobject.h */
+typedef PyObject *(*getter)(PyObject *, void *);
+typedef int (*setter)(PyObject *, PyObject *, void *);
+
+typedef struct PyGetSetDef {
+ char *name;
+ getter get;
+ setter set;
+ char *doc;
+ void *closure;
+} PyGetSetDef;
+
+/* from methodobject.h */
+typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
+typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
+ PyObject *);
+typedef PyObject *(*PyNoArgsFunction)(PyObject *);
+
+struct PyMethodDef {
+ const char *ml_name; /* The name of the built-in function/method */
+ PyCFunction ml_meth; /* The C function that implements it */
+ int ml_flags; /* Combination of METH_xxx flags, which mostly
+ describe the args expected by the C func */
+ const char *ml_doc; /* The __doc__ attribute, or NULL */
+};
+typedef struct PyMethodDef PyMethodDef;
+
+/* from structmember.h */
+typedef struct PyMemberDef {
+ /* Current version, use this */
+ char *name;
+ int type;
+ Py_ssize_t offset;
+ int flags;
+ char *doc;
+} PyMemberDef;
typedef struct _typeobject {
PyObject_VAR_HEAD
- const char *tp_name; /* For printing, in format "<module>.<name>" */
+ /* const */ char *tp_name; /* For printing, in format "<module>.<name>"
*/
Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
/* Methods to implement standard operations */
@@ -876,7 +912,7 @@
/* Flags to define presence of optional/expanded features */
long tp_flags;
- const char *tp_doc; /* Documentation string */
+ /*const*/ char *tp_doc; /* Documentation string */
/* Assigned meaning in release 2.0 */
/* call function for all accessible objects */
@@ -923,7 +959,7 @@
} PyTypeObject;
-""")
+""", configure_now=True)
Py_ssize_t = object_h.gettype('Py_ssize_t')
Py_ssize_tP = object_h.gettype('Py_ssize_t *')
diff --git a/pypy/module/cpyext/methodobject.py
b/pypy/module/cpyext/methodobject.py
--- a/pypy/module/cpyext/methodobject.py
+++ b/pypy/module/cpyext/methodobject.py
@@ -11,23 +11,15 @@
CONST_STRING, METH_CLASS, METH_COEXIST, METH_KEYWORDS, METH_NOARGS, METH_O,
METH_STATIC, METH_VARARGS, PyObject, PyObjectFields, bootstrap_function,
build_type_checkers, cpython_api, cpython_struct, generic_cpy_call,
- PyTypeObjectPtr, slot_function)
+ PyTypeObjectPtr, slot_function, object_h)
from pypy.module.cpyext.pyobject import (
Py_DecRef, from_ref, make_ref, as_pyobj, make_typedescr)
PyCFunction_typedef = rffi.COpaquePtr(typedef='PyCFunction')
-PyCFunction = lltype.Ptr(lltype.FuncType([PyObject, PyObject], PyObject))
-PyCFunctionKwArgs = lltype.Ptr(lltype.FuncType([PyObject, PyObject, PyObject],
- PyObject))
-PyMethodDef = cpython_struct(
- 'PyMethodDef',
- [('ml_name', rffi.CONST_CCHARP),
- ('ml_meth', PyCFunction_typedef),
- ('ml_flags', rffi.INT_real),
- ('ml_doc', rffi.CONST_CCHARP),
- ])
-
+PyMethodDef = object_h.gettype('PyMethodDef')
+PyCFunction = object_h.gettype('PyCFunction')
+PyCFunctionKwArgs = object_h.gettype('PyCFunctionWithKeywords')
PyCFunctionObjectStruct = cpython_struct(
'PyCFunctionObject',
PyObjectFields + (
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
@@ -50,7 +50,7 @@
cache. CPython includes some extra checking here to make sure the module
being initialized lines up with what's expected, but we don't.
"""
- from pypy.module.cpyext.typeobjectdefs import PyTypeObjectPtr
+ from pypy.module.cpyext.api import PyTypeObjectPtr
modname = rffi.charp2str(name)
state = space.fromcache(State)
f_name, f_path = state.package_context
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -7,9 +7,9 @@
from rpython.rlib import rgc # Force registration of gc.collect
from pypy.module.cpyext.api import (
slot_function, generic_cpy_call, PyObject, Py_ssize_t,
Py_TPFLAGS_CHECKTYPES,
- pypy_decl, Py_buffer, Py_bufferP)
+ pypy_decl, Py_buffer, Py_bufferP, PyTypeObjectPtr)
from pypy.module.cpyext.typeobjectdefs import (
- unaryfunc, ternaryfunc, PyTypeObjectPtr, binaryfunc,
+ unaryfunc, ternaryfunc, binaryfunc,
getattrfunc, getattrofunc, setattrofunc, lenfunc, ssizeargfunc, inquiry,
ssizessizeargfunc, ssizeobjargproc, iternextfunc, initproc, richcmpfunc,
cmpfunc, hashfunc, descrgetfunc, descrsetfunc, objobjproc, objobjargproc,
diff --git a/pypy/module/cpyext/test/test_bytesobject.py
b/pypy/module/cpyext/test/test_bytesobject.py
--- a/pypy/module/cpyext/test/test_bytesobject.py
+++ b/pypy/module/cpyext/test/test_bytesobject.py
@@ -5,7 +5,7 @@
from pypy.module.cpyext.bytesobject import new_empty_str, PyBytesObject
from pypy.module.cpyext.api import PyObjectP, PyObject, Py_ssize_tP,
generic_cpy_call
from pypy.module.cpyext.pyobject import Py_DecRef, from_ref, make_ref
-from pypy.module.cpyext.typeobjectdefs import PyTypeObjectPtr
+from pypy.module.cpyext.api import PyTypeObjectPtr
import py
import sys
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
@@ -1,237 +1,59 @@
-from rpython.rtyper.lltypesystem import rffi, lltype
-from rpython.rtyper.lltypesystem.lltype import Ptr, FuncType, Void
-from pypy.module.cpyext.api import (cpython_struct, Py_ssize_t, Py_ssize_tP,
- PyVarObjectFields, PyTypeObject, PyTypeObjectPtr, FILEP,
- 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, object_h
+from pypy.module.cpyext.api import object_h
-P, FT, PyO = Ptr, FuncType, PyObject
-PyOPtr = Ptr(lltype.Array(PyO, hints={'nolength': True}))
+freefunc = object_h.definitions['freefunc']
+destructor = object_h.definitions['destructor']
+printfunc = object_h.definitions['printfunc']
+getattrfunc = object_h.definitions['getattrfunc']
+getattrofunc = object_h.definitions['getattrofunc']
+setattrfunc = object_h.definitions['setattrfunc']
+setattrofunc = object_h.definitions['setattrofunc']
+cmpfunc = object_h.definitions['cmpfunc']
+reprfunc = object_h.definitions['reprfunc']
+hashfunc = object_h.definitions['hashfunc']
+richcmpfunc = object_h.definitions['richcmpfunc']
+getiterfunc = object_h.definitions['getiterfunc']
+iternextfunc = object_h.definitions['iternextfunc']
+descrgetfunc = object_h.definitions['descrgetfunc']
+descrsetfunc = object_h.definitions['descrsetfunc']
+initproc = object_h.definitions['initproc']
+newfunc = object_h.definitions['newfunc']
+allocfunc = object_h.definitions['allocfunc']
-#freefunc = P(FT([rffi.VOIDP], Void))
-freefunc = object_h.definitions['freefunc']
+unaryfunc = object_h.definitions['unaryfunc']
+binaryfunc = object_h.definitions['binaryfunc']
+ternaryfunc = object_h.definitions['ternaryfunc']
+inquiry = object_h.definitions['inquiry']
+lenfunc = object_h.definitions['lenfunc']
+coercion = object_h.definitions['coercion']
+intargfunc = object_h.definitions['intargfunc']
+intintargfunc = object_h.definitions['intintargfunc']
+ssizeargfunc = object_h.definitions['ssizeargfunc']
+ssizessizeargfunc = object_h.definitions['ssizessizeargfunc']
+intobjargproc = object_h.definitions['intobjargproc']
+intintobjargproc = object_h.definitions['intintobjargproc']
+ssizeobjargproc = object_h.definitions['ssizeobjargproc']
+ssizessizeobjargproc = object_h.definitions['ssizessizeobjargproc']
+objobjargproc = object_h.definitions['objobjargproc']
-destructor = P(FT([PyO], Void))
-printfunc = P(FT([PyO, FILEP, rffi.INT_real], rffi.INT))
-getattrfunc = P(FT([PyO, rffi.CCHARP], PyO))
-getattrofunc = P(FT([PyO, PyO], PyO))
-setattrfunc = P(FT([PyO, rffi.CCHARP, PyO], rffi.INT_real))
-setattrofunc = P(FT([PyO, PyO, PyO], rffi.INT_real))
-cmpfunc = P(FT([PyO, PyO], rffi.INT_real))
-reprfunc = P(FT([PyO], PyO))
-hashfunc = P(FT([PyO], lltype.Signed))
-richcmpfunc = P(FT([PyO, PyO, rffi.INT_real], PyO))
-getiterfunc = P(FT([PyO], PyO))
-iternextfunc = P(FT([PyO], PyO))
-descrgetfunc = P(FT([PyO, PyO, PyO], PyO))
-descrsetfunc = P(FT([PyO, PyO, PyO], rffi.INT_real))
-initproc = P(FT([PyO, PyO, PyO], rffi.INT_real))
-newfunc = P(FT([PyTypeObjectPtr, PyO, PyO], PyO))
-allocfunc = P(FT([PyTypeObjectPtr, Py_ssize_t], PyO))
+objobjproc = object_h.definitions['objobjproc']
+visitproc = object_h.definitions['visitproc']
+traverseproc = object_h.definitions['traverseproc']
-unaryfunc = P(FT([PyO], PyO))
-binaryfunc = P(FT([PyO, PyO], PyO))
-ternaryfunc = P(FT([PyO, PyO, PyO], PyO))
-inquiry = P(FT([PyO], rffi.INT_real))
-lenfunc = P(FT([PyO], Py_ssize_t))
-coercion = P(FT([PyOPtr, PyOPtr], rffi.INT_real))
-intargfunc = P(FT([PyO, rffi.INT_real], PyO))
-intintargfunc = P(FT([PyO, rffi.INT_real, rffi.INT], PyO))
-ssizeargfunc = P(FT([PyO, Py_ssize_t], PyO))
-ssizessizeargfunc = P(FT([PyO, Py_ssize_t, Py_ssize_t], PyO))
-intobjargproc = P(FT([PyO, rffi.INT_real, PyO], rffi.INT))
-intintobjargproc = P(FT([PyO, rffi.INT_real, rffi.INT, PyO], rffi.INT))
-ssizeobjargproc = P(FT([PyO, Py_ssize_t, PyO], rffi.INT_real))
-ssizessizeobjargproc = P(FT([PyO, Py_ssize_t, Py_ssize_t, PyO], rffi.INT_real))
-objobjargproc = P(FT([PyO, PyO, PyO], rffi.INT_real))
+getter = object_h.definitions['getter']
+setter = object_h.definitions['setter']
-objobjproc = P(FT([PyO, PyO], rffi.INT_real))
-visitproc = P(FT([PyO, rffi.VOIDP], rffi.INT_real))
-traverseproc = P(FT([PyO, visitproc, rffi.VOIDP], rffi.INT_real))
+readbufferproc = object_h.definitions['readbufferproc']
+writebufferproc = object_h.definitions['writebufferproc']
+segcountproc = object_h.definitions['segcountproc']
+charbufferproc = object_h.definitions['charbufferproc']
+getbufferproc = object_h.definitions['getbufferproc']
+releasebufferproc = object_h.definitions['releasebufferproc']
-getter = P(FT([PyO, rffi.VOIDP], PyO))
-setter = P(FT([PyO, PyO, rffi.VOIDP], rffi.INT_real))
-wrapperfunc = P(FT([PyO, PyO, rffi.VOIDP], PyO))
-wrapperfunc_kwds = P(FT([PyO, PyO, rffi.VOIDP, PyO], PyO))
-
-readbufferproc = P(FT([PyO, Py_ssize_t, rffi.VOIDPP], Py_ssize_t))
-writebufferproc = P(FT([PyO, Py_ssize_t, rffi.VOIDPP], Py_ssize_t))
-segcountproc = P(FT([PyO, Py_ssize_tP], Py_ssize_t))
-charbufferproc = P(FT([PyO, Py_ssize_t, rffi.CCHARPP], Py_ssize_t))
-getbufferproc = P(FT([PyO, Py_bufferP, rffi.INT_real], rffi.INT_real))
-releasebufferproc = P(FT([PyO, Py_bufferP], Void))
-
-
-PyGetSetDef = cpython_struct("PyGetSetDef", (
- ("name", rffi.CCHARP),
- ("get", getter),
- ("set", setter),
- ("doc", rffi.CCHARP),
- ("closure", rffi.VOIDP),
-))
-
-PyNumberMethods = cpython_struct("PyNumberMethods", (
- ("nb_add", binaryfunc),
- ("nb_subtract", binaryfunc),
- ("nb_multiply", binaryfunc),
- ("nb_divide", binaryfunc),
- ("nb_remainder", binaryfunc),
- ("nb_divmod", binaryfunc),
- ("nb_power", ternaryfunc),
- ("nb_negative", unaryfunc),
- ("nb_positive", unaryfunc),
- ("nb_absolute", unaryfunc),
- ("nb_nonzero", inquiry),
- ("nb_invert", unaryfunc),
- ("nb_lshift", binaryfunc),
- ("nb_rshift", binaryfunc),
- ("nb_and", binaryfunc),
- ("nb_xor", binaryfunc),
- ("nb_or", binaryfunc),
- ("nb_coerce", coercion),
- ("nb_int", unaryfunc),
- ("nb_long", unaryfunc),
- ("nb_float", unaryfunc),
- ("nb_oct", unaryfunc),
- ("nb_hex", unaryfunc),
- ("nb_inplace_add", binaryfunc),
- ("nb_inplace_subtract", binaryfunc),
- ("nb_inplace_multiply", binaryfunc),
- ("nb_inplace_divide", binaryfunc),
- ("nb_inplace_remainder", binaryfunc),
- ("nb_inplace_power", ternaryfunc),
- ("nb_inplace_lshift", binaryfunc),
- ("nb_inplace_rshift", binaryfunc),
- ("nb_inplace_and", binaryfunc),
- ("nb_inplace_xor", binaryfunc),
- ("nb_inplace_or", binaryfunc),
-
- ("nb_floor_divide", binaryfunc),
- ("nb_true_divide", binaryfunc),
- ("nb_inplace_floor_divide", binaryfunc),
- ("nb_inplace_true_divide", binaryfunc),
-
- ("nb_index", unaryfunc),
-))
-
-PySequenceMethods = cpython_struct("PySequenceMethods", (
- ("sq_length", lenfunc),
- ("sq_concat", binaryfunc),
- ("sq_repeat", ssizeargfunc),
- ("sq_item", ssizeargfunc),
- ("sq_slice", ssizessizeargfunc),
- ("sq_ass_item", ssizeobjargproc),
- ("sq_ass_slice", ssizessizeobjargproc),
- ("sq_contains", objobjproc),
- ("sq_inplace_concat", binaryfunc),
- ("sq_inplace_repeat", ssizeargfunc),
-))
-
-PyMappingMethods = cpython_struct("PyMappingMethods", (
- ("mp_length", lenfunc),
- ("mp_subscript", binaryfunc),
- ("mp_ass_subscript", objobjargproc),
-))
-
-PyBufferProcs = cpython_struct("PyBufferProcs", (
- ("bf_getreadbuffer", readbufferproc),
- ("bf_getwritebuffer", writebufferproc),
- ("bf_getsegcount", segcountproc),
- ("bf_getcharbuffer", charbufferproc),
- ("bf_getbuffer", getbufferproc),
- ("bf_releasebuffer", releasebufferproc),
-))
-
-PyMemberDef = cpython_struct("PyMemberDef", (
- ("name", rffi.CCHARP),
- ("type", rffi.INT_real),
- ("offset", Py_ssize_t),
- ("flags", rffi.INT_real),
- ("doc", rffi.CCHARP),
-))
-
-# These fields are supported and used in different ways
-# The following comments mean:
-# #E essential, initialized for all PTOs
-# #S supported
-# #U unsupported
-# #N not yet implemented
-PyTypeObjectFields = []
-PyTypeObjectFields.extend(PyVarObjectFields)
-PyTypeObjectFields.extend([
- ("tp_name", rffi.CCHARP), #E For printing, in format "<module>.<name>"
- ("tp_basicsize", Py_ssize_t), #E For allocation
- ("tp_itemsize", Py_ssize_t), #E "
-
- # Methods to implement standard operations
- ("tp_dealloc", destructor), #E
- ("tp_print", printfunc), #U
- ("tp_getattr", getattrfunc), #U
- ("tp_setattr", setattrfunc), #U
- ("tp_compare", cmpfunc), #N
- ("tp_repr", reprfunc), #N
-
- # Method suites for standard classes
- ("tp_as_number", Ptr(PyNumberMethods)), #N
- ("tp_as_sequence", Ptr(PySequenceMethods)), #N
- ("tp_as_mapping", Ptr(PyMappingMethods)), #N
-
- # More standard operations (here for binary compatibility)
- ("tp_hash", hashfunc), #N
- ("tp_call", ternaryfunc), #N
- ("tp_str", reprfunc), #N
- ("tp_getattro", getattrofunc),#N
- ("tp_setattro", setattrofunc),#N
-
- # Functions to access object as input/output buffer
- ("tp_as_buffer", Ptr(PyBufferProcs)), #U
-
- # Flags to define presence of optional/expanded features
- ("tp_flags", lltype.Signed), #E
-
- ("tp_doc", rffi.CCHARP), #N Documentation string
-
- # Assigned meaning in release 2.0
- # call function for all accessible objects
- ("tp_traverse", traverseproc),#U
-
- # delete references to contained objects
- ("tp_clear", inquiry), #U
-
- # Assigned meaning in release 2.1
- # rich comparisons
- ("tp_richcompare", richcmpfunc), #N
-
- # weak reference enabler
- ("tp_weaklistoffset", Py_ssize_t), #U
-
- # Added in release 2.2
- # Iterators
- ("tp_iter", getiterfunc), #N
- ("tp_iternext", iternextfunc), #N
-
- # Attribute descriptor and subclassing stuff
- ("tp_methods", Ptr(PyMethodDef)), #S
- ("tp_members", Ptr(PyMemberDef)), #S
- ("tp_getset", Ptr(PyGetSetDef)), #S
- ("tp_base", Ptr(PyTypeObject)), #E
- ("tp_dict", PyObject), #U
- ("tp_descr_get", descrgetfunc), #N
- ("tp_descr_set", descrsetfunc), #N
- ("tp_dictoffset", Py_ssize_t), #U
- ("tp_init", initproc), #N
- ("tp_alloc", allocfunc), #N
- ("tp_new", newfunc), #S
- ("tp_free", freefunc), #E Low-level free-memory routine
- ("tp_is_gc", inquiry), #U For PyObject_IS_GC
- ("tp_bases", PyObject),#E
- ("tp_mro", PyObject), #U method resolution order
- ("tp_cache", PyObject),#S
- ("tp_subclasses", PyObject), #U
- ("tp_weaklist", PyObject), #U
- ("tp_del", destructor), #N
- ])
+PyGetSetDef = object_h.definitions['PyGetSetDef']
+PyNumberMethods = object_h.definitions['PyNumberMethods']
+PySequenceMethods = object_h.definitions['PySequenceMethods']
+PyMappingMethods = object_h.definitions['PyMappingMethods']
+PyBufferProcs = object_h.definitions['PyBufferProcs']
+PyMemberDef = object_h.definitions['PyMemberDef']
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit