blob: fe5b44ea342addac4823c81ad22ad957b1e51d6c [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
Guido van Rossum3f5da241990-12-20 15:06:42 +000012/* 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
Guido van Rossumcaa63801995-01-12 11:45:45 +000024 PyMember_Get() and set by PyMember_Set() (except if their READONLY flag
Guido van Rossum3f5da241990-12-20 15:06:42 +000025 is set). The array must be terminated with an entry whose name
26 pointer is NULL. */
27
28struct memberlist {
Antoine Pitrouc83ea132010-05-09 14:46:46 +000029 /* Obsolete version, for binary backwards compatibility */
30 char *name;
31 int type;
32 int offset;
33 int flags;
Guido van Rossum3f5da241990-12-20 15:06:42 +000034};
35
Guido van Rossum6f799372001-09-20 20:46:19 +000036typedef struct PyMemberDef {
Antoine Pitrouc83ea132010-05-09 14:46:46 +000037 /* Current version, use this */
38 char *name;
39 int type;
40 Py_ssize_t offset;
41 int flags;
42 char *doc;
Guido van Rossum6f799372001-09-20 20:46:19 +000043} PyMemberDef;
44
Guido van Rossum3f5da241990-12-20 15:06:42 +000045/* Types */
Antoine Pitrouc83ea132010-05-09 14:46:46 +000046#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
Guido van Rossum00023951992-06-03 17:07:40 +000053/* XXX the ordering here is weird for binary compatibility */
Antoine Pitrouc83ea132010-05-09 14:46:46 +000054#define T_CHAR 7 /* 1-character string */
55#define T_BYTE 8 /* 8-bit signed int */
Guido van Rossum00023951992-06-03 17:07:40 +000056/* unsigned variants: */
Antoine Pitrouc83ea132010-05-09 14:46:46 +000057#define T_UBYTE 9
58#define T_USHORT 10
59#define T_UINT 11
60#define T_ULONG 12
Guido van Rossum3f5da241990-12-20 15:06:42 +000061
Jack Jansen599f0d11994-12-14 13:04:05 +000062/* Added by Jack: strings contained in the structure */
Antoine Pitrouc83ea132010-05-09 14:46:46 +000063#define T_STRING_INPLACE 13
Jack Jansen599f0d11994-12-14 13:04:05 +000064
Georg Brandl32a3fb52008-01-21 21:23:15 +000065/* Added by Lillo: bools contained in the structure (assumed char) */
Antoine Pitrouc83ea132010-05-09 14:46:46 +000066#define T_BOOL 14
Georg Brandl32a3fb52008-01-21 21:23:15 +000067
Antoine Pitrouc83ea132010-05-09 14:46:46 +000068#define T_OBJECT_EX 16 /* Like T_OBJECT, but raises AttributeError
69 when the value is NULL, instead of
70 converting to None. */
Martin v. Löwis96d743e2005-03-03 23:00:26 +000071#ifdef HAVE_LONG_LONG
Antoine Pitrouc83ea132010-05-09 14:46:46 +000072#define T_LONGLONG 17
Martin v. Löwis96d743e2005-03-03 23:00:26 +000073#define T_ULONGLONG 18
74#endif /* HAVE_LONG_LONG */
Guido van Rossum6b705992001-12-04 16:23:42 +000075
Neal Norwitz766d8802007-08-03 06:46:29 +000076#define T_PYSSIZET 19 /* Py_ssize_t */
77
78
Guido van Rossumc299fc12001-09-17 19:28:08 +000079/* Flags */
Antoine Pitrouc83ea132010-05-09 14:46:46 +000080#define READONLY 1
81#define RO READONLY /* Shorthand */
82#define READ_RESTRICTED 2
Christian Heimese8954f82007-11-22 11:21:16 +000083#define PY_WRITE_RESTRICTED 4
Antoine Pitrouc83ea132010-05-09 14:46:46 +000084#define RESTRICTED (READ_RESTRICTED | PY_WRITE_RESTRICTED)
Guido van Rossumc299fc12001-09-17 19:28:08 +000085
Guido van Rossum3f5da241990-12-20 15:06:42 +000086
Guido van Rossum6f799372001-09-20 20:46:19 +000087/* Obsolete API, for binary backwards compatibility */
Tim Petersc3d12ac2005-12-24 06:03:06 +000088PyAPI_FUNC(PyObject *) PyMember_Get(const char *, struct memberlist *, const char *);
89PyAPI_FUNC(int) PyMember_Set(char *, struct memberlist *, const char *, PyObject *);
Guido van Rossuma3309961993-07-28 09:05:47 +000090
Guido van Rossum6f799372001-09-20 20:46:19 +000091/* Current API, use this */
Tim Petersc3d12ac2005-12-24 06:03:06 +000092PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);
Mark Hammond91a681d2002-08-12 07:21:58 +000093PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *);
Guido van Rossum6f799372001-09-20 20:46:19 +000094
95
Guido van Rossuma3309961993-07-28 09:05:47 +000096#ifdef __cplusplus
97}
98#endif
99#endif /* !Py_STRUCTMEMBER_H */