blob: 1dd763bd6167029996c889a9a980884106194474 [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 Rossum5799b521995-01-04 19:06:22 +00008Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
9The Netherlands.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000010
11 All Rights Reserved
12
Guido van Rossumd266eb41996-10-25 14:44:06 +000013Permission to use, copy, modify, and distribute this software and its
14documentation for any purpose and without fee is hereby granted,
Guido van Rossumf70e43a1991-02-19 12:39:46 +000015provided that the above copyright notice appear in all copies and that
Guido van Rossumd266eb41996-10-25 14:44:06 +000016both that copyright notice and this permission notice appear in
Guido van Rossumf70e43a1991-02-19 12:39:46 +000017supporting documentation, and that the names of Stichting Mathematisch
Guido van Rossumd266eb41996-10-25 14:44:06 +000018Centrum or CWI or Corporation for National Research Initiatives or
19CNRI not be used in advertising or publicity pertaining to
20distribution of the software without specific, written prior
21permission.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000022
Guido van Rossumd266eb41996-10-25 14:44:06 +000023While CWI is the initial source for this software, a modified version
24is made available by the Corporation for National Research Initiatives
25(CNRI) at the Internet address ftp://ftp.python.org.
26
27STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
28REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
29MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
30CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
31DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
32PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
33TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
34PERFORMANCE OF THIS SOFTWARE.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000035
36******************************************************************/
37
Guido van Rossum3f5da241990-12-20 15:06:42 +000038/* Interface to map C struct members to Python object attributes */
39
Guido van Rossum5ebc0ca1994-10-20 22:03:08 +000040#ifdef HAVE_STDDEF_H
41#include <stddef.h> /* For offsetof */
42#endif
43
Guido van Rossum3f5da241990-12-20 15:06:42 +000044/* The offsetof() macro calculates the offset of a structure member
45 in its structure. Unfortunately this cannot be written down
46 portably, hence it is provided by a Standard C header file.
47 For pre-Standard C compilers, here is a version that usually works
48 (but watch out!): */
49
50#ifndef offsetof
51#define offsetof(type, member) ( (int) & ((type*)0) -> member )
52#endif
53
54/* An array of memberlist structures defines the name, type and offset
55 of selected members of a C structure. These can be read by
Guido van Rossumcaa63801995-01-12 11:45:45 +000056 PyMember_Get() and set by PyMember_Set() (except if their READONLY flag
Guido van Rossum3f5da241990-12-20 15:06:42 +000057 is set). The array must be terminated with an entry whose name
58 pointer is NULL. */
59
60struct memberlist {
61 char *name;
62 int type;
63 int offset;
64 int readonly;
65};
66
67/* Types */
68#define T_SHORT 0
69#define T_INT 1
70#define T_LONG 2
71#define T_FLOAT 3
72#define T_DOUBLE 4
73#define T_STRING 5
74#define T_OBJECT 6
Guido van Rossum00023951992-06-03 17:07:40 +000075/* XXX the ordering here is weird for binary compatibility */
76#define T_CHAR 7 /* 1-character string */
77#define T_BYTE 8 /* 8-bit signed int */
78/* unsigned variants: */
79#define T_UBYTE 9
80#define T_USHORT 10
81#define T_UINT 11
82#define T_ULONG 12
Guido van Rossum3f5da241990-12-20 15:06:42 +000083
Jack Jansen599f0d11994-12-14 13:04:05 +000084/* Added by Jack: strings contained in the structure */
85#define T_STRING_INPLACE 13
86#ifdef macintosh
87#define T_PSTRING 14 /* macintosh pascal-style counted string */
88#define T_PSTRING_INPLACE 15
89#endif /* macintosh */
90
Guido van Rossum3f5da241990-12-20 15:06:42 +000091/* Readonly flag */
92#define READONLY 1
93#define RO READONLY /* Shorthand */
94
Guido van Rossum43466ec1998-12-04 18:48:25 +000095DL_IMPORT(PyObject *) PyMember_Get Py_PROTO((char *, struct memberlist *, char *));
96DL_IMPORT(int) PyMember_Set Py_PROTO((char *, struct memberlist *, char *, PyObject *));
Guido van Rossuma3309961993-07-28 09:05:47 +000097
98#ifdef __cplusplus
99}
100#endif
101#endif /* !Py_STRUCTMEMBER_H */