~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Include/structmember.h

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef Py_STRUCTMEMBER_H
 
2
#define Py_STRUCTMEMBER_H
 
3
#ifdef __cplusplus
 
4
extern "C" {
 
5
#endif
 
6
 
 
7
 
 
8
/* Interface to map C struct members to Python object attributes */
 
9
 
 
10
#include <stddef.h> /* For offsetof */
 
11
 
 
12
/* The offsetof() macro calculates the offset of a structure member
 
13
   in its structure.  Unfortunately this cannot be written down
 
14
   portably, hence it is provided by a Standard C header file.
 
15
   For pre-Standard C compilers, here is a version that usually works
 
16
   (but watch out!): */
 
17
 
 
18
#ifndef offsetof
 
19
#define offsetof(type, member) ( (int) & ((type*)0) -> member )
 
20
#endif
 
21
 
 
22
/* An array of PyMemberDef structures defines the name, type and offset
 
23
   of selected members of a C structure.  These can be read by
 
24
   PyMember_GetOne() and set by PyMember_SetOne() (except if their READONLY
 
25
   flag is set).  The array must be terminated with an entry whose name
 
26
   pointer is NULL. */
 
27
 
 
28
typedef struct PyMemberDef {
 
29
        /* Current version, use this */
 
30
        char *name;
 
31
        int type;
 
32
        Py_ssize_t offset;
 
33
        int flags;
 
34
        char *doc;
 
35
} PyMemberDef;
 
36
 
 
37
/* Types */
 
38
#define T_SHORT         0
 
39
#define T_INT           1
 
40
#define T_LONG          2
 
41
#define T_FLOAT         3
 
42
#define T_DOUBLE        4
 
43
#define T_STRING        5
 
44
#define T_OBJECT        6
 
45
/* XXX the ordering here is weird for binary compatibility */
 
46
#define T_CHAR          7       /* 1-character string */
 
47
#define T_BYTE          8       /* 8-bit signed int */
 
48
/* unsigned variants: */
 
49
#define T_UBYTE         9
 
50
#define T_USHORT        10
 
51
#define T_UINT          11
 
52
#define T_ULONG         12
 
53
 
 
54
/* Added by Jack: strings contained in the structure */
 
55
#define T_STRING_INPLACE        13
 
56
 
 
57
/* Added by Lillo: bools contained in the structure (assumed char) */
 
58
#define T_BOOL          14
 
59
 
 
60
#define T_OBJECT_EX     16      /* Like T_OBJECT, but raises AttributeError
 
61
                                   when the value is NULL, instead of
 
62
                                   converting to None. */
 
63
#ifdef HAVE_LONG_LONG
 
64
#define T_LONGLONG      17  
 
65
#define T_ULONGLONG     18
 
66
#endif /* HAVE_LONG_LONG */
 
67
 
 
68
#define T_PYSSIZET      19      /* Py_ssize_t */
 
69
#define T_NONE          20      /* Value is always None */
 
70
 
 
71
 
 
72
/* Flags */
 
73
#define READONLY        1
 
74
#define READ_RESTRICTED 2
 
75
#define PY_WRITE_RESTRICTED 4
 
76
#define RESTRICTED      (READ_RESTRICTED | PY_WRITE_RESTRICTED)
 
77
 
 
78
 
 
79
/* Current API, use this */
 
80
PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);
 
81
PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *);
 
82
 
 
83
 
 
84
#ifdef __cplusplus
 
85
}
 
86
#endif
 
87
#endif /* !Py_STRUCTMEMBER_H */