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 | #include <stddef.h> /* For offsetof */ |
Guido van Rossum | 5ebc0ca | 1994-10-20 22:03:08 +0000 | [diff] [blame] | 11 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 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 | |
Neal Norwitz | 8dfc4a9 | 2007-08-11 06:39:53 +0000 | [diff] [blame] | 22 | /* An array of PyMemberDef structures defines the name, type and offset |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 23 | of selected members of a C structure. These can be read by |
Neal Norwitz | 8dfc4a9 | 2007-08-11 06:39:53 +0000 | [diff] [blame] | 24 | PyMember_GetOne() and set by PyMember_SetOne() (except if their READONLY |
| 25 | flag is set). The array must be terminated with an entry whose name |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 26 | pointer is NULL. */ |
| 27 | |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 28 | typedef struct PyMemberDef { |
| 29 | /* Current version, use this */ |
| 30 | char *name; |
| 31 | int type; |
Martin v. Löwis | 44e379d | 2006-02-16 14:23:19 +0000 | [diff] [blame] | 32 | Py_ssize_t offset; |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 33 | int flags; |
| 34 | char *doc; |
| 35 | } PyMemberDef; |
| 36 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 37 | /* Types */ |
| 38 | #define T_SHORT 0 |
| 39 | #define T_INT 1 |
| 40 | #define T_LONG 2 |
| 41 | #define T_FLOAT 3 |
| 42 | #define T_DOUBLE 4 |
| 43 | #define T_STRING 5 |
| 44 | #define T_OBJECT 6 |
Guido van Rossum | 0002395 | 1992-06-03 17:07:40 +0000 | [diff] [blame] | 45 | /* XXX the ordering here is weird for binary compatibility */ |
| 46 | #define T_CHAR 7 /* 1-character string */ |
| 47 | #define T_BYTE 8 /* 8-bit signed int */ |
| 48 | /* unsigned variants: */ |
| 49 | #define T_UBYTE 9 |
| 50 | #define T_USHORT 10 |
| 51 | #define T_UINT 11 |
| 52 | #define T_ULONG 12 |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 53 | |
Jack Jansen | 599f0d1 | 1994-12-14 13:04:05 +0000 | [diff] [blame] | 54 | /* Added by Jack: strings contained in the structure */ |
| 55 | #define T_STRING_INPLACE 13 |
Jack Jansen | 599f0d1 | 1994-12-14 13:04:05 +0000 | [diff] [blame] | 56 | |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 57 | /* Added by Lillo: bools contained in the structure (assumed char) */ |
| 58 | #define T_BOOL 14 |
| 59 | |
Guido van Rossum | 6b70599 | 2001-12-04 16:23:42 +0000 | [diff] [blame] | 60 | #define T_OBJECT_EX 16 /* Like T_OBJECT, but raises AttributeError |
| 61 | when the value is NULL, instead of |
| 62 | converting to None. */ |
Martin v. Löwis | 96d743e | 2005-03-03 23:00:26 +0000 | [diff] [blame] | 63 | #ifdef HAVE_LONG_LONG |
| 64 | #define T_LONGLONG 17 |
Guido van Rossum | 50e9fb9 | 2006-08-17 05:42:55 +0000 | [diff] [blame] | 65 | #define T_ULONGLONG 18 |
Martin v. Löwis | 96d743e | 2005-03-03 23:00:26 +0000 | [diff] [blame] | 66 | #endif /* HAVE_LONG_LONG */ |
Guido van Rossum | 6b70599 | 2001-12-04 16:23:42 +0000 | [diff] [blame] | 67 | |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 68 | #define T_PYSSIZET 19 /* Py_ssize_t */ |
Guido van Rossum | 7eaf822 | 2007-06-18 17:58:50 +0000 | [diff] [blame] | 69 | #define T_NONE 20 /* Value is always None */ |
Guido van Rossum | 50e9fb9 | 2006-08-17 05:42:55 +0000 | [diff] [blame] | 70 | |
Guido van Rossum | 806c246 | 2007-08-06 23:33:07 +0000 | [diff] [blame] | 71 | |
Guido van Rossum | c299fc1 | 2001-09-17 19:28:08 +0000 | [diff] [blame] | 72 | /* Flags */ |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 73 | #define READONLY 1 |
Guido van Rossum | c299fc1 | 2001-09-17 19:28:08 +0000 | [diff] [blame] | 74 | #define READ_RESTRICTED 2 |
Christian Heimes | bce52be | 2007-11-17 19:08:41 +0000 | [diff] [blame] | 75 | #define PY_WRITE_RESTRICTED 4 |
| 76 | #define RESTRICTED (READ_RESTRICTED | PY_WRITE_RESTRICTED) |
Guido van Rossum | c299fc1 | 2001-09-17 19:28:08 +0000 | [diff] [blame] | 77 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 78 | |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 79 | /* Current API, use this */ |
Tim Peters | c3d12ac | 2005-12-24 06:03:06 +0000 | [diff] [blame] | 80 | PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *); |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 81 | PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *); |
Guido van Rossum | 6f79937 | 2001-09-20 20:46:19 +0000 | [diff] [blame] | 82 | |
| 83 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 84 | #ifdef __cplusplus |
| 85 | } |
| 86 | #endif |
| 87 | #endif /* !Py_STRUCTMEMBER_H */ |