Chris@87: #ifndef Py_STRUCTMEMBER_H Chris@87: #define Py_STRUCTMEMBER_H Chris@87: #ifdef __cplusplus Chris@87: extern "C" { Chris@87: #endif Chris@87: Chris@87: Chris@87: /* Interface to map C struct members to Python object attributes */ Chris@87: Chris@87: #include /* For offsetof */ Chris@87: Chris@87: /* The offsetof() macro calculates the offset of a structure member Chris@87: in its structure. Unfortunately this cannot be written down Chris@87: portably, hence it is provided by a Standard C header file. Chris@87: For pre-Standard C compilers, here is a version that usually works Chris@87: (but watch out!): */ Chris@87: Chris@87: #ifndef offsetof Chris@87: #define offsetof(type, member) ( (int) & ((type*)0) -> member ) Chris@87: #endif Chris@87: Chris@87: /* An array of memberlist structures defines the name, type and offset Chris@87: of selected members of a C structure. These can be read by Chris@87: PyMember_Get() and set by PyMember_Set() (except if their READONLY flag Chris@87: is set). The array must be terminated with an entry whose name Chris@87: pointer is NULL. */ Chris@87: Chris@87: struct memberlist { Chris@87: /* Obsolete version, for binary backwards compatibility */ Chris@87: char *name; Chris@87: int type; Chris@87: int offset; Chris@87: int flags; Chris@87: }; Chris@87: Chris@87: typedef struct PyMemberDef { Chris@87: /* Current version, use this */ Chris@87: char *name; Chris@87: int type; Chris@87: Py_ssize_t offset; Chris@87: int flags; Chris@87: char *doc; Chris@87: } PyMemberDef; Chris@87: Chris@87: /* Types */ Chris@87: #define T_SHORT 0 Chris@87: #define T_INT 1 Chris@87: #define T_LONG 2 Chris@87: #define T_FLOAT 3 Chris@87: #define T_DOUBLE 4 Chris@87: #define T_STRING 5 Chris@87: #define T_OBJECT 6 Chris@87: /* XXX the ordering here is weird for binary compatibility */ Chris@87: #define T_CHAR 7 /* 1-character string */ Chris@87: #define T_BYTE 8 /* 8-bit signed int */ Chris@87: /* unsigned variants: */ Chris@87: #define T_UBYTE 9 Chris@87: #define T_USHORT 10 Chris@87: #define T_UINT 11 Chris@87: #define T_ULONG 12 Chris@87: Chris@87: /* Added by Jack: strings contained in the structure */ Chris@87: #define T_STRING_INPLACE 13 Chris@87: Chris@87: /* Added by Lillo: bools contained in the structure (assumed char) */ Chris@87: #define T_BOOL 14 Chris@87: Chris@87: #define T_OBJECT_EX 16 /* Like T_OBJECT, but raises AttributeError Chris@87: when the value is NULL, instead of Chris@87: converting to None. */ Chris@87: #ifdef HAVE_LONG_LONG Chris@87: #define T_LONGLONG 17 Chris@87: #define T_ULONGLONG 18 Chris@87: #endif /* HAVE_LONG_LONG */ Chris@87: Chris@87: #define T_PYSSIZET 19 /* Py_ssize_t */ Chris@87: Chris@87: Chris@87: /* Flags */ Chris@87: #define READONLY 1 Chris@87: #define RO READONLY /* Shorthand */ Chris@87: #define READ_RESTRICTED 2 Chris@87: #define PY_WRITE_RESTRICTED 4 Chris@87: #define RESTRICTED (READ_RESTRICTED | PY_WRITE_RESTRICTED) Chris@87: Chris@87: Chris@87: /* Obsolete API, for binary backwards compatibility */ Chris@87: PyAPI_FUNC(PyObject *) PyMember_Get(const char *, struct memberlist *, const char *); Chris@87: PyAPI_FUNC(int) PyMember_Set(char *, struct memberlist *, const char *, PyObject *); Chris@87: Chris@87: /* Current API, use this */ Chris@87: PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *); Chris@87: PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *); Chris@87: Chris@87: Chris@87: #ifdef __cplusplus Chris@87: } Chris@87: #endif Chris@87: #endif /* !Py_STRUCTMEMBER_H */