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