blob: 948f690300f5c974a9c5239f51b02919d3d0b8ec [file] [log] [blame]
Guido van Rossuma3309961993-07-28 09:05:47 +00001#ifndef Py_STRUCTMEMBER_H
2#define Py_STRUCTMEMBER_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
Guido van Rossumf70e43a1991-02-19 12:39:46 +00007
Guido van Rossum3f5da241990-12-20 15:06:42 +00008/* Interface to map C struct members to Python object attributes */
9
Guido van Rossum5ebc0ca1994-10-20 22:03:08 +000010#include <stddef.h> /* For offsetof */
Guido van Rossum5ebc0ca1994-10-20 22:03:08 +000011
Neal Norwitz8dfc4a92007-08-11 06:39:53 +000012/* An array of PyMemberDef structures defines the name, type and offset
Guido van Rossum3f5da241990-12-20 15:06:42 +000013 of selected members of a C structure. These can be read by
Neal Norwitz8dfc4a92007-08-11 06:39:53 +000014 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 Rossum3f5da241990-12-20 15:06:42 +000016 pointer is NULL. */
17
Guido van Rossum6f799372001-09-20 20:46:19 +000018typedef struct PyMemberDef {
Eli Benderskye1f107e2012-05-23 07:09:08 +030019 char *name;
20 int type;
21 Py_ssize_t offset;
22 int flags;
23 char *doc;
Guido van Rossum6f799372001-09-20 20:46:19 +000024} PyMemberDef;
25
Guido van Rossum3f5da241990-12-20 15:06:42 +000026/* Types */
Eli Benderskye1f107e2012-05-23 07:09:08 +030027#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 Rossum00023951992-06-03 17:07:40 +000034/* XXX the ordering here is weird for binary compatibility */
Eli Benderskye1f107e2012-05-23 07:09:08 +030035#define T_CHAR 7 /* 1-character string */
36#define T_BYTE 8 /* 8-bit signed int */
Guido van Rossum00023951992-06-03 17:07:40 +000037/* unsigned variants: */
Eli Benderskye1f107e2012-05-23 07:09:08 +030038#define T_UBYTE 9
39#define T_USHORT 10
40#define T_UINT 11
41#define T_ULONG 12
Guido van Rossum3f5da241990-12-20 15:06:42 +000042
Jack Jansen599f0d11994-12-14 13:04:05 +000043/* Added by Jack: strings contained in the structure */
Eli Benderskye1f107e2012-05-23 07:09:08 +030044#define T_STRING_INPLACE 13
Jack Jansen599f0d11994-12-14 13:04:05 +000045
Christian Heimes1af737c2008-01-23 08:24:23 +000046/* Added by Lillo: bools contained in the structure (assumed char) */
Eli Benderskye1f107e2012-05-23 07:09:08 +030047#define T_BOOL 14
Christian Heimes1af737c2008-01-23 08:24:23 +000048
Eli Benderskye1f107e2012-05-23 07:09:08 +030049#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öwis96d743e2005-03-03 23:00:26 +000052#ifdef HAVE_LONG_LONG
Eli Benderskye1f107e2012-05-23 07:09:08 +030053#define T_LONGLONG 17
Guido van Rossum50e9fb92006-08-17 05:42:55 +000054#define T_ULONGLONG 18
Martin v. Löwis96d743e2005-03-03 23:00:26 +000055#endif /* HAVE_LONG_LONG */
Guido van Rossum6b705992001-12-04 16:23:42 +000056
Guido van Rossum806c2462007-08-06 23:33:07 +000057#define T_PYSSIZET 19 /* Py_ssize_t */
Guido van Rossum7eaf8222007-06-18 17:58:50 +000058#define T_NONE 20 /* Value is always None */
Guido van Rossum50e9fb92006-08-17 05:42:55 +000059
Guido van Rossum806c2462007-08-06 23:33:07 +000060
Guido van Rossumc299fc12001-09-17 19:28:08 +000061/* Flags */
Eli Benderskye1f107e2012-05-23 07:09:08 +030062#define READONLY 1
63#define READ_RESTRICTED 2
Christian Heimesbce52be2007-11-17 19:08:41 +000064#define PY_WRITE_RESTRICTED 4
Eli Benderskye1f107e2012-05-23 07:09:08 +030065#define RESTRICTED (READ_RESTRICTED | PY_WRITE_RESTRICTED)
Guido van Rossumc299fc12001-09-17 19:28:08 +000066
Guido van Rossum3f5da241990-12-20 15:06:42 +000067
Guido van Rossum6f799372001-09-20 20:46:19 +000068/* Current API, use this */
Tim Petersc3d12ac2005-12-24 06:03:06 +000069PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);
Mark Hammond91a681d2002-08-12 07:21:58 +000070PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *);
Guido van Rossum6f799372001-09-20 20:46:19 +000071
72
Guido van Rossuma3309961993-07-28 09:05:47 +000073#ifdef __cplusplus
74}
75#endif
76#endif /* !Py_STRUCTMEMBER_H */