Author: Ronan Lamy <[email protected]>
Branch: rffi-parser-2
Changeset: r89508:5897cf94242d
Date: 2016-12-18 02:07 +0000
http://bitbucket.org/pypy/pypy/changeset/5897cf94242d/

Log:    Complete the declaration of 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
@@ -671,7 +671,7 @@
        PyObject_VAR_HEAD
 } PyVarObject;
 
-typedef struct _typeobject PyTypeObject;
+struct _typeobject;
 
 typedef void (*freefunc)(void *);
 typedef void (*destructor)(PyObject *);
@@ -751,6 +751,178 @@
 typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
 /* end Py3k buffer interface */
 
+typedef int (*objobjproc)(PyObject *, PyObject *);
+typedef int (*visitproc)(PyObject *, void *);
+typedef int (*traverseproc)(PyObject *, visitproc, void *);
+
+typedef struct {
+       /* For numbers without flag bit Py_TPFLAGS_CHECKTYPES set, all
+          arguments are guaranteed to be of the object's type (modulo
+          coercion hacks -- i.e. if the type's coercion function
+          returns other types, then these are allowed as well).  Numbers that
+          have the Py_TPFLAGS_CHECKTYPES flag bit set should check *both*
+          arguments for proper type and implement the necessary conversions
+          in the slot functions themselves. */
+
+       binaryfunc nb_add;
+       binaryfunc nb_subtract;
+       binaryfunc nb_multiply;
+       binaryfunc nb_divide;
+       binaryfunc nb_remainder;
+       binaryfunc nb_divmod;
+       ternaryfunc nb_power;
+       unaryfunc nb_negative;
+       unaryfunc nb_positive;
+       unaryfunc nb_absolute;
+       inquiry nb_nonzero;
+       unaryfunc nb_invert;
+       binaryfunc nb_lshift;
+       binaryfunc nb_rshift;
+       binaryfunc nb_and;
+       binaryfunc nb_xor;
+       binaryfunc nb_or;
+       coercion nb_coerce;
+       unaryfunc nb_int;
+       unaryfunc nb_long;
+       unaryfunc nb_float;
+       unaryfunc nb_oct;
+       unaryfunc nb_hex;
+       /* Added in release 2.0 */
+       binaryfunc nb_inplace_add;
+       binaryfunc nb_inplace_subtract;
+       binaryfunc nb_inplace_multiply;
+       binaryfunc nb_inplace_divide;
+       binaryfunc nb_inplace_remainder;
+       ternaryfunc nb_inplace_power;
+       binaryfunc nb_inplace_lshift;
+       binaryfunc nb_inplace_rshift;
+       binaryfunc nb_inplace_and;
+       binaryfunc nb_inplace_xor;
+       binaryfunc nb_inplace_or;
+
+       /* Added in release 2.2 */
+       /* The following require the Py_TPFLAGS_HAVE_CLASS flag */
+       binaryfunc nb_floor_divide;
+       binaryfunc nb_true_divide;
+       binaryfunc nb_inplace_floor_divide;
+       binaryfunc nb_inplace_true_divide;
+
+       /* Added in release 2.5 */
+       unaryfunc nb_index;
+} PyNumberMethods;
+
+typedef struct {
+       lenfunc sq_length;
+       binaryfunc sq_concat;
+       ssizeargfunc sq_repeat;
+       ssizeargfunc sq_item;
+       ssizessizeargfunc sq_slice;
+       ssizeobjargproc sq_ass_item;
+       ssizessizeobjargproc sq_ass_slice;
+       objobjproc sq_contains;
+       /* Added in release 2.0 */
+       binaryfunc sq_inplace_concat;
+       ssizeargfunc sq_inplace_repeat;
+} PySequenceMethods;
+
+typedef struct {
+       lenfunc mp_length;
+       binaryfunc mp_subscript;
+       objobjargproc mp_ass_subscript;
+} PyMappingMethods;
+
+typedef struct {
+       readbufferproc bf_getreadbuffer;
+       writebufferproc bf_getwritebuffer;
+       segcountproc bf_getsegcount;
+       charbufferproc bf_getcharbuffer;
+       getbufferproc bf_getbuffer;
+       releasebufferproc bf_releasebuffer;
+} PyBufferProcs;
+
+
+
+typedef struct _typeobject {
+       PyObject_VAR_HEAD
+       const char *tp_name; /* For printing, in format "<module>.<name>" */
+       Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
+
+       /* Methods to implement standard operations */
+
+       destructor tp_dealloc;
+       printfunc tp_print;
+       getattrfunc tp_getattr;
+       setattrfunc tp_setattr;
+       cmpfunc tp_compare;
+       reprfunc tp_repr;
+
+       /* Method suites for standard classes */
+
+       PyNumberMethods *tp_as_number;
+       PySequenceMethods *tp_as_sequence;
+       PyMappingMethods *tp_as_mapping;
+
+       /* More standard operations (here for binary compatibility) */
+
+       hashfunc tp_hash;
+       ternaryfunc tp_call;
+       reprfunc tp_str;
+       getattrofunc tp_getattro;
+       setattrofunc tp_setattro;
+
+       /* Functions to access object as input/output buffer */
+       PyBufferProcs *tp_as_buffer;
+
+       /* Flags to define presence of optional/expanded features */
+       long tp_flags;
+
+       const char *tp_doc; /* Documentation string */
+
+       /* Assigned meaning in release 2.0 */
+       /* call function for all accessible objects */
+       traverseproc tp_traverse;
+
+       /* delete references to contained objects */
+       inquiry tp_clear;
+
+       /* Assigned meaning in release 2.1 */
+       /* rich comparisons */
+       richcmpfunc tp_richcompare;
+
+       /* weak reference enabler */
+       Py_ssize_t tp_weaklistoffset;
+
+       /* Added in release 2.2 */
+       /* Iterators */
+       getiterfunc tp_iter;
+       iternextfunc tp_iternext;
+
+       /* Attribute descriptor and subclassing stuff */
+       struct PyMethodDef *tp_methods;
+       struct PyMemberDef *tp_members;
+       struct PyGetSetDef *tp_getset;
+       struct _typeobject *tp_base;
+       PyObject *tp_dict;
+       descrgetfunc tp_descr_get;
+       descrsetfunc tp_descr_set;
+       Py_ssize_t tp_dictoffset;
+       initproc tp_init;
+       allocfunc tp_alloc;
+       newfunc tp_new;
+       freefunc tp_free; /* Low-level free-memory routine */
+       inquiry tp_is_gc; /* For PyObject_IS_GC */
+       PyObject *tp_bases;
+       PyObject *tp_mro; /* method resolution order */
+       PyObject *tp_cache;
+       PyObject *tp_subclasses;
+       PyObject *tp_weaklist;
+       destructor tp_del;
+
+       /* Type attribute cache version tag. Added in version 2.6 */
+       unsigned int tp_version_tag;
+
+} PyTypeObject;
+
 """)
 
 Py_ssize_t = object_h.gettype('Py_ssize_t')
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
@@ -235,4 +235,3 @@
     ("tp_weaklist", PyObject),   #U
     ("tp_del", destructor),      #N
     ])
-cpython_struct("PyTypeObject", PyTypeObjectFields, PyTypeObject)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to