cpyext_object.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. #pragma once
  2. typedef long Py_ssize_t;
  3. #define PyObject_HEAD \
  4. Py_ssize_t ob_refcnt; \
  5. Py_ssize_t ob_pypy_link; \
  6. struct _typeobject *ob_type;
  7. #define PyObject_VAR_HEAD \
  8. PyObject_HEAD \
  9. Py_ssize_t ob_size; /* Number of items in variable part */
  10. typedef struct _object {
  11. PyObject_HEAD
  12. } PyObject;
  13. typedef struct {
  14. PyObject_VAR_HEAD
  15. } PyVarObject;
  16. struct _typeobject;
  17. typedef void (*freefunc)(void *);
  18. typedef void (*destructor)(PyObject *);
  19. typedef int (*printfunc)(PyObject *, FILE *, int);
  20. typedef PyObject *(*getattrfunc)(PyObject *, char *);
  21. typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);
  22. typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
  23. typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);
  24. typedef int (*cmpfunc)(PyObject *, PyObject *);
  25. typedef PyObject *(*reprfunc)(PyObject *);
  26. typedef long (*hashfunc)(PyObject *);
  27. typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
  28. typedef PyObject *(*getiterfunc) (PyObject *);
  29. typedef PyObject *(*iternextfunc) (PyObject *);
  30. typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *);
  31. typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *);
  32. typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
  33. typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);
  34. typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t);
  35. typedef PyObject * (*unaryfunc)(PyObject *);
  36. typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
  37. typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
  38. typedef int (*inquiry)(PyObject *);
  39. typedef Py_ssize_t (*lenfunc)(PyObject *);
  40. typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t);
  41. typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t);
  42. typedef int(*ssizeobjargproc)(PyObject *, Py_ssize_t, PyObject *);
  43. typedef int(*ssizessizeobjargproc)(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *);
  44. typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
  45. /* Py3k buffer interface, adapted for PyPy */
  46. #define Py_MAX_NDIMS 32
  47. #define Py_MAX_FMT 128
  48. typedef struct bufferinfo {
  49. void *buf;
  50. PyObject *obj; /* owned reference */
  51. Py_ssize_t len;
  52. Py_ssize_t itemsize; /* This is Py_ssize_t so it can be
  53. pointed to by strides in simple case.*/
  54. int readonly;
  55. int ndim;
  56. char *format;
  57. Py_ssize_t *shape;
  58. Py_ssize_t *strides;
  59. Py_ssize_t *suboffsets; /* alway NULL for app-level objects*/
  60. unsigned char _format[Py_MAX_FMT];
  61. Py_ssize_t _strides[Py_MAX_NDIMS];
  62. Py_ssize_t _shape[Py_MAX_NDIMS];
  63. /* static store for shape and strides of
  64. mono-dimensional buffers. */
  65. /* Py_ssize_t smalltable[2]; */
  66. void *internal; /* always NULL for app-level objects */
  67. } Py_buffer;
  68. typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
  69. typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
  70. /* end Py3k buffer interface */
  71. typedef int (*objobjproc)(PyObject *, PyObject *);
  72. typedef int (*visitproc)(PyObject *, void *);
  73. typedef int (*traverseproc)(PyObject *, visitproc, void *);
  74. typedef struct {
  75. /* Number implementations must check *both*
  76. arguments for proper type and implement the necessary conversions
  77. in the slot functions themselves. */
  78. binaryfunc nb_add;
  79. binaryfunc nb_subtract;
  80. binaryfunc nb_multiply;
  81. binaryfunc nb_remainder;
  82. binaryfunc nb_divmod;
  83. ternaryfunc nb_power;
  84. unaryfunc nb_negative;
  85. unaryfunc nb_positive;
  86. unaryfunc nb_absolute;
  87. inquiry nb_bool;
  88. unaryfunc nb_invert;
  89. binaryfunc nb_lshift;
  90. binaryfunc nb_rshift;
  91. binaryfunc nb_and;
  92. binaryfunc nb_xor;
  93. binaryfunc nb_or;
  94. unaryfunc nb_int;
  95. void *nb_reserved; /* the slot formerly known as nb_long */
  96. unaryfunc nb_float;
  97. binaryfunc nb_inplace_add;
  98. binaryfunc nb_inplace_subtract;
  99. binaryfunc nb_inplace_multiply;
  100. binaryfunc nb_inplace_remainder;
  101. ternaryfunc nb_inplace_power;
  102. binaryfunc nb_inplace_lshift;
  103. binaryfunc nb_inplace_rshift;
  104. binaryfunc nb_inplace_and;
  105. binaryfunc nb_inplace_xor;
  106. binaryfunc nb_inplace_or;
  107. binaryfunc nb_floor_divide;
  108. binaryfunc nb_true_divide;
  109. binaryfunc nb_inplace_floor_divide;
  110. binaryfunc nb_inplace_true_divide;
  111. unaryfunc nb_index;
  112. binaryfunc nb_matrix_multiply;
  113. binaryfunc nb_inplace_matrix_multiply;
  114. } PyNumberMethods;
  115. typedef struct {
  116. lenfunc sq_length;
  117. binaryfunc sq_concat;
  118. ssizeargfunc sq_repeat;
  119. ssizeargfunc sq_item;
  120. void *was_sq_slice;
  121. ssizeobjargproc sq_ass_item;
  122. void *was_sq_ass_slice;
  123. objobjproc sq_contains;
  124. binaryfunc sq_inplace_concat;
  125. ssizeargfunc sq_inplace_repeat;
  126. } PySequenceMethods;
  127. typedef struct {
  128. lenfunc mp_length;
  129. binaryfunc mp_subscript;
  130. objobjargproc mp_ass_subscript;
  131. } PyMappingMethods;
  132. typedef struct {
  133. unaryfunc am_await;
  134. unaryfunc am_aiter;
  135. unaryfunc am_anext;
  136. } PyAsyncMethods;
  137. typedef struct {
  138. getbufferproc bf_getbuffer;
  139. releasebufferproc bf_releasebuffer;
  140. } PyBufferProcs;
  141. /* from descrobject.h */
  142. typedef PyObject *(*getter)(PyObject *, void *);
  143. typedef int (*setter)(PyObject *, PyObject *, void *);
  144. typedef struct PyGetSetDef {
  145. char *name;
  146. getter get;
  147. setter set;
  148. char *doc;
  149. void *closure;
  150. } PyGetSetDef;
  151. /* from methodobject.h */
  152. typedef PyObject *(*PyCFunction)(PyObject *, PyObject *);
  153. typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *,
  154. PyObject *);
  155. typedef PyObject *(*PyNoArgsFunction)(PyObject *);
  156. struct PyMethodDef {
  157. const char *ml_name; /* The name of the built-in function/method */
  158. PyCFunction ml_meth; /* The C function that implements it */
  159. int ml_flags; /* Combination of METH_xxx flags, which mostly
  160. describe the args expected by the C func */
  161. const char *ml_doc; /* The __doc__ attribute, or NULL */
  162. };
  163. typedef struct PyMethodDef PyMethodDef;
  164. typedef struct {
  165. PyObject_HEAD
  166. PyMethodDef *m_ml; /* Description of the C function to call */
  167. PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */
  168. PyObject *m_module; /* The __module__ attribute, can be anything */
  169. PyObject *m_weakreflist; /* List of weak references */
  170. } PyCFunctionObject;
  171. /* from structmember.h */
  172. typedef struct PyMemberDef {
  173. /* Current version, use this */
  174. char *name;
  175. int type;
  176. Py_ssize_t offset;
  177. int flags;
  178. char *doc;
  179. } PyMemberDef;
  180. typedef struct _typeobject {
  181. PyObject_VAR_HEAD
  182. const char *tp_name; /* For printing, in format "<module>.<name>" */
  183. Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
  184. /* Methods to implement standard operations */
  185. destructor tp_dealloc;
  186. printfunc tp_print;
  187. getattrfunc tp_getattr;
  188. setattrfunc tp_setattr;
  189. PyAsyncMethods *tp_as_async; /* formerly known as tp_compare (Python 2)
  190. or tp_reserved (Python 3) */
  191. reprfunc tp_repr;
  192. /* Method suites for standard classes */
  193. PyNumberMethods *tp_as_number;
  194. PySequenceMethods *tp_as_sequence;
  195. PyMappingMethods *tp_as_mapping;
  196. /* More standard operations (here for binary compatibility) */
  197. hashfunc tp_hash;
  198. ternaryfunc tp_call;
  199. reprfunc tp_str;
  200. getattrofunc tp_getattro;
  201. setattrofunc tp_setattro;
  202. /* Functions to access object as input/output buffer */
  203. PyBufferProcs *tp_as_buffer;
  204. /* Flags to define presence of optional/expanded features */
  205. unsigned long tp_flags;
  206. const char *tp_doc; /* Documentation string */
  207. /* Assigned meaning in release 2.0 */
  208. /* call function for all accessible objects */
  209. traverseproc tp_traverse;
  210. /* delete references to contained objects */
  211. inquiry tp_clear;
  212. /* Assigned meaning in release 2.1 */
  213. /* rich comparisons */
  214. richcmpfunc tp_richcompare;
  215. /* weak reference enabler */
  216. Py_ssize_t tp_weaklistoffset;
  217. /* Iterators */
  218. getiterfunc tp_iter;
  219. iternextfunc tp_iternext;
  220. /* Attribute descriptor and subclassing stuff */
  221. struct PyMethodDef *tp_methods;
  222. struct PyMemberDef *tp_members;
  223. struct PyGetSetDef *tp_getset;
  224. struct _typeobject *tp_base;
  225. PyObject *tp_dict;
  226. descrgetfunc tp_descr_get;
  227. descrsetfunc tp_descr_set;
  228. Py_ssize_t tp_dictoffset;
  229. initproc tp_init;
  230. allocfunc tp_alloc;
  231. newfunc tp_new;
  232. freefunc tp_free; /* Low-level free-memory routine */
  233. inquiry tp_is_gc; /* For PyObject_IS_GC */
  234. PyObject *tp_bases;
  235. PyObject *tp_mro; /* method resolution order */
  236. PyObject *tp_cache;
  237. PyObject *tp_subclasses;
  238. PyObject *tp_weaklist;
  239. destructor tp_del;
  240. /* Type attribute cache version tag. Added in version 2.6 */
  241. unsigned int tp_version_tag;
  242. destructor tp_finalize;
  243. } PyTypeObject;
  244. typedef struct{
  245. int slot; /* slot id, see below */
  246. void *pfunc; /* function pointer */
  247. } PyType_Slot;
  248. typedef struct{
  249. const char* name;
  250. int basicsize;
  251. int itemsize;
  252. unsigned int flags;
  253. PyType_Slot *slots; /* terminated by slot==0. */
  254. } PyType_Spec;
  255. typedef struct _heaptypeobject {
  256. PyTypeObject ht_type;
  257. PyAsyncMethods as_async;
  258. PyNumberMethods as_number;
  259. PyMappingMethods as_mapping;
  260. PySequenceMethods as_sequence;
  261. PyBufferProcs as_buffer;
  262. PyObject *ht_name, *ht_slots, *ht_qualname;
  263. } PyHeapTypeObject;