structmember.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef Py_STRUCTMEMBER_H
  2. #define Py_STRUCTMEMBER_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /* Interface to map C struct members to Python object attributes */
  7. #include <stddef.h> /* For offsetof */
  8. /* The offsetof() macro calculates the offset of a structure member
  9. in its structure. Unfortunately this cannot be written down
  10. portably, hence it is provided by a Standard C header file.
  11. For pre-Standard C compilers, here is a version that usually works
  12. (but watch out!): */
  13. #ifndef offsetof
  14. #define offsetof(type, member) ( (int) & ((type*)0) -> member )
  15. #endif
  16. /* An array of memberlist structures defines the name, type and offset
  17. of selected members of a C structure. These can be read by
  18. PyMember_Get() and set by PyMember_Set() (except if their READONLY flag
  19. is set). The array must be terminated with an entry whose name
  20. pointer is NULL. */
  21. struct memberlist {
  22. /* Obsolete version, for binary backwards compatibility */
  23. char *name;
  24. int type;
  25. int offset;
  26. int flags;
  27. };
  28. typedef struct PyMemberDef {
  29. /* Current version, use this */
  30. char *name;
  31. int type;
  32. Py_ssize_t offset;
  33. int flags;
  34. char *doc;
  35. } PyMemberDef;
  36. /* Types */
  37. #define T_SHORT 0
  38. #define T_INT 1
  39. #define T_LONG 2
  40. #define T_FLOAT 3
  41. #define T_DOUBLE 4
  42. #define T_STRING 5
  43. #define T_OBJECT 6
  44. /* XXX the ordering here is weird for binary compatibility */
  45. #define T_CHAR 7 /* 1-character string */
  46. #define T_BYTE 8 /* 8-bit signed int */
  47. /* unsigned variants: */
  48. #define T_UBYTE 9
  49. #define T_USHORT 10
  50. #define T_UINT 11
  51. #define T_ULONG 12
  52. /* Added by Jack: strings contained in the structure */
  53. #define T_STRING_INPLACE 13
  54. /* Added by Lillo: bools contained in the structure (assumed char) */
  55. #define T_BOOL 14
  56. #define T_OBJECT_EX 16 /* Like T_OBJECT, but raises AttributeError
  57. when the value is NULL, instead of
  58. converting to None. */
  59. #ifdef HAVE_LONG_LONG
  60. #define T_LONGLONG 17
  61. #define T_ULONGLONG 18
  62. #endif /* HAVE_LONG_LONG */
  63. #define T_PYSSIZET 19 /* Py_ssize_t */
  64. /* Flags */
  65. #define READONLY 1
  66. #define RO READONLY /* Shorthand */
  67. #define READ_RESTRICTED 2
  68. #define PY_WRITE_RESTRICTED 4
  69. #define RESTRICTED (READ_RESTRICTED | PY_WRITE_RESTRICTED)
  70. /* Obsolete API, for binary backwards compatibility */
  71. PyAPI_FUNC(PyObject *) PyMember_Get(const char *, struct memberlist *, const char *);
  72. PyAPI_FUNC(int) PyMember_Set(char *, struct memberlist *, const char *, PyObject *);
  73. /* Current API, use this */
  74. PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);
  75. PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *);
  76. #ifdef __cplusplus
  77. }
  78. #endif
  79. #endif /* !Py_STRUCTMEMBER_H */