annotate Include/object.h @ 12357:5b59ea41db4e legacy-trunk

Install the docs (with fewer rules). Add descriptions for the system variables.
author Guido van Rossum <guido@python.org>
date Mon, 10 Apr 2000 19:36:27 +0000
parents 8dc0918ae2c2
children ec6b6ca5d111
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
1 #ifndef Py_OBJECT_H
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
2 #define Py_OBJECT_H
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
3 #ifdef __cplusplus
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
4 extern "C" {
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
5 #endif
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
6
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
7 /***********************************************************
2058
508036dbba3b Added 1995 copyright.
Guido van Rossum <guido@python.org>
parents: 1794
diff changeset
8 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
508036dbba3b Added 1995 copyright.
Guido van Rossum <guido@python.org>
parents: 1794
diff changeset
9 The Netherlands.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
10
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
11 All Rights Reserved
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
12
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
13 Permission to use, copy, modify, and distribute this software and its
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
14 documentation for any purpose and without fee is hereby granted,
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
15 provided that the above copyright notice appear in all copies and that
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
16 both that copyright notice and this permission notice appear in
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
17 supporting documentation, and that the names of Stichting Mathematisch
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
18 Centrum or CWI or Corporation for National Research Initiatives or
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
19 CNRI not be used in advertising or publicity pertaining to
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
20 distribution of the software without specific, written prior
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
21 permission.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
22
4503
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
23 While CWI is the initial source for this software, a modified version
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
24 is made available by the Corporation for National Research Initiatives
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
25 (CNRI) at the Internet address ftp://ftp.python.org.
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
26
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
27 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
28 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
29 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
30 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
31 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
32 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
33 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
65d2d8e67da3 New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents: 4001
diff changeset
34 PERFORMANCE OF THIS SOFTWARE.
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
35
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
36 ******************************************************************/
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
37
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 /* Object and type object interface */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 /*
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 Objects are structures allocated on the heap. Special rules apply to
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 the use of objects to ensure they are properly garbage-collected.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 Objects are never allocated statically or on the stack; they must be
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 accessed through special macros and functions only. (Type objects are
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 exceptions to the first rule; the standard types are represented by
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 statically initialized type objects.)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 An object has a 'reference count' that is increased or decreased when a
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 pointer to the object is copied or deleted; when the reference count
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 reaches zero there are no references to the object left and it can be
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 removed from the heap.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
52
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 An object has a 'type' that determines what it represents and what kind
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 of data it contains. An object's type is fixed when it is created.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 Types themselves are represented as objects; an object contains a
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 pointer to the corresponding type object. The type itself has a type
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 pointer pointing to the object representing the type 'type', which
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 contains a pointer to itself!).
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 Objects do not float around in memory; once allocated an object keeps
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 the same size and address. Objects that must hold variable-size data
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 can contain pointers to variable-size parts of the object. Not all
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 objects of the same type have the same size; but the size cannot change
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 after allocation. (These restrictions are made so a reference to an
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 object can be simply a pointer -- moving an object would require
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 updating all the pointers, and changing an object's size would require
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 moving it if there was another object right next to it.)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
68
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
69 Objects are always accessed through pointers of the type 'PyObject *'.
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
70 The type 'PyObject' is a structure that only contains the reference count
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 and the type pointer. The actual memory allocated for an object
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 contains other data that can only be accessed after casting the pointer
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 to a pointer to a longer structure type. This longer type must start
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
74 with the reference count and type fields; the macro PyObject_HEAD should be
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 used for this (to accomodate for future changes). The implementation
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 of a particular object type can cast the object pointer to the proper
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 type and back.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
78
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 A standard interface exists for objects that contain an array of items
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 whose size is determined when the object is allocated.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
82
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
83 #ifdef Py_DEBUG
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
84
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
85 /* Turn on heavy reference debugging */
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
86 #define Py_TRACE_REFS
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
87
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
88 /* Turn on reference counting */
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
89 #define Py_REF_DEBUG
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
90
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
91 #endif /* Py_DEBUG */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
93 #ifdef Py_TRACE_REFS
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
94 #define PyObject_HEAD \
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 struct _object *_ob_next, *_ob_prev; \
62
fffd1286c882 Be more careful with negative reference counts.
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
96 int ob_refcnt; \
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 struct _typeobject *ob_type;
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
98 #define PyObject_HEAD_INIT(type) 0, 0, 1, type,
3573
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
99 #else /* !Py_TRACE_REFS */
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
100 #define PyObject_HEAD \
2058
508036dbba3b Added 1995 copyright.
Guido van Rossum <guido@python.org>
parents: 1794
diff changeset
101 int ob_refcnt; \
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 struct _typeobject *ob_type;
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
103 #define PyObject_HEAD_INIT(type) 1, type,
3573
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
104 #endif /* !Py_TRACE_REFS */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
105
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
106 #define PyObject_VAR_HEAD \
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
107 PyObject_HEAD \
2058
508036dbba3b Added 1995 copyright.
Guido van Rossum <guido@python.org>
parents: 1794
diff changeset
108 int ob_size; /* Number of items in variable part */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
109
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 typedef struct _object {
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
111 PyObject_HEAD
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
112 } PyObject;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
113
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 typedef struct {
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
115 PyObject_VAR_HEAD
5535
20c2b715188e Oops, another forgotten renaming: varobject -> PyVarObject.
Guido van Rossum <guido@python.org>
parents: 5410
diff changeset
116 } PyVarObject;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
117
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
118
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 /*
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 Type objects contain a string containing the type name (to help somewhat
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 in debugging), the allocation parameters (see newobj() and newvarobj()),
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 and methods for accessing objects of the type. Methods are optional,a
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 nil pointer meaning that particular kind of access is not available for
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
124 this type. The Py_DECREF() macro uses the tp_dealloc method without
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 checking for a nil pointer; it should always be implemented except if
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 the implementation can guarantee that the reference count will never
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 reach zero (e.g., for type objects).
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
128
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 NB: the methods for certain type groups are now contained in separate
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 method blocks.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
132
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
133 typedef PyObject * (*unaryfunc) Py_PROTO((PyObject *));
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
134 typedef PyObject * (*binaryfunc) Py_PROTO((PyObject *, PyObject *));
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
135 typedef PyObject * (*ternaryfunc) Py_PROTO((PyObject *, PyObject *, PyObject *));
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
136 typedef int (*inquiry) Py_PROTO((PyObject *));
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
137 typedef int (*coercion) Py_PROTO((PyObject **, PyObject **));
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
138 typedef PyObject *(*intargfunc) Py_PROTO((PyObject *, int));
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
139 typedef PyObject *(*intintargfunc) Py_PROTO((PyObject *, int, int));
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
140 typedef int(*intobjargproc) Py_PROTO((PyObject *, int, PyObject *));
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
141 typedef int(*intintobjargproc) Py_PROTO((PyObject *, int, int, PyObject *));
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
142 typedef int(*objobjargproc) Py_PROTO((PyObject *, PyObject *, PyObject *));
5410
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
143 typedef int (*getreadbufferproc) Py_PROTO((PyObject *, int, void **));
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
144 typedef int (*getwritebufferproc) Py_PROTO((PyObject *, int, void **));
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
145 typedef int (*getsegcountproc) Py_PROTO((PyObject *, int *));
9304
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
146 typedef int (*getcharbufferproc) Py_PROTO((PyObject *, int, const char **));
11867
06104bcf06a6 Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This adds
Guido van Rossum <guido@python.org>
parents: 11673
diff changeset
147 typedef int (*objobjproc) Py_PROTO((PyObject *, PyObject *));
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
148
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 typedef struct {
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
150 binaryfunc nb_add;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
151 binaryfunc nb_subtract;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
152 binaryfunc nb_multiply;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
153 binaryfunc nb_divide;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
154 binaryfunc nb_remainder;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
155 binaryfunc nb_divmod;
1770
b0dca2972b2b * Objects/{int,long,float}object.c, Include/object.h,
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
156 ternaryfunc nb_power;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
157 unaryfunc nb_negative;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
158 unaryfunc nb_positive;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
159 unaryfunc nb_absolute;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
160 inquiry nb_nonzero;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
161 unaryfunc nb_invert;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
162 binaryfunc nb_lshift;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
163 binaryfunc nb_rshift;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
164 binaryfunc nb_and;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
165 binaryfunc nb_xor;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
166 binaryfunc nb_or;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
167 coercion nb_coerce;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
168 unaryfunc nb_int;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
169 unaryfunc nb_long;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
170 unaryfunc nb_float;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
171 unaryfunc nb_oct;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
172 unaryfunc nb_hex;
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
173 } PyNumberMethods;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
174
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 typedef struct {
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
176 inquiry sq_length;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
177 binaryfunc sq_concat;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
178 intargfunc sq_repeat;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
179 intargfunc sq_item;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
180 intintargfunc sq_slice;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
181 intobjargproc sq_ass_item;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
182 intintobjargproc sq_ass_slice;
11867
06104bcf06a6 Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This adds
Guido van Rossum <guido@python.org>
parents: 11673
diff changeset
183 objobjproc sq_contains;
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
184 } PySequenceMethods;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
185
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
186 typedef struct {
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
187 inquiry mp_length;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
188 binaryfunc mp_subscript;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
189 objobjargproc mp_ass_subscript;
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
190 } PyMappingMethods;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
191
5410
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
192 typedef struct {
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
193 getreadbufferproc bf_getreadbuffer;
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
194 getwritebufferproc bf_getwritebuffer;
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
195 getsegcountproc bf_getsegcount;
9304
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
196 getcharbufferproc bf_getcharbuffer;
5410
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
197 } PyBufferProcs;
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
198
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
199
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
200 typedef void (*destructor) Py_PROTO((PyObject *));
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
201 typedef int (*printfunc) Py_PROTO((PyObject *, FILE *, int));
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
202 typedef PyObject *(*getattrfunc) Py_PROTO((PyObject *, char *));
3983
44902516614a Added tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents: 3605
diff changeset
203 typedef PyObject *(*getattrofunc) Py_PROTO((PyObject *, PyObject *));
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
204 typedef int (*setattrfunc) Py_PROTO((PyObject *, char *, PyObject *));
3983
44902516614a Added tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents: 3605
diff changeset
205 typedef int (*setattrofunc) Py_PROTO((PyObject *, PyObject *, PyObject *));
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
206 typedef int (*cmpfunc) Py_PROTO((PyObject *, PyObject *));
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
207 typedef PyObject *(*reprfunc) Py_PROTO((PyObject *));
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
208 typedef long (*hashfunc) Py_PROTO((PyObject *));
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
209
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 typedef struct _typeobject {
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
211 PyObject_VAR_HEAD
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 char *tp_name; /* For printing */
2058
508036dbba3b Added 1995 copyright.
Guido van Rossum <guido@python.org>
parents: 1794
diff changeset
213 int tp_basicsize, tp_itemsize; /* For allocation */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
214
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 /* Methods to implement standard operations */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
216
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
217 destructor tp_dealloc;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
218 printfunc tp_print;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
219 getattrfunc tp_getattr;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
220 setattrfunc tp_setattr;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
221 cmpfunc tp_compare;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
222 reprfunc tp_repr;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
223
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 /* Method suites for standard classes */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
225
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
226 PyNumberMethods *tp_as_number;
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
227 PySequenceMethods *tp_as_sequence;
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
228 PyMappingMethods *tp_as_mapping;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1049
diff changeset
229
12026
8dc0918ae2c2 Updated comment: in PyTypeObject:
Fred Drake <fdrake@acm.org>
parents: 11999
diff changeset
230 /* More standard operations (here for binary compatibility) */
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1049
diff changeset
231
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
232 hashfunc tp_hash;
2841
64928f6a8e80 keyword arguments and faster function calls
Guido van Rossum <guido@python.org>
parents: 2669
diff changeset
233 ternaryfunc tp_call;
2071
048e91a59c75 new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
234 reprfunc tp_str;
3983
44902516614a Added tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents: 3605
diff changeset
235 getattrofunc tp_getattro;
44902516614a Added tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents: 3605
diff changeset
236 setattrofunc tp_setattro;
2071
048e91a59c75 new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
237
5410
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
238 /* Functions to access object as input/output buffer */
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
239 PyBufferProcs *tp_as_buffer;
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
240
9304
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
241 /* Flags to define presence of optional/expanded features */
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
242 long tp_flags;
2071
048e91a59c75 new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
243
048e91a59c75 new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
244 char *tp_doc; /* Documentation string */
048e91a59c75 new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
245
8124
bd744af6845f Add new spares to the end of the type object struct.
Guido van Rossum <guido@python.org>
parents: 7983
diff changeset
246 /* More spares */
bd744af6845f Add new spares to the end of the type object struct.
Guido van Rossum <guido@python.org>
parents: 7983
diff changeset
247 long tp_xxx5;
bd744af6845f Add new spares to the end of the type object struct.
Guido van Rossum <guido@python.org>
parents: 7983
diff changeset
248 long tp_xxx6;
bd744af6845f Add new spares to the end of the type object struct.
Guido van Rossum <guido@python.org>
parents: 7983
diff changeset
249 long tp_xxx7;
bd744af6845f Add new spares to the end of the type object struct.
Guido van Rossum <guido@python.org>
parents: 7983
diff changeset
250 long tp_xxx8;
bd744af6845f Add new spares to the end of the type object struct.
Guido van Rossum <guido@python.org>
parents: 7983
diff changeset
251
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
252 #ifdef COUNT_ALLOCS
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
253 /* these must be last */
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
254 int tp_alloc;
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
255 int tp_free;
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
256 int tp_maxalloc;
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
257 struct _typeobject *tp_next;
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
258 #endif
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
259 } PyTypeObject;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
260
2669
34eefa226709 DL_IMPORT needs an argument.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2664
diff changeset
261 extern DL_IMPORT(PyTypeObject) PyType_Type; /* The type of type objects */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
262
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
263 #define PyType_Check(op) ((op)->ob_type == &PyType_Type)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
264
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
265 /* Generic operations on objects */
9586
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
266 extern DL_IMPORT(int) PyObject_Print Py_PROTO((PyObject *, FILE *, int));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
267 extern DL_IMPORT(PyObject *) PyObject_Repr Py_PROTO((PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
268 extern DL_IMPORT(PyObject *) PyObject_Str Py_PROTO((PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
269 extern DL_IMPORT(int) PyObject_Compare Py_PROTO((PyObject *, PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
270 extern DL_IMPORT(PyObject *) PyObject_GetAttrString Py_PROTO((PyObject *, char *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
271 extern DL_IMPORT(int) PyObject_SetAttrString Py_PROTO((PyObject *, char *, PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
272 extern DL_IMPORT(int) PyObject_HasAttrString Py_PROTO((PyObject *, char *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
273 extern DL_IMPORT(PyObject *) PyObject_GetAttr Py_PROTO((PyObject *, PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
274 extern DL_IMPORT(int) PyObject_SetAttr Py_PROTO((PyObject *, PyObject *, PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
275 extern DL_IMPORT(int) PyObject_HasAttr Py_PROTO((PyObject *, PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
276 extern DL_IMPORT(long) PyObject_Hash Py_PROTO((PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
277 extern DL_IMPORT(int) PyObject_IsTrue Py_PROTO((PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
278 extern DL_IMPORT(int) PyObject_Not Py_PROTO((PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
279 extern DL_IMPORT(int) PyCallable_Check Py_PROTO((PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
280 extern DL_IMPORT(int) PyNumber_Coerce Py_PROTO((PyObject **, PyObject **));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
281 extern DL_IMPORT(int) PyNumber_CoerceEx Py_PROTO((PyObject **, PyObject **));
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
282
7983
068303f925ea Add prototypes for Py_Repr{Enter,Leave}.
Guido van Rossum <guido@python.org>
parents: 7935
diff changeset
283 /* Helpers for printing recursive container types */
9586
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
284 extern DL_IMPORT(int) Py_ReprEnter Py_PROTO((PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
285 extern DL_IMPORT(void) Py_ReprLeave Py_PROTO((PyObject *));
7983
068303f925ea Add prototypes for Py_Repr{Enter,Leave}.
Guido van Rossum <guido@python.org>
parents: 7935
diff changeset
286
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 /* Flag bits for printing: */
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
288 #define Py_PRINT_RAW 1 /* No string quotes etc. */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
289
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 /*
9304
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
291
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
292 Type flags (tp_flags)
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
293
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
294 These flags are used to extend the type structure in a backwards-compatible
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
295 fashion. Extensions can use the flags to indicate (and test) when a given
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
296 type structure contains a new feature. The Python core will use these when
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
297 introducing new functionality between major revisions (to avoid mid-version
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
298 changes in the PYTHON_API_VERSION).
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
299
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
300 Arbitration of the flag bit positions will need to be coordinated among
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
301 all extension writers who publically release their extensions (this will
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
302 be fewer than you might expect!)..
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
303
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
304 Python 1.5.2 introduced the bf_getcharbuffer slot into PyBufferProcs.
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
305
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
306 Type definitions should use Py_TPFLAGS_DEFAULT for their tp_flags value.
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
307
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
308 Code can use PyType_HasFeature(type_ob, flag_value) to test whether the
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
309 given type object has a specified feature.
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
310
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
311 */
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
312
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
313 /* PyBufferProcs contains bf_getcharbuffer */
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
314 #define Py_TPFLAGS_HAVE_GETCHARBUFFER (1L<<0)
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
315
11867
06104bcf06a6 Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This adds
Guido van Rossum <guido@python.org>
parents: 11673
diff changeset
316 /* PySequenceMethods contains sq_contains */
06104bcf06a6 Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This adds
Guido van Rossum <guido@python.org>
parents: 11673
diff changeset
317 #define Py_TPFLAGS_HAVE_SEQUENCE_IN (1L<<1)
06104bcf06a6 Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This adds
Guido van Rossum <guido@python.org>
parents: 11673
diff changeset
318
06104bcf06a6 Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This adds
Guido van Rossum <guido@python.org>
parents: 11673
diff changeset
319 #define Py_TPFLAGS_DEFAULT (Py_TPFLAGS_HAVE_GETCHARBUFFER | \
06104bcf06a6 Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This adds
Guido van Rossum <guido@python.org>
parents: 11673
diff changeset
320 Py_TPFLAGS_HAVE_SEQUENCE_IN)
9304
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
321
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
322 #define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
323
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
324
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
325 /*
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
326 The macros Py_INCREF(op) and Py_DECREF(op) are used to increment or decrement
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
327 reference counts. Py_DECREF calls the object's deallocator function; for
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 objects that don't contain references to other objects or heap memory
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 this can be the standard function free(). Both macros can be used
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 whereever a void expression is allowed. The argument shouldn't be a
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
331 NIL pointer. The macro _Py_NewReference(op) is used only to initialize
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
332 reference counts to 1; it is defined here for convenience.
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
333
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 We assume that the reference count field can never overflow; this can
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 be proven when the size of the field is the same as the pointer size
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 but even with a 16-bit reference count field it is pretty unlikely so
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 we ignore the possibility. (If you are paranoid, make it a long.)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
338
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 Type objects should never be deallocated; the type pointer in an object
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
340 is not considered to be a reference to the type object, to save
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 complications in the deallocation function. (This is actually a
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 decision that's up to the implementer of each new type so if you want,
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
343 you can count such references to the type object.)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
344
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
345 *** WARNING*** The Py_DECREF macro must have a side-effect-free argument
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 since it may evaluate its argument multiple times. (The alternative
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
347 would be to mace it a proper function or assign it to a global temporary
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 variable first, both of which are slower; and in a multi-threaded
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 environment the global variable trick is not safe.)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
351
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
352 #ifdef Py_TRACE_REFS
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
353 #ifndef Py_REF_DEBUG
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
354 #define Py_REF_DEBUG
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 #endif
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 #endif
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
357
4001
1ed773e15936 Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents: 3983
diff changeset
358 #ifdef Py_TRACE_REFS
9586
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
359 extern DL_IMPORT(void) _Py_Dealloc Py_PROTO((PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
360 extern DL_IMPORT(void) _Py_NewReference Py_PROTO((PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
361 extern DL_IMPORT(void) _Py_ForgetReference Py_PROTO((PyObject *));
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
362 extern DL_IMPORT(void) _Py_PrintReferences Py_PROTO((FILE *));
11673
5e6e9e893acd The rest of the changes by Trent Mick and Dale Nagata for warning-free
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
363 extern DL_IMPORT(void) _Py_ResetReferences Py_PROTO((void));
4001
1ed773e15936 Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents: 3983
diff changeset
364 #endif
1ed773e15936 Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents: 3983
diff changeset
365
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
366 #ifndef Py_TRACE_REFS
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
367 #ifdef COUNT_ALLOCS
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
368 #define _Py_Dealloc(op) ((op)->ob_type->tp_free++, (*(op)->ob_type->tp_dealloc)((PyObject *)(op)))
2638
68c7a0a61fd5 Also count UNREF's as freeing an object (only relevant when
Sjoerd Mullender <sjoerd@acm.org>
parents: 2612
diff changeset
369 #define _Py_ForgetReference(op) ((op)->ob_type->tp_free++)
4001
1ed773e15936 Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents: 3983
diff changeset
370 #else /* !COUNT_ALLOCS */
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
371 #define _Py_Dealloc(op) (*(op)->ob_type->tp_dealloc)((PyObject *)(op))
2638
68c7a0a61fd5 Also count UNREF's as freeing an object (only relevant when
Sjoerd Mullender <sjoerd@acm.org>
parents: 2612
diff changeset
372 #define _Py_ForgetReference(op) /*empty*/
4001
1ed773e15936 Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents: 3983
diff changeset
373 #endif /* !COUNT_ALLOCS */
1ed773e15936 Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents: 3983
diff changeset
374 #endif /* !Py_TRACE_REFS */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
375
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
376 #ifdef COUNT_ALLOCS
9586
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
377 extern DL_IMPORT(void) inc_count Py_PROTO((PyTypeObject *));
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
378 #endif
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
379
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
380 #ifdef Py_REF_DEBUG
3573
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
381
9586
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
382 extern DL_IMPORT(long) _Py_RefTotal;
3573
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
383
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
384 #ifndef Py_TRACE_REFS
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
385 #ifdef COUNT_ALLOCS
2612
ca6b60d4ea90 fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents: 2436
diff changeset
386 #define _Py_NewReference(op) (inc_count((op)->ob_type), _Py_RefTotal++, (op)->ob_refcnt = 1)
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
387 #else
2612
ca6b60d4ea90 fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents: 2436
diff changeset
388 #define _Py_NewReference(op) (_Py_RefTotal++, (op)->ob_refcnt = 1)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 #endif
3573
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
390 #endif /* !Py_TRACE_REFS */
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
391
2612
ca6b60d4ea90 fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents: 2436
diff changeset
392 #define Py_INCREF(op) (_Py_RefTotal++, (op)->ob_refcnt++)
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
393 #define Py_DECREF(op) \
2612
ca6b60d4ea90 fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents: 2436
diff changeset
394 if (--_Py_RefTotal, --(op)->ob_refcnt != 0) \
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 ; \
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 else \
5943
ac877c4768e1 Add a cast to the call to _Py_Dealloc in the expanded version of
Guido van Rossum <guido@python.org>
parents: 5535
diff changeset
397 _Py_Dealloc((PyObject *)(op))
3573
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
398 #else /* !Py_REF_DEBUG */
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
399
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
400 #ifdef COUNT_ALLOCS
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
401 #define _Py_NewReference(op) (inc_count((op)->ob_type), (op)->ob_refcnt = 1)
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
402 #else
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
403 #define _Py_NewReference(op) ((op)->ob_refcnt = 1)
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
404 #endif
3573
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
405
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
406 #define Py_INCREF(op) ((op)->ob_refcnt++)
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
407 #define Py_DECREF(op) \
2058
508036dbba3b Added 1995 copyright.
Guido van Rossum <guido@python.org>
parents: 1794
diff changeset
408 if (--(op)->ob_refcnt != 0) \
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
409 ; \
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
410 else \
5943
ac877c4768e1 Add a cast to the call to _Py_Dealloc in the expanded version of
Guido van Rossum <guido@python.org>
parents: 5535
diff changeset
411 _Py_Dealloc((PyObject *)(op))
3573
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
412 #endif /* !Py_REF_DEBUG */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
413
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
414 /* Macros to use in case the object pointer may be NULL: */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
415
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
416 #define Py_XINCREF(op) if ((op) == NULL) ; else Py_INCREF(op)
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
417 #define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
418
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
419 /* Definition of NULL, so you don't have to include <stdio.h> */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
420
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
421 #ifndef NULL
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
422 #define NULL 0
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 #endif
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
424
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
425
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
426 /*
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
427 _Py_NoneStruct is an object of undefined type which can be used in contexts
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 where NULL (nil) is not suitable (since NULL often means 'error').
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
429
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
430 Don't forget to apply Py_INCREF() when returning this value!!!
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
431 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
432
2669
34eefa226709 DL_IMPORT needs an argument.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2664
diff changeset
433 extern DL_IMPORT(PyObject) _Py_NoneStruct; /* Don't use this directly */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
434
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
435 #define Py_None (&_Py_NoneStruct)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
436
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
437
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
438 /*
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
439 A common programming style in Python requires the forward declaration
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
440 of static, initialized structures, e.g. for a type object that is used
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
441 by the functions whose address must be used in the initializer.
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
442 Some compilers (notably SCO ODT 3.0, I seem to remember early AIX as
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
443 well) botch this if you use the static keyword for both declarations
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
444 (they allocate two objects, and use the first, uninitialized one until
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
445 the second declaration is encountered). Therefore, the forward
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
446 declaration should use the 'forwardstatic' keyword. This expands to
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
447 static on most systems, but to extern on a few. The actual storage
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
448 and name will still be static because the second declaration is
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
449 static, so no linker visible symbols will be generated. (Standard C
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
450 compilers take offense to the extern forward declaration of a static
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
451 object, so I can't just put extern in all cases. :-( )
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
452 */
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
453
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
454 #ifdef BAD_STATIC_FORWARD
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
455 #define staticforward extern
2422
f4f71ebea53f change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents: 2364
diff changeset
456 #ifdef __SC__
f4f71ebea53f change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents: 2364
diff changeset
457 #define statichere
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
458 #else
2422
f4f71ebea53f change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents: 2364
diff changeset
459 #define statichere static
f4f71ebea53f change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents: 2364
diff changeset
460 #endif /* __SC__ */
f4f71ebea53f change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents: 2364
diff changeset
461 #else /* !BAD_STATIC_FORWARD */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
462 #define staticforward static
2422
f4f71ebea53f change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents: 2364
diff changeset
463 #define statichere static
f4f71ebea53f change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents: 2364
diff changeset
464 #endif /* !BAD_STATIC_FORWARD */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
465
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
466
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
467 /*
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
468 More conventions
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
469 ================
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
470
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
471 Argument Checking
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
472 -----------------
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
473
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
474 Functions that take objects as arguments normally don't check for nil
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
475 arguments, but they do check the type of the argument, and return an
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
476 error if the function doesn't apply to the type.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
477
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
478 Failure Modes
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
479 -------------
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
480
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
481 Functions may fail for a variety of reasons, including running out of
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
482 memory. This is communicated to the caller in two ways: an error string
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
483 is set (see errors.h), and the function result differs: functions that
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
484 normally return a pointer return NULL for failure, functions returning
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
485 an integer return -1 (which could be a legal return value too!), and
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
486 other functions return 0 for success and -1 for failure.
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
487 Callers should always check for errors before using the result.
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
488
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
489 Reference Counts
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
490 ----------------
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
491
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
492 It takes a while to get used to the proper usage of reference counts.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
493
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
494 Functions that create an object set the reference count to 1; such new
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
495 objects must be stored somewhere or destroyed again with Py_DECREF().
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
496 Functions that 'store' objects such as PyTuple_SetItem() and
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
497 PyDict_SetItemString()
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
498 don't increment the reference count of the object, since the most
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
499 frequent use is to store a fresh object. Functions that 'retrieve'
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
500 objects such as PyTuple_GetItem() and PyDict_GetItemString() also
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
501 don't increment
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
502 the reference count, since most frequently the object is only looked at
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
503 quickly. Thus, to retrieve an object and store it again, the caller
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
504 must call Py_INCREF() explicitly.
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
505
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
506 NOTE: functions that 'consume' a reference count like
6244
5ab21d1b61d8 Fix in trailing comment: PyDict_SetItemString() does *not* consume a reference
Fred Drake <fdrake@acm.org>
parents: 5943
diff changeset
507 PyList_SetItemString() even consume the reference if the object wasn't
5ab21d1b61d8 Fix in trailing comment: PyDict_SetItemString() does *not* consume a reference
Fred Drake <fdrake@acm.org>
parents: 5943
diff changeset
508 stored, to simplify error handling.
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
509
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
510 It seems attractive to make other functions that take an object as
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
511 argument consume a reference count; however this may quickly get
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
512 confusing (even the current practice is already confusing). Consider
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
513 it carefully, it may save lots of calls to Py_INCREF() and Py_DECREF() at
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
514 times.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
515 */
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
516
11999
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
517 /*
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
518 trashcan
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
519 CT 2k0130
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
520 non-recursively destroy nested objects
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
521
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
522 CT 2k0223
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
523 redefinition for better locality and less overhead.
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
524
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
525 Objects that want to be recursion safe need to use
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
526 the macroes
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
527 Py_TRASHCAN_SAFE_BEGIN(name)
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
528 and
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
529 Py_TRASHCAN_SAFE_END(name)
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
530 surrounding their actual deallocation code.
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
531
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
532 It would be nice to do this using the thread state.
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
533 Also, we could do an exact stack measure then.
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
534 Unfortunately, deallocations also take place when
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
535 the thread state is undefined.
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
536 */
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
537
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
538 #define PyTrash_UNWIND_LEVEL 50
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
539
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
540 #define Py_TRASHCAN_SAFE_BEGIN(op) \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
541 { \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
542 ++_PyTrash_delete_nesting; \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
543 if (_PyTrash_delete_nesting < PyTrash_UNWIND_LEVEL) { \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
544
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
545 #define Py_TRASHCAN_SAFE_END(op) \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
546 ;} \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
547 else \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
548 _PyTrash_deposit_object((PyObject*)op);\
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
549 --_PyTrash_delete_nesting; \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
550 if (_PyTrash_delete_later && _PyTrash_delete_nesting <= 0) \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
551 _PyTrash_destroy_list(); \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
552 } \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
553
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
554 extern DL_IMPORT(void) _PyTrash_deposit_object Py_PROTO((PyObject*));
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
555 extern DL_IMPORT(void) _PyTrash_destroy_list Py_PROTO(());
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
556
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
557 extern DL_IMPORT(int) _PyTrash_delete_nesting;
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
558 extern DL_IMPORT(PyObject *) _PyTrash_delete_later;
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
559
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
560 /* swap the "xx" to check the speed loss */
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
561
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
562 #define xxPy_TRASHCAN_SAFE_BEGIN(op)
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
563 #define xxPy_TRASHCAN_SAFE_END(op) ;
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
564 #ifdef __cplusplus
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
565 }
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
566 #endif
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
567 #endif /* !Py_OBJECT_H */