descrobject.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* Descriptors */
  2. #ifndef Py_DESCROBJECT_H
  3. #define Py_DESCROBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef PyObject *(*getter)(PyObject *, void *);
  8. typedef int (*setter)(PyObject *, PyObject *, void *);
  9. struct PyGetSetDef {
  10. const char *name;
  11. getter get;
  12. setter set;
  13. const char *doc;
  14. void *closure;
  15. };
  16. PyAPI_DATA(PyTypeObject) PyClassMethodDescr_Type;
  17. PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;
  18. PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;
  19. PyAPI_DATA(PyTypeObject) PyMethodDescr_Type;
  20. PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
  21. PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
  22. PyAPI_DATA(PyTypeObject) PyProperty_Type;
  23. PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
  24. PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
  25. PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *, PyMemberDef *);
  26. PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *, PyGetSetDef *);
  27. PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
  28. PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);
  29. /* An array of PyMemberDef structures defines the name, type and offset
  30. of selected members of a C structure. These can be read by
  31. PyMember_GetOne() and set by PyMember_SetOne() (except if their READONLY
  32. flag is set). The array must be terminated with an entry whose name
  33. pointer is NULL. */
  34. struct PyMemberDef {
  35. const char *name;
  36. int type;
  37. Py_ssize_t offset;
  38. int flags;
  39. const char *doc;
  40. };
  41. // These constants used to be in structmember.h, not prefixed by Py_.
  42. // (structmember.h now has aliases to the new names.)
  43. /* Types */
  44. #define Py_T_SHORT 0
  45. #define Py_T_INT 1
  46. #define Py_T_LONG 2
  47. #define Py_T_FLOAT 3
  48. #define Py_T_DOUBLE 4
  49. #define Py_T_STRING 5
  50. #define _Py_T_OBJECT 6 // Deprecated, use Py_T_OBJECT_EX instead
  51. /* the ordering here is weird for binary compatibility */
  52. #define Py_T_CHAR 7 /* 1-character string */
  53. #define Py_T_BYTE 8 /* 8-bit signed int */
  54. /* unsigned variants: */
  55. #define Py_T_UBYTE 9
  56. #define Py_T_USHORT 10
  57. #define Py_T_UINT 11
  58. #define Py_T_ULONG 12
  59. /* Added by Jack: strings contained in the structure */
  60. #define Py_T_STRING_INPLACE 13
  61. /* Added by Lillo: bools contained in the structure (assumed char) */
  62. #define Py_T_BOOL 14
  63. #define Py_T_OBJECT_EX 16
  64. #define Py_T_LONGLONG 17
  65. #define Py_T_ULONGLONG 18
  66. #define Py_T_PYSSIZET 19 /* Py_ssize_t */
  67. #define _Py_T_NONE 20 // Deprecated. Value is always None.
  68. /* Flags */
  69. #define Py_READONLY 1
  70. #define Py_AUDIT_READ 2 // Added in 3.10, harmless no-op before that
  71. #define _Py_WRITE_RESTRICTED 4 // Deprecated, no-op. Do not reuse the value.
  72. #define Py_RELATIVE_OFFSET 8
  73. PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, PyMemberDef *);
  74. PyAPI_FUNC(int) PyMember_SetOne(char *, PyMemberDef *, PyObject *);
  75. #ifndef Py_LIMITED_API
  76. # define Py_CPYTHON_DESCROBJECT_H
  77. # include "cpython/descrobject.h"
  78. # undef Py_CPYTHON_DESCROBJECT_H
  79. #endif
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #endif /* !Py_DESCROBJECT_H */