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 | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 13 | Permission to use, copy, modify, and distribute this software and its |
| 14 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 15 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 16 | both that copyright notice and this permission notice appear in |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 17 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 18 | Centrum or CWI or Corporation for National Research Initiatives or |
| 19 | CNRI not be used in advertising or publicity pertaining to |
| 20 | distribution of the software without specific, written prior |
| 21 | permission. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 22 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 23 | While CWI is the initial source for this software, a modified version |
| 24 | is made available by the Corporation for National Research Initiatives |
| 25 | (CNRI) at the Internet address ftp://ftp.python.org. |
| 26 | |
| 27 | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
| 28 | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
| 29 | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
| 30 | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
| 31 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 32 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 33 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 34 | PERFORMANCE OF THIS SOFTWARE. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 35 | |
| 36 | ******************************************************************/ |
| 37 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 38 | /* Interface to map C struct members to Python object attributes */ |
| 39 | |
Guido van Rossum | 5ebc0ca | 1994-10-20 22:03:08 +0000 | [diff] [blame] | 40 | #ifdef HAVE_STDDEF_H |
| 41 | #include <stddef.h> /* For offsetof */ |
| 42 | #endif |
| 43 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 44 | /* 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 Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 56 | 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] | 57 | is set). The array must be terminated with an entry whose name |
| 58 | pointer is NULL. */ |
| 59 | |
| 60 | struct 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 Rossum | 0002395 | 1992-06-03 17:07:40 +0000 | [diff] [blame] | 75 | /* 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 Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 83 | |
Jack Jansen | 599f0d1 | 1994-12-14 13:04:05 +0000 | [diff] [blame] | 84 | /* 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 Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 91 | /* Readonly flag */ |
| 92 | #define READONLY 1 |
| 93 | #define RO READONLY /* Shorthand */ |
| 94 | |
Guido van Rossum | 43466ec | 1998-12-04 18:48:25 +0000 | [diff] [blame^] | 95 | DL_IMPORT(PyObject *) PyMember_Get Py_PROTO((char *, struct memberlist *, char *)); |
| 96 | 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] | 97 | |
| 98 | #ifdef __cplusplus |
| 99 | } |
| 100 | #endif |
| 101 | #endif /* !Py_STRUCTMEMBER_H */ |