Mercurial > cpython-lru_cache-weakref
annotate Objects/object.c @ 6719:faebc1940432 legacy-trunk
Understand -Xlinker option.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 02 Dec 1997 20:38:11 +0000 |
| parents | b88fd3894d5a |
| children | 516189984b0c |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
2059
866c81068dbd
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2053
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
866c81068dbd
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2053
diff
changeset
|
3 The Netherlands. |
| 145 | 4 |
| 5 All Rights Reserved | |
| 6 | |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
| 145 | 9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
| 145 | 11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
15 permission. |
| 145 | 16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
4288
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
| 145 | 29 |
| 30 ******************************************************************/ | |
| 31 | |
| 86 | 32 /* Generic object operations; and implementation of None (NoObject) */ |
| 6 | 33 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
34 #include "Python.h" |
| 6 | 35 |
|
2612
ca6b60d4ea90
fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents:
2307
diff
changeset
|
36 #if defined( Py_TRACE_REFS ) || defined( Py_REF_DEBUG ) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
37 long _Py_RefTotal; |
| 86 | 38 #endif |
| 6 | 39 |
| 86 | 40 /* Object allocation routines used by NEWOBJ and NEWVAROBJ macros. |
| 41 These are used by the individual routines for object creation. | |
| 42 Do not call them otherwise, they do not initialize the object! */ | |
| 6 | 43 |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
44 #ifdef COUNT_ALLOCS |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
45 static PyTypeObject *type_list; |
|
1352
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
46 extern int tuple_zero_allocs, fast_tuple_allocs; |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
47 extern int quick_int_allocs, quick_neg_int_allocs; |
|
1356
043da19302ef
Several optimizations and speed improvements.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1352
diff
changeset
|
48 extern int null_strings, one_strings; |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
49 void |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
50 dump_counts() |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
51 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
52 PyTypeObject *tp; |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
53 |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
54 for (tp = type_list; tp; tp = tp->tp_next) |
|
1361
7cd533cf194a
import.c: When something is wrong with the .pyc, properly open the .py
Sjoerd Mullender <sjoerd@acm.org>
parents:
1356
diff
changeset
|
55 fprintf(stderr, "%s alloc'd: %d, freed: %d, max in use: %d\n", |
|
7cd533cf194a
import.c: When something is wrong with the .pyc, properly open the .py
Sjoerd Mullender <sjoerd@acm.org>
parents:
1356
diff
changeset
|
56 tp->tp_name, tp->tp_alloc, tp->tp_free, |
|
7cd533cf194a
import.c: When something is wrong with the .pyc, properly open the .py
Sjoerd Mullender <sjoerd@acm.org>
parents:
1356
diff
changeset
|
57 tp->tp_maxalloc); |
|
7cd533cf194a
import.c: When something is wrong with the .pyc, properly open the .py
Sjoerd Mullender <sjoerd@acm.org>
parents:
1356
diff
changeset
|
58 fprintf(stderr, "fast tuple allocs: %d, empty: %d\n", |
|
7cd533cf194a
import.c: When something is wrong with the .pyc, properly open the .py
Sjoerd Mullender <sjoerd@acm.org>
parents:
1356
diff
changeset
|
59 fast_tuple_allocs, tuple_zero_allocs); |
|
7cd533cf194a
import.c: When something is wrong with the .pyc, properly open the .py
Sjoerd Mullender <sjoerd@acm.org>
parents:
1356
diff
changeset
|
60 fprintf(stderr, "fast int allocs: pos: %d, neg: %d\n", |
|
7cd533cf194a
import.c: When something is wrong with the .pyc, properly open the .py
Sjoerd Mullender <sjoerd@acm.org>
parents:
1356
diff
changeset
|
61 quick_int_allocs, quick_neg_int_allocs); |
|
7cd533cf194a
import.c: When something is wrong with the .pyc, properly open the .py
Sjoerd Mullender <sjoerd@acm.org>
parents:
1356
diff
changeset
|
62 fprintf(stderr, "null strings: %d, 1-strings: %d\n", |
|
7cd533cf194a
import.c: When something is wrong with the .pyc, properly open the .py
Sjoerd Mullender <sjoerd@acm.org>
parents:
1356
diff
changeset
|
63 null_strings, one_strings); |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
64 } |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
65 |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
66 PyObject * |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
67 get_counts() |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
68 { |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
69 PyTypeObject *tp; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
70 PyObject *result; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
71 PyObject *v; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
72 |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
73 result = PyList_New(0); |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
74 if (result == NULL) |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
75 return NULL; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
76 for (tp = type_list; tp; tp = tp->tp_next) { |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
77 v = Py_BuildValue("(siii)", tp->tp_name, tp->tp_alloc, |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
78 tp->tp_free, tp->tp_maxalloc); |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
79 if (v == NULL) { |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
80 Py_DECREF(result); |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
81 return NULL; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
82 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
83 if (PyList_Append(result, v) < 0) { |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
84 Py_DECREF(v); |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
85 Py_DECREF(result); |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
86 return NULL; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
87 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
88 Py_DECREF(v); |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
89 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
90 return result; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
91 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
92 |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
93 void |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
94 inc_count(tp) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
95 PyTypeObject *tp; |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
96 { |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
97 if (tp->tp_alloc == 0) { |
|
2639
f11ba9cc342f
change in counting freed objects
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
98 /* first time; insert in linked list */ |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
99 if (tp->tp_next != NULL) /* sanity check */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
100 Py_FatalError("XXX inc_count sanity check"); |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
101 tp->tp_next = type_list; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
102 type_list = tp; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
103 } |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
104 tp->tp_alloc++; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
105 if (tp->tp_alloc - tp->tp_free > tp->tp_maxalloc) |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
106 tp->tp_maxalloc = tp->tp_alloc - tp->tp_free; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
107 } |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
108 #endif |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
109 |
| 3770 | 110 #ifndef MS_COREDLL |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
111 PyObject * |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
112 _PyObject_New(tp) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
113 PyTypeObject *tp; |
| 3770 | 114 #else |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
115 PyObject * |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
116 _PyObject_New(tp,op) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
117 PyTypeObject *tp; |
| 3770 | 118 PyObject *op; |
| 119 #endif | |
| 6 | 120 { |
| 3770 | 121 #ifndef MS_COREDLL |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
122 PyObject *op = (PyObject *) malloc(tp->tp_basicsize); |
| 3770 | 123 #endif |
| 6 | 124 if (op == NULL) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
125 return PyErr_NoMemory(); |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
126 op->ob_type = tp; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
127 _Py_NewReference(op); |
| 6 | 128 return op; |
| 129 } | |
| 130 | |
| 3770 | 131 #ifndef MS_COREDLL |
|
5535
20c2b715188e
Oops, another forgotten renaming: varobject -> PyVarObject.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
132 PyVarObject * |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
133 _PyObject_NewVar(tp, size) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
134 PyTypeObject *tp; |
| 2307 | 135 int size; |
| 3770 | 136 #else |
|
5535
20c2b715188e
Oops, another forgotten renaming: varobject -> PyVarObject.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
137 PyVarObject * |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
138 _PyObject_NewVar(tp, size, op) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
139 PyTypeObject *tp; |
| 3770 | 140 int size; |
|
5535
20c2b715188e
Oops, another forgotten renaming: varobject -> PyVarObject.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
141 PyVarObject *op; |
| 3770 | 142 #endif |
| 6 | 143 { |
| 3770 | 144 #ifndef MS_COREDLL |
|
5535
20c2b715188e
Oops, another forgotten renaming: varobject -> PyVarObject.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
145 PyVarObject *op = (PyVarObject *) |
| 6 | 146 malloc(tp->tp_basicsize + size * tp->tp_itemsize); |
| 3770 | 147 #endif |
| 6 | 148 if (op == NULL) |
|
5535
20c2b715188e
Oops, another forgotten renaming: varobject -> PyVarObject.
Guido van Rossum <guido@python.org>
parents:
5396
diff
changeset
|
149 return (PyVarObject *)PyErr_NoMemory(); |
| 6 | 150 op->ob_type = tp; |
| 151 op->ob_size = size; | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
152 _Py_NewReference(op); |
| 6 | 153 return op; |
| 154 } | |
| 155 | |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
156 int |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
157 PyObject_Print(op, fp, flags) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
158 PyObject *op; |
| 6 | 159 FILE *fp; |
| 160 int flags; | |
| 161 { | |
|
322
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
162 int ret = 0; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
163 if (PyErr_CheckSignals()) |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
164 return -1; |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
165 if (op == NULL) { |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
166 fprintf(fp, "<nil>"); |
| 6 | 167 } |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
168 else { |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
169 if (op->ob_refcnt <= 0) |
|
1017
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
170 fprintf(fp, "<refcnt %u at %lx>", |
|
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
171 op->ob_refcnt, (long)op); |
|
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
172 else if (op->ob_type->tp_print == NULL) { |
|
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
173 if (op->ob_type->tp_repr == NULL) { |
|
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
174 fprintf(fp, "<%s object at %lx>", |
|
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
175 op->ob_type->tp_name, (long)op); |
|
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
176 } |
|
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
177 else { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
178 PyObject *s; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
179 if (flags & Py_PRINT_RAW) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
180 s = PyObject_Str(op); |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
181 else |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
182 s = PyObject_Repr(op); |
|
1017
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
183 if (s == NULL) |
|
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
184 ret = -1; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
185 else if (!PyString_Check(s)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
186 PyErr_SetString(PyExc_TypeError, |
|
1017
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
187 "repr not string"); |
|
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
188 ret = -1; |
|
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
189 } |
|
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
190 else { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
191 fprintf(fp, "%s", |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
192 PyString_AsString(s)); |
|
1017
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
193 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
194 Py_XDECREF(s); |
|
1017
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
195 } |
|
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
196 } |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
197 else |
|
322
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
198 ret = (*op->ob_type->tp_print)(op, fp, flags); |
| 6 | 199 } |
|
322
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
200 if (ret == 0) { |
|
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
201 if (ferror(fp)) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
202 PyErr_SetFromErrno(PyExc_IOError); |
|
322
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
203 clearerr(fp); |
|
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
204 ret = -1; |
|
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
205 } |
|
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
206 } |
|
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
207 return ret; |
| 6 | 208 } |
| 209 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
210 PyObject * |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
211 PyObject_Repr(v) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
212 PyObject *v; |
| 6 | 213 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
214 if (PyErr_CheckSignals()) |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
215 return NULL; |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
216 if (v == NULL) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
217 return PyString_FromString("<NULL>"); |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
218 else if (v->ob_type->tp_repr == NULL) { |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
219 char buf[120]; |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
220 sprintf(buf, "<%.80s object at %lx>", |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
221 v->ob_type->tp_name, (long)v); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
222 return PyString_FromString(buf); |
| 6 | 223 } |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
224 else |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
225 return (*v->ob_type->tp_repr)(v); |
| 6 | 226 } |
| 227 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
228 PyObject * |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
229 PyObject_Str(v) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
230 PyObject *v; |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
231 { |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
232 if (v == NULL) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
233 return PyString_FromString("<NULL>"); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
234 else if (PyString_Check(v)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
235 Py_INCREF(v); |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
236 return v; |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
237 } |
|
2160
899b4e3dfd4c
fix strobject() behavior
Guido van Rossum <guido@python.org>
parents:
2124
diff
changeset
|
238 else if (v->ob_type->tp_str != NULL) |
|
899b4e3dfd4c
fix strobject() behavior
Guido van Rossum <guido@python.org>
parents:
2124
diff
changeset
|
239 return (*v->ob_type->tp_str)(v); |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
240 else { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
241 PyObject *func; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
242 PyObject *res; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
243 if (!PyInstance_Check(v) || |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
244 (func = PyObject_GetAttrString(v, "__str__")) == NULL) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
245 PyErr_Clear(); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
246 return PyObject_Repr(v); |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
247 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
248 res = PyEval_CallObject(func, (PyObject *)NULL); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
249 Py_DECREF(func); |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
250 return res; |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
251 } |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
252 } |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
253 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
254 static PyObject * |
|
2124
36847b8b575d
properly implement cmp() for class instances
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
255 do_cmp(v, w) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
256 PyObject *v, *w; |
|
2124
36847b8b575d
properly implement cmp() for class instances
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
257 { |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
258 long c; |
|
2124
36847b8b575d
properly implement cmp() for class instances
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
259 /* __rcmp__ actually won't be called unless __cmp__ isn't defined, |
|
36847b8b575d
properly implement cmp() for class instances
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
260 because the check in cmpobject() reverses the objects first. |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
261 This is intentional -- it makes no sense to define cmp(x,y) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
262 different than -cmp(y,x). */ |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
263 if (PyInstance_Check(v) || PyInstance_Check(w)) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
264 return PyInstance_DoBinOp(v, w, "__cmp__", "__rcmp__", do_cmp); |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
265 c = PyObject_Compare(v, w); |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
266 if (c && PyErr_Occurred()) |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
267 return NULL; |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
268 return PyInt_FromLong(c); |
|
2124
36847b8b575d
properly implement cmp() for class instances
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
269 } |
|
36847b8b575d
properly implement cmp() for class instances
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
270 |
| 6 | 271 int |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
272 PyObject_Compare(v, w) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
273 PyObject *v, *w; |
| 6 | 274 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
275 PyTypeObject *tp; |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
276 if (v == NULL || w == NULL) { |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
277 PyErr_BadInternalCall(); |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
278 return -1; |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
279 } |
| 6 | 280 if (v == w) |
| 281 return 0; | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
282 if (PyInstance_Check(v) || PyInstance_Check(w)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
283 PyObject *res; |
|
2124
36847b8b575d
properly implement cmp() for class instances
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
284 int c; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
285 if (!PyInstance_Check(v)) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
286 return -PyObject_Compare(w, v); |
|
2124
36847b8b575d
properly implement cmp() for class instances
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
287 res = do_cmp(v, w); |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
288 if (res == NULL) |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
289 return -1; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
290 if (!PyInt_Check(res)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
291 Py_DECREF(res); |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
292 PyErr_SetString(PyExc_TypeError, |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
293 "comparison did not return an int"); |
|
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
294 return -1; |
|
2124
36847b8b575d
properly implement cmp() for class instances
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
295 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
296 c = PyInt_AsLong(res); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
297 Py_DECREF(res); |
|
2124
36847b8b575d
properly implement cmp() for class instances
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
298 return (c < 0) ? -1 : (c > 0) ? 1 : 0; |
|
36847b8b575d
properly implement cmp() for class instances
Guido van Rossum <guido@python.org>
parents:
2113
diff
changeset
|
299 } |
|
307
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
300 if ((tp = v->ob_type) != w->ob_type) { |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
301 if (tp->tp_as_number != NULL && |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
302 w->ob_type->tp_as_number != NULL) { |
|
6597
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
303 int err; |
|
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
304 err = PyNumber_CoerceEx(&v, &w); |
|
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
305 if (err < 0) |
|
5610
10e9cfa010f0
PyObject_Compare can raise an exception now.
Guido van Rossum <guido@python.org>
parents:
5560
diff
changeset
|
306 return -1; |
|
6597
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
307 else if (err == 0) { |
|
307
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
308 int cmp = (*v->ob_type->tp_compare)(v, w); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
309 Py_DECREF(v); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
310 Py_DECREF(w); |
|
307
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
311 return cmp; |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
312 } |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
313 } |
| 6 | 314 return strcmp(tp->tp_name, w->ob_type->tp_name); |
|
307
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
315 } |
| 6 | 316 if (tp->tp_compare == NULL) |
| 317 return (v < w) ? -1 : 1; | |
|
307
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
318 return (*tp->tp_compare)(v, w); |
| 6 | 319 } |
| 320 | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
321 long |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
322 PyObject_Hash(v) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
323 PyObject *v; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
324 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
325 PyTypeObject *tp = v->ob_type; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
326 if (tp->tp_hash != NULL) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
327 return (*tp->tp_hash)(v); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
328 if (tp->tp_compare == NULL) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
329 return (long) v; /* Use address as hash value */ |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
330 /* If there's a cmp but no hash defined, the object can't be hashed */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
331 PyErr_SetString(PyExc_TypeError, "unhashable type"); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
332 return -1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
333 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
334 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
335 PyObject * |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
336 PyObject_GetAttrString(v, name) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
337 PyObject *v; |
| 86 | 338 char *name; |
| 339 { | |
|
3986
9c2cbf306864
Support for tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3770
diff
changeset
|
340 if (v->ob_type->tp_getattro != NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
341 PyObject *w, *res; |
|
5006
5f4b23e3d97c
Intern the strings created in getattr() and setattr().
Guido van Rossum <guido@python.org>
parents:
4588
diff
changeset
|
342 w = PyString_InternFromString(name); |
|
3986
9c2cbf306864
Support for tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3770
diff
changeset
|
343 if (w == NULL) |
|
9c2cbf306864
Support for tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3770
diff
changeset
|
344 return NULL; |
|
9c2cbf306864
Support for tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3770
diff
changeset
|
345 res = (*v->ob_type->tp_getattro)(v, w); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
346 Py_XDECREF(w); |
|
3986
9c2cbf306864
Support for tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3770
diff
changeset
|
347 return res; |
|
9c2cbf306864
Support for tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3770
diff
changeset
|
348 } |
|
9c2cbf306864
Support for tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3770
diff
changeset
|
349 |
| 86 | 350 if (v->ob_type->tp_getattr == NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
351 PyErr_SetString(PyExc_AttributeError, "attribute-less object"); |
| 86 | 352 return NULL; |
| 353 } | |
| 354 else { | |
| 355 return (*v->ob_type->tp_getattr)(v, name); | |
| 356 } | |
| 357 } | |
| 358 | |
| 359 int | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
360 PyObject_HasAttrString(v, name) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
361 PyObject *v; |
|
1324
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
362 char *name; |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
363 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
364 PyObject *res = PyObject_GetAttrString(v, name); |
|
1324
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
365 if (res != NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
366 Py_DECREF(res); |
|
1324
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
367 return 1; |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
368 } |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
369 PyErr_Clear(); |
|
1324
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
370 return 0; |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
371 } |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
372 |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
373 int |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
374 PyObject_SetAttrString(v, name, w) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
375 PyObject *v; |
| 86 | 376 char *name; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
377 PyObject *w; |
| 86 | 378 { |
|
3986
9c2cbf306864
Support for tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3770
diff
changeset
|
379 if (v->ob_type->tp_setattro != NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
380 PyObject *s; |
|
3986
9c2cbf306864
Support for tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3770
diff
changeset
|
381 int res; |
|
5006
5f4b23e3d97c
Intern the strings created in getattr() and setattr().
Guido van Rossum <guido@python.org>
parents:
4588
diff
changeset
|
382 s = PyString_InternFromString(name); |
|
3986
9c2cbf306864
Support for tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3770
diff
changeset
|
383 if (s == NULL) |
|
4288
43ae045aa10e
Correct typo in setattr: return -1 for error, not NULL
Guido van Rossum <guido@python.org>
parents:
4002
diff
changeset
|
384 return -1; |
|
3986
9c2cbf306864
Support for tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3770
diff
changeset
|
385 res = (*v->ob_type->tp_setattro)(v, s, w); |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
386 Py_XDECREF(s); |
|
3986
9c2cbf306864
Support for tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3770
diff
changeset
|
387 return res; |
|
9c2cbf306864
Support for tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3770
diff
changeset
|
388 } |
|
9c2cbf306864
Support for tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3770
diff
changeset
|
389 |
| 86 | 390 if (v->ob_type->tp_setattr == NULL) { |
| 391 if (v->ob_type->tp_getattr == NULL) | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
392 PyErr_SetString(PyExc_TypeError, |
|
512
8414e1f9a5fe
Change error messages for impossible assignment slightly.
Guido van Rossum <guido@python.org>
parents:
473
diff
changeset
|
393 "attribute-less object (assign or del)"); |
| 86 | 394 else |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
395 PyErr_SetString(PyExc_TypeError, |
|
512
8414e1f9a5fe
Change error messages for impossible assignment slightly.
Guido van Rossum <guido@python.org>
parents:
473
diff
changeset
|
396 "object has read-only attributes"); |
| 95 | 397 return -1; |
| 86 | 398 } |
| 399 else { | |
| 400 return (*v->ob_type->tp_setattr)(v, name, w); | |
| 401 } | |
| 402 } | |
| 403 | |
|
5560
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
404 PyObject * |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
405 PyObject_GetAttr(v, name) |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
406 PyObject *v; |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
407 PyObject *name; |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
408 { |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
409 if (v->ob_type->tp_getattro != NULL) |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
410 return (*v->ob_type->tp_getattro)(v, name); |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
411 else |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
412 return PyObject_GetAttrString(v, PyString_AsString(name)); |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
413 } |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
414 |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
415 int |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
416 PyObject_HasAttr(v, name) |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
417 PyObject *v; |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
418 PyObject *name; |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
419 { |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
420 PyObject *res = PyObject_GetAttr(v, name); |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
421 if (res != NULL) { |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
422 Py_DECREF(res); |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
423 return 1; |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
424 } |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
425 PyErr_Clear(); |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
426 return 0; |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
427 } |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
428 |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
429 int |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
430 PyObject_SetAttr(v, name, value) |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
431 PyObject *v; |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
432 PyObject *name; |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
433 PyObject *value; |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
434 { |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
435 int err; |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
436 Py_INCREF(name); |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
437 PyString_InternInPlace(&name); |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
438 if (v->ob_type->tp_setattro != NULL) |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
439 err = (*v->ob_type->tp_setattro)(v, name, value); |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
440 else |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
441 err = PyObject_SetAttrString( |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
442 v, PyString_AsString(name), value); |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
443 Py_DECREF(name); |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
444 return err; |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
445 } |
|
8ec298b255a2
Moved PyObject_{Get,Set}Attr here (from dictobject) and add PyObject_HasAttr.
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
446 |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
447 /* Test a value used as condition, e.g., in a for or if statement. |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
448 Return -1 if an error occurred */ |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
449 |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
450 int |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
451 PyObject_IsTrue(v) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
452 PyObject *v; |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
453 { |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
454 int res; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
455 if (v == Py_None) |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
456 res = 0; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
457 else if (v->ob_type->tp_as_number != NULL) |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
458 res = (*v->ob_type->tp_as_number->nb_nonzero)(v); |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
459 else if (v->ob_type->tp_as_mapping != NULL) |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
460 res = (*v->ob_type->tp_as_mapping->mp_length)(v); |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
461 else if (v->ob_type->tp_as_sequence != NULL) |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
462 res = (*v->ob_type->tp_as_sequence->sq_length)(v); |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
463 else |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
464 res = 1; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
465 if (res > 0) |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
466 res = 1; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
467 return res; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
468 } |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
469 |
|
2113
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
470 /* Coerce two numeric types to the "larger" one. |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
471 Increment the reference count on each argument. |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
472 Return -1 and raise an exception if no coercion is possible |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
473 (and then no reference count is incremented). |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
474 */ |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
475 |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
476 int |
|
6597
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
477 PyNumber_CoerceEx(pv, pw) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
478 PyObject **pv, **pw; |
|
2113
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
479 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
480 register PyObject *v = *pv; |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
481 register PyObject *w = *pw; |
|
2113
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
482 int res; |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
483 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
484 if (v->ob_type == w->ob_type && !PyInstance_Check(v)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
485 Py_INCREF(v); |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
486 Py_INCREF(w); |
|
2113
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
487 return 0; |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
488 } |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
489 if (v->ob_type->tp_as_number && v->ob_type->tp_as_number->nb_coerce) { |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
490 res = (*v->ob_type->tp_as_number->nb_coerce)(pv, pw); |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
491 if (res <= 0) |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
492 return res; |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
493 } |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
494 if (w->ob_type->tp_as_number && w->ob_type->tp_as_number->nb_coerce) { |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
495 res = (*w->ob_type->tp_as_number->nb_coerce)(pw, pv); |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
496 if (res <= 0) |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
497 return res; |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
498 } |
|
6597
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
499 return 1; |
|
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
500 } |
|
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
501 |
|
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
502 int |
|
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
503 PyNumber_Coerce(pv, pw) |
|
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
504 PyObject **pv, **pw; |
|
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
505 { |
|
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
506 int err = PyNumber_CoerceEx(pv, pw); |
|
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
507 if (err <= 0) |
|
b88fd3894d5a
Add a new function PyNumber_CoerceEx() which works just like
Guido van Rossum <guido@python.org>
parents:
5981
diff
changeset
|
508 return err; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
509 PyErr_SetString(PyExc_TypeError, "number coercion failed"); |
|
2113
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
510 return -1; |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
511 } |
|
76c860a18d82
move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently
Guido van Rossum <guido@python.org>
parents:
2079
diff
changeset
|
512 |
| 6 | 513 |
| 2237 | 514 /* Test whether an object can be called */ |
| 515 | |
| 516 int | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
517 PyCallable_Check(x) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
518 PyObject *x; |
| 2237 | 519 { |
| 520 if (x == NULL) | |
| 521 return 0; | |
| 522 if (x->ob_type->tp_call != NULL || | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
523 PyFunction_Check(x) || |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
524 PyMethod_Check(x) || |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
525 PyCFunction_Check(x) || |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
526 PyClass_Check(x)) |
| 2237 | 527 return 1; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
528 if (PyInstance_Check(x)) { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
529 PyObject *call = PyObject_GetAttrString(x, "__call__"); |
| 2237 | 530 if (call == NULL) { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
531 PyErr_Clear(); |
| 2237 | 532 return 0; |
| 533 } | |
| 534 /* Could test recursively but don't, for fear of endless | |
| 535 recursion if some joker sets self.__call__ = self */ | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
536 Py_DECREF(call); |
| 2237 | 537 return 1; |
| 538 } | |
| 539 return 0; | |
| 540 } | |
| 541 | |
| 542 | |
| 6 | 543 /* |
| 544 NoObject is usable as a non-NULL undefined value, used by the macro None. | |
| 545 There is (and should be!) no way to create other objects of this type, | |
| 86 | 546 so there is exactly one (which is indestructible, by the way). |
| 6 | 547 */ |
| 548 | |
| 739 | 549 /* ARGSUSED */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
550 static PyObject * |
| 86 | 551 none_repr(op) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
552 PyObject *op; |
| 86 | 553 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
554 return PyString_FromString("None"); |
| 6 | 555 } |
| 556 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
557 static PyTypeObject PyNothing_Type = { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
558 PyObject_HEAD_INIT(&PyType_Type) |
| 6 | 559 0, |
| 86 | 560 "None", |
| 6 | 561 0, |
| 562 0, | |
| 563 0, /*tp_dealloc*/ /*never called*/ | |
|
1051
f54e64c8b9b7
* Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents:
1017
diff
changeset
|
564 0, /*tp_print*/ |
| 86 | 565 0, /*tp_getattr*/ |
| 566 0, /*tp_setattr*/ | |
| 567 0, /*tp_compare*/ | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
568 (reprfunc)none_repr, /*tp_repr*/ |
| 86 | 569 0, /*tp_as_number*/ |
| 570 0, /*tp_as_sequence*/ | |
| 571 0, /*tp_as_mapping*/ | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
572 0, /*tp_hash */ |
| 6 | 573 }; |
| 574 | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
575 PyObject _Py_NoneStruct = { |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
576 PyObject_HEAD_INIT(&PyNothing_Type) |
| 6 | 577 }; |
| 578 | |
| 579 | |
|
3574
1ec154241747
TRACE_REFS -> Py_TRACE_REFS.
Guido van Rossum <guido@python.org>
parents:
3330
diff
changeset
|
580 #ifdef Py_TRACE_REFS |
| 6 | 581 |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
582 static PyObject refchain = {&refchain, &refchain}; |
| 6 | 583 |
|
4002
4241582636ad
Define reference count admin debug functions to return void.
Guido van Rossum <guido@python.org>
parents:
3986
diff
changeset
|
584 void |
|
5931
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
585 _Py_ResetReferences() |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
586 { |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
587 refchain._ob_prev = refchain._ob_next = &refchain; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
588 _Py_RefTotal = 0; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
589 } |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
590 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
591 void |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
592 _Py_NewReference(op) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
593 PyObject *op; |
| 6 | 594 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
595 _Py_RefTotal++; |
| 6 | 596 op->ob_refcnt = 1; |
| 597 op->_ob_next = refchain._ob_next; | |
| 598 op->_ob_prev = &refchain; | |
| 599 refchain._ob_next->_ob_prev = op; | |
| 600 refchain._ob_next = op; | |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
601 #ifdef COUNT_ALLOCS |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
602 inc_count(op->ob_type); |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
603 #endif |
| 6 | 604 } |
| 605 | |
|
4002
4241582636ad
Define reference count admin debug functions to return void.
Guido van Rossum <guido@python.org>
parents:
3986
diff
changeset
|
606 void |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
607 _Py_ForgetReference(op) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
608 register PyObject *op; |
| 6 | 609 { |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
610 register PyObject *p; |
|
2053
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1869
diff
changeset
|
611 if (op->ob_refcnt < 0) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
612 Py_FatalError("UNREF negative refcnt"); |
|
1017
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
613 if (op == &refchain || |
|
2053
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1869
diff
changeset
|
614 op->_ob_prev->_ob_next != op || op->_ob_next->_ob_prev != op) |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
615 Py_FatalError("UNREF invalid object"); |
|
1017
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
616 #ifdef SLOW_UNREF_CHECK |
| 86 | 617 for (p = refchain._ob_next; p != &refchain; p = p->_ob_next) { |
| 618 if (p == op) | |
| 619 break; | |
| 620 } | |
|
2053
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1869
diff
changeset
|
621 if (p == &refchain) /* Not found */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
622 Py_FatalError("UNREF unknown object"); |
|
1017
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
623 #endif |
| 6 | 624 op->_ob_next->_ob_prev = op->_ob_prev; |
| 625 op->_ob_prev->_ob_next = op->_ob_next; | |
|
1017
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
626 op->_ob_next = op->_ob_prev = NULL; |
|
2639
f11ba9cc342f
change in counting freed objects
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
627 #ifdef COUNT_ALLOCS |
|
f11ba9cc342f
change in counting freed objects
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
628 op->ob_type->tp_free++; |
|
f11ba9cc342f
change in counting freed objects
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
629 #endif |
| 86 | 630 } |
| 631 | |
|
4002
4241582636ad
Define reference count admin debug functions to return void.
Guido van Rossum <guido@python.org>
parents:
3986
diff
changeset
|
632 void |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
633 _Py_Dealloc(op) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
634 PyObject *op; |
| 86 | 635 { |
|
1869
2cede61e9b1b
rearranged code in debugging version of DELREF to avoid touching data
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
636 destructor dealloc = op->ob_type->tp_dealloc; |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
637 _Py_ForgetReference(op); |
|
1017
cb7ef9bd9ede
If a type has a repr function but no print function, printing it now
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
638 op->ob_type = NULL; |
|
1869
2cede61e9b1b
rearranged code in debugging version of DELREF to avoid touching data
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
639 (*dealloc)(op); |
| 6 | 640 } |
| 641 | |
|
4002
4241582636ad
Define reference count admin debug functions to return void.
Guido van Rossum <guido@python.org>
parents:
3986
diff
changeset
|
642 void |
|
3609
0b0c4ed1936a
rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
3574
diff
changeset
|
643 _Py_PrintReferences(fp) |
| 6 | 644 FILE *fp; |
| 645 { | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
646 PyObject *op; |
|
5931
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
647 fprintf(fp, "Remaining objects:\n"); |
| 6 | 648 for (op = refchain._ob_next; op != &refchain; op = op->_ob_next) { |
| 649 fprintf(fp, "[%d] ", op->ob_refcnt); | |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
650 if (PyObject_Print(op, fp, 0) != 0) |
|
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
651 PyErr_Clear(); |
| 6 | 652 putc('\n', fp); |
| 653 } | |
| 654 } | |
| 655 | |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
656 PyObject * |
|
3609
0b0c4ed1936a
rename printrefs, getobjects to _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
3574
diff
changeset
|
657 _Py_GetObjects(self, args) |
|
3024
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
658 PyObject *self; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
659 PyObject *args; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
660 { |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
661 int i, n; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
662 PyObject *t = NULL; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
663 PyObject *res, *op; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
664 |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
665 if (!PyArg_ParseTuple(args, "i|O", &n, &t)) |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
666 return NULL; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
667 op = refchain._ob_next; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
668 res = PyList_New(0); |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
669 if (res == NULL) |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
670 return NULL; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
671 for (i = 0; (n == 0 || i < n) && op != &refchain; i++) { |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
672 while (op == self || op == args || op == res || op == t || |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
673 t != NULL && op->ob_type != (PyTypeObject *) t) { |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
674 op = op->_ob_next; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
675 if (op == &refchain) |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
676 return res; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
677 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
678 if (PyList_Append(res, op) < 0) { |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
679 Py_DECREF(res); |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
680 return NULL; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
681 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
682 op = op->_ob_next; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
683 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
684 return res; |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
685 } |
|
54aa87b1ccee
Implemented two new functions in sys:
Sjoerd Mullender <sjoerd@acm.org>
parents:
2827
diff
changeset
|
686 |
| 6 | 687 #endif |
|
3330
9f1b6e2db8e0
Hack to force loading of cobject.o
Guido van Rossum <guido@python.org>
parents:
3024
diff
changeset
|
688 |
|
9f1b6e2db8e0
Hack to force loading of cobject.o
Guido van Rossum <guido@python.org>
parents:
3024
diff
changeset
|
689 |
|
9f1b6e2db8e0
Hack to force loading of cobject.o
Guido van Rossum <guido@python.org>
parents:
3024
diff
changeset
|
690 /* Hack to force loading of cobject.o */ |
| 4588 | 691 PyTypeObject *_Py_cobject_hack = &PyCObject_Type; |
|
3574
1ec154241747
TRACE_REFS -> Py_TRACE_REFS.
Guido van Rossum <guido@python.org>
parents:
3330
diff
changeset
|
692 |
|
1ec154241747
TRACE_REFS -> Py_TRACE_REFS.
Guido van Rossum <guido@python.org>
parents:
3330
diff
changeset
|
693 |
|
1ec154241747
TRACE_REFS -> Py_TRACE_REFS.
Guido van Rossum <guido@python.org>
parents:
3330
diff
changeset
|
694 /* Hack to force loading of abstract.o */ |
|
5396
d1447950fa04
Quickly renamed the last directory.
Guido van Rossum <guido@python.org>
parents:
5006
diff
changeset
|
695 int (*_Py_abstract_hack) Py_FPROTO((PyObject *)) = &PyObject_Length; |
|
5931
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
696 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
697 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
698 /* Malloc wrappers (see mymalloc.h) */ |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
699 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
700 /* The Py_{Malloc,Realloc} wrappers call PyErr_NoMemory() on failure */ |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
701 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
702 ANY * |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
703 Py_Malloc(nbytes) |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
704 size_t nbytes; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
705 { |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
706 ANY *p; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
707 #if _PyMem_EXTRA > 0 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
708 if (nbytes == 0) |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
709 nbytes = _PyMem_EXTRA; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
710 #endif |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
711 p = malloc(nbytes); |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
712 if (p != NULL) |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
713 return p; |
|
5981
170c46a65022
Fix mixup about PyErr_NoMemory() prototype.
Guido van Rossum <guido@python.org>
parents:
5931
diff
changeset
|
714 else { |
|
170c46a65022
Fix mixup about PyErr_NoMemory() prototype.
Guido van Rossum <guido@python.org>
parents:
5931
diff
changeset
|
715 PyErr_NoMemory(); |
|
170c46a65022
Fix mixup about PyErr_NoMemory() prototype.
Guido van Rossum <guido@python.org>
parents:
5931
diff
changeset
|
716 return NULL; |
|
170c46a65022
Fix mixup about PyErr_NoMemory() prototype.
Guido van Rossum <guido@python.org>
parents:
5931
diff
changeset
|
717 } |
|
5931
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
718 } |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
719 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
720 ANY * |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
721 Py_Realloc(p, nbytes) |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
722 ANY *p; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
723 size_t nbytes; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
724 { |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
725 #if _PyMem_EXTRA > 0 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
726 if (nbytes == 0) |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
727 nbytes = _PyMem_EXTRA; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
728 #endif |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
729 p = realloc(p, nbytes); |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
730 if (p != NULL) |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
731 return p; |
|
5981
170c46a65022
Fix mixup about PyErr_NoMemory() prototype.
Guido van Rossum <guido@python.org>
parents:
5931
diff
changeset
|
732 else { |
|
170c46a65022
Fix mixup about PyErr_NoMemory() prototype.
Guido van Rossum <guido@python.org>
parents:
5931
diff
changeset
|
733 PyErr_NoMemory(); |
|
170c46a65022
Fix mixup about PyErr_NoMemory() prototype.
Guido van Rossum <guido@python.org>
parents:
5931
diff
changeset
|
734 return NULL; |
|
170c46a65022
Fix mixup about PyErr_NoMemory() prototype.
Guido van Rossum <guido@python.org>
parents:
5931
diff
changeset
|
735 } |
|
5931
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
736 } |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
737 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
738 void |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
739 Py_Free(p) |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
740 ANY *p; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
741 { |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
742 free(p); |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
743 } |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
744 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
745 /* The PyMem_{Malloc,Realloc} wrappers don't call anything on failure */ |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
746 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
747 ANY * |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
748 PyMem_Malloc(nbytes) |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
749 size_t nbytes; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
750 { |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
751 #if _PyMem_EXTRA > 0 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
752 if (nbytes == 0) |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
753 nbytes = _PyMem_EXTRA; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
754 #endif |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
755 return malloc(nbytes); |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
756 } |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
757 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
758 ANY * |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
759 PyMem_Realloc(p, nbytes) |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
760 ANY *p; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
761 size_t nbytes; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
762 { |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
763 #if _PyMem_EXTRA > 0 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
764 if (nbytes == 0) |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
765 nbytes = _PyMem_EXTRA; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
766 #endif |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
767 return realloc(p, nbytes); |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
768 } |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
769 |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
770 void |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
771 PyMem_Free(p) |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
772 ANY *p; |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
773 { |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
774 free(p); |
|
12fe5cc1516d
Added _Py_ResetReferences(), if tracing references.
Guido van Rossum <guido@python.org>
parents:
5610
diff
changeset
|
775 } |
