annotate Include/object.h @ 17322:bd110eadc19a legacy-trunk

One-liner critical fix from Jim Fulton: Eric's string-method crusade got the order backwards in a line (for .find()).
author Tim Peters <tim.peters@gmail.com>
date Thu, 05 Apr 2001 22:26:23 +0000
parents d446e4ec9b7b
children 32e7d0898eab
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
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 /* Object and type object interface */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 /*
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 Objects are structures allocated on the heap. Special rules apply to
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 the use of objects to ensure they are properly garbage-collected.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 Objects are never allocated statically or on the stack; they must be
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 accessed through special macros and functions only. (Type objects are
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 exceptions to the first rule; the standard types are represented by
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 statically initialized type objects.)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 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
19 pointer to the object is copied or deleted; when the reference count
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 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
21 removed from the heap.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 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
24 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
25 Types themselves are represented as objects; an object contains a
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 pointer to the corresponding type object. The type itself has a type
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 pointer pointing to the object representing the type 'type', which
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 contains a pointer to itself!).
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 Objects do not float around in memory; once allocated an object keeps
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 the same size and address. Objects that must hold variable-size data
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 can contain pointers to variable-size parts of the object. Not all
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 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
34 after allocation. (These restrictions are made so a reference to an
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 object can be simply a pointer -- moving an object would require
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 updating all the pointers, and changing an object's size would require
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 moving it if there was another object right next to it.)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
39 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
40 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
41 and the type pointer. The actual memory allocated for an object
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 contains other data that can only be accessed after casting the pointer
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 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
44 with the reference count and type fields; the macro PyObject_HEAD should be
13620
5b727ab37092 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents: 13464
diff changeset
45 used for this (to accommodate for future changes). The implementation
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 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
47 type and back.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 A standard interface exists for objects that contain an array of items
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 whose size is determined when the object is allocated.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
52
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
53 #ifdef Py_DEBUG
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
54
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
55 /* 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
56 #define Py_TRACE_REFS
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
57
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
58 /* 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
59 #define Py_REF_DEBUG
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
60
4839
4567e158d20c Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
61 #endif /* Py_DEBUG */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
62
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
63 #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
64 #define PyObject_HEAD \
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 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
66 int ob_refcnt; \
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 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
68 #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
69 #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
70 #define PyObject_HEAD \
2058
508036dbba3b Added 1995 copyright.
Guido van Rossum <guido@python.org>
parents: 1794
diff changeset
71 int ob_refcnt; \
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 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
73 #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
74 #endif /* !Py_TRACE_REFS */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
75
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
76 #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
77 PyObject_HEAD \
2058
508036dbba3b Added 1995 copyright.
Guido van Rossum <guido@python.org>
parents: 1794
diff changeset
78 int ob_size; /* Number of items in variable part */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
79
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 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
81 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
82 } PyObject;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 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
85 PyObject_VAR_HEAD
5535
20c2b715188e Oops, another forgotten renaming: varobject -> PyVarObject.
Guido van Rossum <guido@python.org>
parents: 5410
diff changeset
86 } PyVarObject;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
87
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
88
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 /*
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 Type objects contain a string containing the type name (to help somewhat
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 in debugging), the allocation parameters (see newobj() and newvarobj()),
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 and methods for accessing objects of the type. Methods are optional,a
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 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
94 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
95 checking for a nil pointer; it should always be implemented except if
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 the implementation can guarantee that the reference count will never
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 reach zero (e.g., for type objects).
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
98
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 NB: the methods for certain type groups are now contained in separate
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 method blocks.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
102
13418
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
103 typedef PyObject * (*unaryfunc)(PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
104 typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
105 typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
106 typedef int (*inquiry)(PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
107 typedef int (*coercion)(PyObject **, PyObject **);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
108 typedef PyObject *(*intargfunc)(PyObject *, int);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
109 typedef PyObject *(*intintargfunc)(PyObject *, int, int);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
110 typedef int(*intobjargproc)(PyObject *, int, PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
111 typedef int(*intintobjargproc)(PyObject *, int, int, PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
112 typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
113 typedef int (*getreadbufferproc)(PyObject *, int, void **);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
114 typedef int (*getwritebufferproc)(PyObject *, int, void **);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
115 typedef int (*getsegcountproc)(PyObject *, int *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
116 typedef int (*getcharbufferproc)(PyObject *, int, const char **);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
117 typedef int (*objobjproc)(PyObject *, PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
118 typedef int (*visitproc)(PyObject *, void *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
119 typedef int (*traverseproc)(PyObject *, visitproc, void *);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
120
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 typedef struct {
15938
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
122 /* For numbers without flag bit Py_TPFLAGS_CHECKTYPES set, all
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
123 arguments are guaranteed to be of the object's type (modulo
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
124 coercion hacks that is -- i.e. if the type's coercion function
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
125 returns other types, then these are allowed as well). Numbers that
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
126 have the Py_TPFLAGS_CHECKTYPES flag bit set should check *both*
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
127 arguments for proper type and implement the necessary conversions
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
128 in the slot functions themselves. */
15716
362e53f43dd2 - Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14497
diff changeset
129
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
130 binaryfunc nb_add;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
131 binaryfunc nb_subtract;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
132 binaryfunc nb_multiply;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
133 binaryfunc nb_divide;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
134 binaryfunc nb_remainder;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
135 binaryfunc nb_divmod;
1770
b0dca2972b2b * Objects/{int,long,float}object.c, Include/object.h,
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
136 ternaryfunc nb_power;
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
137 unaryfunc nb_negative;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
138 unaryfunc nb_positive;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
139 unaryfunc nb_absolute;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
140 inquiry nb_nonzero;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
141 unaryfunc nb_invert;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
142 binaryfunc nb_lshift;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
143 binaryfunc nb_rshift;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
144 binaryfunc nb_and;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
145 binaryfunc nb_xor;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
146 binaryfunc nb_or;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
147 coercion nb_coerce;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
148 unaryfunc nb_int;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
149 unaryfunc nb_long;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
150 unaryfunc nb_float;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
151 unaryfunc nb_oct;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
152 unaryfunc nb_hex;
14162
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
153 binaryfunc nb_inplace_add;
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
154 binaryfunc nb_inplace_subtract;
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
155 binaryfunc nb_inplace_multiply;
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
156 binaryfunc nb_inplace_divide;
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
157 binaryfunc nb_inplace_remainder;
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
158 ternaryfunc nb_inplace_power;
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
159 binaryfunc nb_inplace_lshift;
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
160 binaryfunc nb_inplace_rshift;
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
161 binaryfunc nb_inplace_and;
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
162 binaryfunc nb_inplace_xor;
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
163 binaryfunc nb_inplace_or;
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
164 } PyNumberMethods;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
165
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 typedef struct {
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
167 inquiry sq_length;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
168 binaryfunc sq_concat;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
169 intargfunc sq_repeat;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
170 intargfunc sq_item;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
171 intintargfunc sq_slice;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
172 intobjargproc sq_ass_item;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
173 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
174 objobjproc sq_contains;
14162
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
175 binaryfunc sq_inplace_concat;
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
176 intargfunc sq_inplace_repeat;
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
177 } PySequenceMethods;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
178
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 typedef struct {
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
180 inquiry mp_length;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
181 binaryfunc mp_subscript;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
182 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
183 } PyMappingMethods;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
184
5410
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
185 typedef struct {
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
186 getreadbufferproc bf_getreadbuffer;
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
187 getwritebufferproc bf_getwritebuffer;
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
188 getsegcountproc bf_getsegcount;
9304
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
189 getcharbufferproc bf_getcharbuffer;
5410
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
190 } PyBufferProcs;
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
191
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
192
13418
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
193 typedef void (*destructor)(PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
194 typedef int (*printfunc)(PyObject *, FILE *, int);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
195 typedef PyObject *(*getattrfunc)(PyObject *, char *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
196 typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
197 typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
198 typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
199 typedef int (*cmpfunc)(PyObject *, PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
200 typedef PyObject *(*reprfunc)(PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
201 typedef long (*hashfunc)(PyObject *);
15938
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
202 typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
203
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 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
205 PyObject_VAR_HEAD
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 char *tp_name; /* For printing */
2058
508036dbba3b Added 1995 copyright.
Guido van Rossum <guido@python.org>
parents: 1794
diff changeset
207 int tp_basicsize, tp_itemsize; /* For allocation */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
208
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 /* Methods to implement standard operations */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
210
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
211 destructor tp_dealloc;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
212 printfunc tp_print;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
213 getattrfunc tp_getattr;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
214 setattrfunc tp_setattr;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
215 cmpfunc tp_compare;
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
216 reprfunc tp_repr;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
217
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 /* Method suites for standard classes */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
219
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
220 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
221 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
222 PyMappingMethods *tp_as_mapping;
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1049
diff changeset
223
12026
8dc0918ae2c2 Updated comment: in PyTypeObject:
Fred Drake <fdrake@acm.org>
parents: 11999
diff changeset
224 /* 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
225
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
226 hashfunc tp_hash;
2841
64928f6a8e80 keyword arguments and faster function calls
Guido van Rossum <guido@python.org>
parents: 2669
diff changeset
227 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
228 reprfunc tp_str;
3983
44902516614a Added tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents: 3605
diff changeset
229 getattrofunc tp_getattro;
44902516614a Added tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents: 3605
diff changeset
230 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
231
5410
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
232 /* 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
233 PyBufferProcs *tp_as_buffer;
3b2fda31bf1b Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents: 4839
diff changeset
234
9304
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
235 /* 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
236 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
237
048e91a59c75 new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents: 2058
diff changeset
238 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
239
12990
e615596c5c47 Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12481
diff changeset
240 /* call function for all accessible objects */
e615596c5c47 Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12481
diff changeset
241 traverseproc tp_traverse;
e615596c5c47 Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12481
diff changeset
242
e615596c5c47 Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12481
diff changeset
243 /* delete references to contained objects */
e615596c5c47 Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12481
diff changeset
244 inquiry tp_clear;
e615596c5c47 Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12481
diff changeset
245
15938
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
246 /* rich comparisons */
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
247 richcmpfunc tp_richcompare;
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
248
16385
1fb6672b20ef PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents: 16235
diff changeset
249 /* weak reference enabler */
1fb6672b20ef PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents: 16235
diff changeset
250 long tp_weaklistoffset;
8124
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 */
13418
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
266 extern DL_IMPORT(int) PyObject_Print(PyObject *, FILE *, int);
16195
1aa8349f6695 PyObject_Dump() -> _PyObject_Dump()
Barry Warsaw <barry@python.org>
parents: 16168
diff changeset
267 extern DL_IMPORT(void) _PyObject_Dump(PyObject *);
13418
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
268 extern DL_IMPORT(PyObject *) PyObject_Repr(PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
269 extern DL_IMPORT(PyObject *) PyObject_Str(PyObject *);
15952
1f92d63b20f0 This patch adds a new builtin unistr() which behaves like str()
Marc-André Lemburg <mal@egenix.com>
parents: 15938
diff changeset
270 extern DL_IMPORT(PyObject *) PyObject_Unicode(PyObject *);
13418
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
271 extern DL_IMPORT(int) PyObject_Compare(PyObject *, PyObject *);
15938
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
272 extern DL_IMPORT(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
273 extern DL_IMPORT(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);
13418
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
274 extern DL_IMPORT(PyObject *) PyObject_GetAttrString(PyObject *, char *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
275 extern DL_IMPORT(int) PyObject_SetAttrString(PyObject *, char *, PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
276 extern DL_IMPORT(int) PyObject_HasAttrString(PyObject *, char *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
277 extern DL_IMPORT(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
278 extern DL_IMPORT(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
279 extern DL_IMPORT(int) PyObject_HasAttr(PyObject *, PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
280 extern DL_IMPORT(long) PyObject_Hash(PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
281 extern DL_IMPORT(int) PyObject_IsTrue(PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
282 extern DL_IMPORT(int) PyObject_Not(PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
283 extern DL_IMPORT(int) PyCallable_Check(PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
284 extern DL_IMPORT(int) PyNumber_Coerce(PyObject **, PyObject **);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
285 extern DL_IMPORT(int) PyNumber_CoerceEx(PyObject **, PyObject **);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
286
16768
d446e4ec9b7b The return value from PyObject_ClearWeakRefs() is no longer meaningful,
Fred Drake <fdrake@acm.org>
parents: 16420
diff changeset
287 extern DL_IMPORT(void) (*PyObject_ClearWeakRefs)(PyObject *);
16385
1fb6672b20ef PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents: 16235
diff changeset
288
7983
068303f925ea Add prototypes for Py_Repr{Enter,Leave}.
Guido van Rossum <guido@python.org>
parents: 7935
diff changeset
289 /* Helpers for printing recursive container types */
13418
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
290 extern DL_IMPORT(int) Py_ReprEnter(PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
291 extern DL_IMPORT(void) Py_ReprLeave(PyObject *);
7983
068303f925ea Add prototypes for Py_Repr{Enter,Leave}.
Guido van Rossum <guido@python.org>
parents: 7935
diff changeset
292
13141
cca84745da3e This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents: 12993
diff changeset
293 /* Helpers for hash functions */
13418
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
294 extern DL_IMPORT(long) _Py_HashDouble(double);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
295 extern DL_IMPORT(long) _Py_HashPointer(void*);
13141
cca84745da3e This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents: 12993
diff changeset
296
16394
f700e6b8de1f Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16385
diff changeset
297 /* Helper for passing objects to printf and the like */
f700e6b8de1f Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16385
diff changeset
298 #define PyObject_REPR(obj) PyString_AS_STRING(PyObject_Repr(obj))
f700e6b8de1f Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16385
diff changeset
299
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 /* 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
301 #define Py_PRINT_RAW 1 /* No string quotes etc. */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
302
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
303 /*
9304
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
304
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
305 Type flags (tp_flags)
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
306
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
307 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
308 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
309 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
310 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
311 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
312
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
313 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
314 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
315 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
316
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
317 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
318
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
319 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
320
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
321 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
322 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
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
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
326 /* PyBufferProcs contains bf_getcharbuffer */
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
327 #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
328
11867
06104bcf06a6 Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This adds
Guido van Rossum <guido@python.org>
parents: 11673
diff changeset
329 /* 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
330 #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
331
12993
8f79c5b69e0a part 2 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12990
diff changeset
332 /* Objects which participate in garbage collection (see objimp.h) */
8f79c5b69e0a part 2 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12990
diff changeset
333 #ifdef WITH_CYCLE_GC
8f79c5b69e0a part 2 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12990
diff changeset
334 #define Py_TPFLAGS_GC (1L<<2)
8f79c5b69e0a part 2 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12990
diff changeset
335 #else
8f79c5b69e0a part 2 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12990
diff changeset
336 #define Py_TPFLAGS_GC 0
8f79c5b69e0a part 2 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12990
diff changeset
337 #endif
8f79c5b69e0a part 2 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 12990
diff changeset
338
14162
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
339 /* PySequenceMethods and PyNumberMethods contain in-place operators */
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
340 #define Py_TPFLAGS_HAVE_INPLACEOPS (1L<<3)
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
341
15716
362e53f43dd2 - Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14497
diff changeset
342 /* PyNumberMethods do their own coercion */
15938
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
343 #define Py_TPFLAGS_CHECKTYPES (1L<<4)
15716
362e53f43dd2 - Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14497
diff changeset
344
16235
5c60184f7f52 Add a flag to indicate the presence of the tp_richcompare field, and
Guido van Rossum <guido@python.org>
parents: 16195
diff changeset
345 #define Py_TPFLAGS_HAVE_RICHCOMPARE (1L<<5)
5c60184f7f52 Add a flag to indicate the presence of the tp_richcompare field, and
Guido van Rossum <guido@python.org>
parents: 16195
diff changeset
346
16420
38204093d9c9 Use a type flag to determine the applicability of the tp_weaklistoffset
Fred Drake <fdrake@acm.org>
parents: 16394
diff changeset
347 /* Objects which are weakly referencable if their tp_weaklistoffset is >0 */
38204093d9c9 Use a type flag to determine the applicability of the tp_weaklistoffset
Fred Drake <fdrake@acm.org>
parents: 16394
diff changeset
348 /* XXX Should this have the same value as Py_TPFLAGS_HAVE_RICHCOMPARE?
38204093d9c9 Use a type flag to determine the applicability of the tp_weaklistoffset
Fred Drake <fdrake@acm.org>
parents: 16394
diff changeset
349 * These both indicate a feature that appeared in the same alpha release.
38204093d9c9 Use a type flag to determine the applicability of the tp_weaklistoffset
Fred Drake <fdrake@acm.org>
parents: 16394
diff changeset
350 */
38204093d9c9 Use a type flag to determine the applicability of the tp_weaklistoffset
Fred Drake <fdrake@acm.org>
parents: 16394
diff changeset
351 #define Py_TPFLAGS_HAVE_WEAKREFS (1L<<6)
38204093d9c9 Use a type flag to determine the applicability of the tp_weaklistoffset
Fred Drake <fdrake@acm.org>
parents: 16394
diff changeset
352
16235
5c60184f7f52 Add a flag to indicate the presence of the tp_richcompare field, and
Guido van Rossum <guido@python.org>
parents: 16195
diff changeset
353 #define Py_TPFLAGS_DEFAULT ( \
5c60184f7f52 Add a flag to indicate the presence of the tp_richcompare field, and
Guido van Rossum <guido@python.org>
parents: 16195
diff changeset
354 Py_TPFLAGS_HAVE_GETCHARBUFFER | \
14162
27d7d89c774b The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
355 Py_TPFLAGS_HAVE_SEQUENCE_IN | \
16235
5c60184f7f52 Add a flag to indicate the presence of the tp_richcompare field, and
Guido van Rossum <guido@python.org>
parents: 16195
diff changeset
356 Py_TPFLAGS_HAVE_INPLACEOPS | \
5c60184f7f52 Add a flag to indicate the presence of the tp_richcompare field, and
Guido van Rossum <guido@python.org>
parents: 16195
diff changeset
357 Py_TPFLAGS_HAVE_RICHCOMPARE | \
16420
38204093d9c9 Use a type flag to determine the applicability of the tp_weaklistoffset
Fred Drake <fdrake@acm.org>
parents: 16394
diff changeset
358 Py_TPFLAGS_HAVE_WEAKREFS | \
16235
5c60184f7f52 Add a flag to indicate the presence of the tp_richcompare field, and
Guido van Rossum <guido@python.org>
parents: 16195
diff changeset
359 0)
9304
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
360
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
361 #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
362
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
363
cc3e14837379 Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents: 8124
diff changeset
364 /*
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
365 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
366 reference counts. Py_DECREF calls the object's deallocator function; for
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 objects that don't contain references to other objects or heap memory
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 this can be the standard function free(). Both macros can be used
13620
5b727ab37092 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents: 13464
diff changeset
369 wherever 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
370 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
371 reference counts to 1; it is defined here for convenience.
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
372
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
373 We assume that the reference count field can never overflow; this can
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 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
375 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
376 we ignore the possibility. (If you are paranoid, make it a long.)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
377
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
378 Type objects should never be deallocated; the type pointer in an object
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 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
380 complications in the deallocation function. (This is actually a
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 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
382 you can count such references to the type object.)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
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 *** 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
385 since it may evaluate its argument multiple times. (The alternative
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
386 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
387 variable first, both of which are slower; and in a multi-threaded
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
388 environment the global variable trick is not safe.)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
390
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
391 #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
392 #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
393 #define Py_REF_DEBUG
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
394 #endif
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 #endif
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
396
4001
1ed773e15936 Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents: 3983
diff changeset
397 #ifdef Py_TRACE_REFS
13418
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
398 extern DL_IMPORT(void) _Py_Dealloc(PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
399 extern DL_IMPORT(void) _Py_NewReference(PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
400 extern DL_IMPORT(void) _Py_ForgetReference(PyObject *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
401 extern DL_IMPORT(void) _Py_PrintReferences(FILE *);
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
402 extern DL_IMPORT(void) _Py_ResetReferences(void);
4001
1ed773e15936 Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents: 3983
diff changeset
403 #endif
1ed773e15936 Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents: 3983
diff changeset
404
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
405 #ifndef Py_TRACE_REFS
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
406 #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
407 #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
408 #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
409 #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
410 #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
411 #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
412 #endif /* !COUNT_ALLOCS */
1ed773e15936 Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents: 3983
diff changeset
413 #endif /* !Py_TRACE_REFS */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
414
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
415 #ifdef COUNT_ALLOCS
13418
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
416 extern DL_IMPORT(void) inc_count(PyTypeObject *);
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
417 #endif
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
418
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
419 #ifdef Py_REF_DEBUG
3573
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
420
9586
60fdb1db1175 Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents: 9304
diff changeset
421 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
422
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
423 #ifndef Py_TRACE_REFS
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
424 #ifdef COUNT_ALLOCS
2612
ca6b60d4ea90 fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents: 2436
diff changeset
425 #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
426 #else
2612
ca6b60d4ea90 fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents: 2436
diff changeset
427 #define _Py_NewReference(op) (_Py_RefTotal++, (op)->ob_refcnt = 1)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 #endif
3573
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
429 #endif /* !Py_TRACE_REFS */
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
430
2612
ca6b60d4ea90 fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents: 2436
diff changeset
431 #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
432 #define Py_DECREF(op) \
16385
1fb6672b20ef PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents: 16235
diff changeset
433 if (--_Py_RefTotal, (--((op)->ob_refcnt) != 0)) \
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 ; \
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 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
436 _Py_Dealloc((PyObject *)(op))
3573
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
437 #else /* !Py_REF_DEBUG */
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
438
1347
a22a350d3a5d * Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents: 1329
diff changeset
439 #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
440 #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
441 #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
442 #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
443 #endif
3573
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
444
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
445 #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
446 #define Py_DECREF(op) \
2058
508036dbba3b Added 1995 copyright.
Guido van Rossum <guido@python.org>
parents: 1794
diff changeset
447 if (--(op)->ob_refcnt != 0) \
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
448 ; \
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
449 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
450 _Py_Dealloc((PyObject *)(op))
3573
4c7bab4cdca6 Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents: 2862
diff changeset
451 #endif /* !Py_REF_DEBUG */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
452
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
453 /* Macros to use in case the object pointer may be NULL: */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
454
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
455 #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
456 #define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
457
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
458 /*
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
459 _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
460 where NULL (nil) is not suitable (since NULL often means 'error').
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
461
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
462 Don't forget to apply Py_INCREF() when returning this value!!!
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
463 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
464
2669
34eefa226709 DL_IMPORT needs an argument.
Sjoerd Mullender <sjoerd@acm.org>
parents: 2664
diff changeset
465 extern DL_IMPORT(PyObject) _Py_NoneStruct; /* Don't use this directly */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
466
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
467 #define Py_None (&_Py_NoneStruct)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
468
15716
362e53f43dd2 - Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14497
diff changeset
469 /*
362e53f43dd2 - Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14497
diff changeset
470 Py_NotImplemented is a singleton used to signal that an operation is
362e53f43dd2 - Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14497
diff changeset
471 not implemented for a given type combination.
362e53f43dd2 - Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14497
diff changeset
472 */
362e53f43dd2 - Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14497
diff changeset
473
362e53f43dd2 - Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14497
diff changeset
474 extern DL_IMPORT(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */
362e53f43dd2 - Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14497
diff changeset
475
362e53f43dd2 - Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 14497
diff changeset
476 #define Py_NotImplemented (&_Py_NotImplementedStruct)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
477
15938
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
478 /* Rich comparison opcodes */
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
479 #define Py_LT 0
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
480 #define Py_LE 1
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
481 #define Py_EQ 2
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
482 #define Py_NE 3
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
483 #define Py_GT 4
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
484 #define Py_GE 5
8fd221aed357 Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents: 15716
diff changeset
485
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
486 /*
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
487 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
488 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
489 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
490 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
491 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
492 (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
493 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
494 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
495 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
496 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
497 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
498 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
499 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
500 */
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
501
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
502 #ifdef BAD_STATIC_FORWARD
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
503 #define staticforward extern
2422
f4f71ebea53f change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents: 2364
diff changeset
504 #define statichere static
f4f71ebea53f change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents: 2364
diff changeset
505 #else /* !BAD_STATIC_FORWARD */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
506 #define staticforward static
2422
f4f71ebea53f change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents: 2364
diff changeset
507 #define statichere static
f4f71ebea53f change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents: 2364
diff changeset
508 #endif /* !BAD_STATIC_FORWARD */
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
509
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
510
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1400
diff changeset
511 /*
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
512 More conventions
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
513 ================
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
514
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
515 Argument Checking
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
516 -----------------
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
517
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
518 Functions that take objects as arguments normally don't check for nil
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
519 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
520 error if the function doesn't apply to the type.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
521
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
522 Failure Modes
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
523 -------------
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
524
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
525 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
526 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
527 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
528 normally return a pointer return NULL for failure, functions returning
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
529 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
530 other functions return 0 for success and -1 for failure.
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 68
diff changeset
531 Callers should always check for errors before using the result.
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
532
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
533 Reference Counts
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
534 ----------------
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
535
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
536 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
537
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
538 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
539 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
540 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
541 PyDict_SetItemString()
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
542 don't increment the reference count of the object, since the most
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
543 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
544 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
545 don't increment
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
546 the reference count, since most frequently the object is only looked at
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
547 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
548 must call Py_INCREF() explicitly.
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
549
2129
05360cd616ae The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents: 2071
diff changeset
550 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
551 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
552 stored, to simplify error handling.
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
553
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
554 It seems attractive to make other functions that take an object as
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
555 argument consume a reference count; however this may quickly get
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
556 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
557 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
558 times.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
559 */
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
560
11999
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 trashcan
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
563 CT 2k0130
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
564 non-recursively destroy nested objects
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
565
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
566 CT 2k0223
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
567 redefinition for better locality and less overhead.
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
568
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
569 Objects that want to be recursion safe need to use
13620
5b727ab37092 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents: 13464
diff changeset
570 the macro's
11999
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
571 Py_TRASHCAN_SAFE_BEGIN(name)
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
572 and
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
573 Py_TRASHCAN_SAFE_END(name)
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
574 surrounding their actual deallocation code.
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
575
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
576 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
577 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
578 Unfortunately, deallocations also take place when
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
579 the thread state is undefined.
12481
a8898a172fe2 Christian Tismer -- total rewrite on trashcan code.
Guido van Rossum <guido@python.org>
parents: 12406
diff changeset
580
a8898a172fe2 Christian Tismer -- total rewrite on trashcan code.
Guido van Rossum <guido@python.org>
parents: 12406
diff changeset
581 CT 2k0422 complete rewrite.
a8898a172fe2 Christian Tismer -- total rewrite on trashcan code.
Guido van Rossum <guido@python.org>
parents: 12406
diff changeset
582 There is no need to allocate new objects.
a8898a172fe2 Christian Tismer -- total rewrite on trashcan code.
Guido van Rossum <guido@python.org>
parents: 12406
diff changeset
583 Everything is done vialob_refcnt and ob_type now.
a8898a172fe2 Christian Tismer -- total rewrite on trashcan code.
Guido van Rossum <guido@python.org>
parents: 12406
diff changeset
584 Adding support for free-threading should be easy, too.
11999
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
585 */
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
586
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
587 #define PyTrash_UNWIND_LEVEL 50
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
588
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
589 #define Py_TRASHCAN_SAFE_BEGIN(op) \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
590 { \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
591 ++_PyTrash_delete_nesting; \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
592 if (_PyTrash_delete_nesting < PyTrash_UNWIND_LEVEL) { \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
593
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
594 #define Py_TRASHCAN_SAFE_END(op) \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
595 ;} \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
596 else \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
597 _PyTrash_deposit_object((PyObject*)op);\
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
598 --_PyTrash_delete_nesting; \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
599 if (_PyTrash_delete_later && _PyTrash_delete_nesting <= 0) \
12481
a8898a172fe2 Christian Tismer -- total rewrite on trashcan code.
Guido van Rossum <guido@python.org>
parents: 12406
diff changeset
600 _PyTrash_destroy_chain(); \
11999
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
601 } \
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
602
13418
85520c220067 Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
603 extern DL_IMPORT(void) _PyTrash_deposit_object(PyObject*);
13419
db9392a04bed One of the new prototypes was missing the "void" args.
Greg Stein <gstein@lyra.org>
parents: 13418
diff changeset
604 extern DL_IMPORT(void) _PyTrash_destroy_chain(void);
11999
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
605
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
606 extern DL_IMPORT(int) _PyTrash_delete_nesting;
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
607 extern DL_IMPORT(PyObject *) _PyTrash_delete_later;
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
608
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
609 /* swap the "xx" to check the speed loss */
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
610
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
611 #define xxPy_TRASHCAN_SAFE_BEGIN(op)
c94247b5c355 Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents: 11891
diff changeset
612 #define xxPy_TRASHCAN_SAFE_END(op) ;
12481
a8898a172fe2 Christian Tismer -- total rewrite on trashcan code.
Guido van Rossum <guido@python.org>
parents: 12406
diff changeset
613
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
614 #ifdef __cplusplus
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
615 }
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
616 #endif
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1324
diff changeset
617 #endif /* !Py_OBJECT_H */