blob: 001e12130838df1b1057351daec8f77157b11043 [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 Rossumfd71b9e2000-06-30 23:50:40 +000013Copyright (c) 2000, BeOpen.com.
14Copyright (c) 1995-2000, Corporation for National Research Initiatives.
15Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
16All rights reserved.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000017
Guido van Rossumfd71b9e2000-06-30 23:50:40 +000018See the file "Misc/COPYRIGHT" for information on usage and
19redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000020
21******************************************************************/
22
Guido van Rossum3f5da241990-12-20 15:06:42 +000023/* Interface to map C struct members to Python object attributes */
24
Guido van Rossum5ebc0ca1994-10-20 22:03:08 +000025#ifdef HAVE_STDDEF_H
26#include <stddef.h> /* For offsetof */
27#endif
28
Guido van Rossum3f5da241990-12-20 15:06:42 +000029/* The offsetof() macro calculates the offset of a structure member
30 in its structure. Unfortunately this cannot be written down
31 portably, hence it is provided by a Standard C header file.
32 For pre-Standard C compilers, here is a version that usually works
33 (but watch out!): */
34
35#ifndef offsetof
36#define offsetof(type, member) ( (int) & ((type*)0) -> member )
37#endif
38
39/* An array of memberlist structures defines the name, type and offset
40 of selected members of a C structure. These can be read by
Guido van Rossumcaa63801995-01-12 11:45:45 +000041 PyMember_Get() and set by PyMember_Set() (except if their READONLY flag
Guido van Rossum3f5da241990-12-20 15:06:42 +000042 is set). The array must be terminated with an entry whose name
43 pointer is NULL. */
44
45struct memberlist {
46 char *name;
47 int type;
48 int offset;
49 int readonly;
50};
51
52/* Types */
53#define T_SHORT 0
54#define T_INT 1
55#define T_LONG 2
56#define T_FLOAT 3
57#define T_DOUBLE 4
58#define T_STRING 5
59#define T_OBJECT 6
Guido van Rossum00023951992-06-03 17:07:40 +000060/* XXX the ordering here is weird for binary compatibility */
61#define T_CHAR 7 /* 1-character string */
62#define T_BYTE 8 /* 8-bit signed int */
63/* unsigned variants: */
64#define T_UBYTE 9
65#define T_USHORT 10
66#define T_UINT 11
67#define T_ULONG 12
Guido van Rossum3f5da241990-12-20 15:06:42 +000068
Jack Jansen599f0d11994-12-14 13:04:05 +000069/* Added by Jack: strings contained in the structure */
70#define T_STRING_INPLACE 13
71#ifdef macintosh
72#define T_PSTRING 14 /* macintosh pascal-style counted string */
73#define T_PSTRING_INPLACE 15
74#endif /* macintosh */
75
Guido van Rossum3f5da241990-12-20 15:06:42 +000076/* Readonly flag */
77#define READONLY 1
78#define RO READONLY /* Shorthand */
79
Guido van Rossum43466ec1998-12-04 18:48:25 +000080DL_IMPORT(PyObject *) PyMember_Get Py_PROTO((char *, struct memberlist *, char *));
81DL_IMPORT(int) PyMember_Set Py_PROTO((char *, struct memberlist *, char *, PyObject *));
Guido van Rossuma3309961993-07-28 09:05:47 +000082
83#ifdef __cplusplus
84}
85#endif
86#endif /* !Py_STRUCTMEMBER_H */