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