Back to index

python3.2  3.2.2
structmember.h
Go to the documentation of this file.
00001 #ifndef Py_STRUCTMEMBER_H
00002 #define Py_STRUCTMEMBER_H
00003 #ifdef __cplusplus
00004 extern "C" {
00005 #endif
00006 
00007 
00008 /* Interface to map C struct members to Python object attributes */
00009 
00010 #include <stddef.h> /* For offsetof */
00011 
00012 /* The offsetof() macro calculates the offset of a structure member
00013    in its structure.  Unfortunately this cannot be written down
00014    portably, hence it is provided by a Standard C header file.
00015    For pre-Standard C compilers, here is a version that usually works
00016    (but watch out!): */
00017 
00018 #ifndef offsetof
00019 #define offsetof(type, member) ( (int) & ((type*)0) -> member )
00020 #endif
00021 
00022 /* An array of PyMemberDef structures defines the name, type and offset
00023    of selected members of a C structure.  These can be read by
00024    PyMember_GetOne() and set by PyMember_SetOne() (except if their READONLY
00025    flag is set).  The array must be terminated with an entry whose name
00026    pointer is NULL. */
00027 
00028 typedef struct PyMemberDef {
00029        /* Current version, use this */
00030        char *name;
00031        int type;
00032        Py_ssize_t offset;
00033        int flags;
00034        char *doc;
00035 } PyMemberDef;
00036 
00037 /* Types */
00038 #define T_SHORT             0
00039 #define T_INT        1
00040 #define T_LONG              2
00041 #define T_FLOAT             3
00042 #define T_DOUBLE     4
00043 #define T_STRING     5
00044 #define T_OBJECT     6
00045 /* XXX the ordering here is weird for binary compatibility */
00046 #define T_CHAR              7      /* 1-character string */
00047 #define T_BYTE              8      /* 8-bit signed int */
00048 /* unsigned variants: */
00049 #define T_UBYTE             9
00050 #define T_USHORT     10
00051 #define T_UINT              11
00052 #define T_ULONG             12
00053 
00054 /* Added by Jack: strings contained in the structure */
00055 #define T_STRING_INPLACE    13
00056 
00057 /* Added by Lillo: bools contained in the structure (assumed char) */
00058 #define T_BOOL              14
00059 
00060 #define T_OBJECT_EX  16     /* Like T_OBJECT, but raises AttributeError
00061                                when the value is NULL, instead of
00062                                converting to None. */
00063 #ifdef HAVE_LONG_LONG
00064 #define T_LONGLONG      17  
00065 #define T_ULONGLONG     18
00066 #endif /* HAVE_LONG_LONG */
00067 
00068 #define T_PYSSIZET      19      /* Py_ssize_t */
00069 #define T_NONE          20      /* Value is always None */
00070 
00071 
00072 /* Flags */
00073 #define READONLY     1
00074 #define READ_RESTRICTED     2
00075 #define PY_WRITE_RESTRICTED 4
00076 #define RESTRICTED   (READ_RESTRICTED | PY_WRITE_RESTRICTED)
00077 
00078 
00079 /* Current API, use this */
00080 PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);
00081 PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *);
00082 
00083 
00084 #ifdef __cplusplus
00085 }
00086 #endif
00087 #endif /* !Py_STRUCTMEMBER_H */