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