Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 1 | #ifndef Py_STRUCTMEMBER_H |
| 2 | #define Py_STRUCTMEMBER_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 7 | /*********************************************************** |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 8 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 9 | The Netherlands. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 10 | |
| 11 | All Rights Reserved |
| 12 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame^] | 13 | Copyright (c) 2000, BeOpen.com. |
| 14 | Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
| 15 | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
| 16 | All rights reserved. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 17 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame^] | 18 | See the file "Misc/COPYRIGHT" for information on usage and |
| 19 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 20 | |
| 21 | ******************************************************************/ |
| 22 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 23 | /* Interface to map C struct members to Python object attributes */ |
| 24 | |
Guido van Rossum | 5ebc0ca | 1994-10-20 22:03:08 +0000 | [diff] [blame] | 25 | #ifdef HAVE_STDDEF_H |
| 26 | #include <stddef.h> /* For offsetof */ |
| 27 | #endif |
| 28 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 29 | /* 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 Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 41 | PyMember_Get() and set by PyMember_Set() (except if their READONLY flag |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 42 | is set). The array must be terminated with an entry whose name |
| 43 | pointer is NULL. */ |
| 44 | |
| 45 | struct 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 Rossum | 0002395 | 1992-06-03 17:07:40 +0000 | [diff] [blame] | 60 | /* 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 Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 68 | |
Jack Jansen | 599f0d1 | 1994-12-14 13:04:05 +0000 | [diff] [blame] | 69 | /* 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 Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 76 | /* Readonly flag */ |
| 77 | #define READONLY 1 |
| 78 | #define RO READONLY /* Shorthand */ |
| 79 | |
Guido van Rossum | 43466ec | 1998-12-04 18:48:25 +0000 | [diff] [blame] | 80 | DL_IMPORT(PyObject *) PyMember_Get Py_PROTO((char *, struct memberlist *, char *)); |
| 81 | DL_IMPORT(int) PyMember_Set Py_PROTO((char *, struct memberlist *, char *, PyObject *)); |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 82 | |
| 83 | #ifdef __cplusplus |
| 84 | } |
| 85 | #endif |
| 86 | #endif /* !Py_STRUCTMEMBER_H */ |