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