Mercurial > cpython-lru_cache-weakref
annotate Objects/object.c @ 1590:ac2e5cc29949 legacy-trunk
Added tests for missing host to open_http and open_gopher
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 18 Apr 1994 09:39:56 +0000 |
| parents | aac8231a715c |
| children | b724599401ff |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
2 Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
3 Amsterdam, The Netherlands. |
| 145 | 4 |
| 5 All Rights Reserved | |
| 6 | |
| 7 Permission to use, copy, modify, and distribute this software and its | |
| 8 documentation for any purpose and without fee is hereby granted, | |
| 9 provided that the above copyright notice appear in all copies and that | |
| 10 both that copyright notice and this permission notice appear in | |
| 11 supporting documentation, and that the names of Stichting Mathematisch | |
| 12 Centrum or CWI not be used in advertising or publicity pertaining to | |
| 13 distribution of the software without specific, written prior permission. | |
| 14 | |
| 15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| 16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | |
| 18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
| 19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
| 20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
| 21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
| 86 | 25 /* Generic object operations; and implementation of None (NoObject) */ |
| 6 | 26 |
| 86 | 27 #include "allobjects.h" |
| 6 | 28 |
| 86 | 29 #ifdef REF_DEBUG |
| 30 long ref_total; | |
| 31 #endif | |
| 6 | 32 |
| 86 | 33 /* Object allocation routines used by NEWOBJ and NEWVAROBJ macros. |
| 34 These are used by the individual routines for object creation. | |
| 35 Do not call them otherwise, they do not initialize the object! */ | |
| 6 | 36 |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
37 #ifdef COUNT_ALLOCS |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
38 static typeobject *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
|
39 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
|
40 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
|
41 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
|
42 void |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
43 dump_counts() |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
44 { |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
45 typeobject *tp; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
46 |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 null_strings, one_strings); |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
57 } |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
58 |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
59 void |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
60 inc_count(tp) |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
61 typeobject *tp; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
62 { |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
63 if (tp->tp_alloc == 0) { |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
64 /* first time; hang in linked list */ |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
65 if (tp->tp_next != NULL) /* sanity check */ |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
66 abort(); |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
67 tp->tp_next = type_list; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
68 type_list = tp; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
69 } |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
70 tp->tp_alloc++; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
71 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
|
72 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
|
73 } |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
74 #endif |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
75 |
| 6 | 76 object * |
| 77 newobject(tp) | |
| 78 typeobject *tp; | |
| 79 { | |
| 80 object *op = (object *) malloc(tp->tp_basicsize); | |
| 81 if (op == NULL) | |
| 82 return err_nomem(); | |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
83 op->ob_type = tp; |
| 6 | 84 NEWREF(op); |
| 85 return op; | |
| 86 } | |
| 87 | |
| 88 varobject * | |
| 89 newvarobject(tp, size) | |
| 90 typeobject *tp; | |
| 91 unsigned int size; | |
| 92 { | |
| 93 varobject *op = (varobject *) | |
| 94 malloc(tp->tp_basicsize + size * tp->tp_itemsize); | |
| 95 if (op == NULL) | |
|
231
b31abf420e61
Enabled (and fixed) newvarobject()
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
96 return (varobject *)err_nomem(); |
| 6 | 97 op->ob_type = tp; |
| 98 op->ob_size = size; | |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
99 NEWREF(op); |
| 6 | 100 return op; |
| 101 } | |
| 102 | |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
103 int |
| 6 | 104 printobject(op, fp, flags) |
| 105 object *op; | |
| 106 FILE *fp; | |
| 107 int flags; | |
| 108 { | |
|
322
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
109 int ret = 0; |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
110 if (intrcheck()) { |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
111 err_set(KeyboardInterrupt); |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
112 return -1; |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
113 } |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
114 if (op == NULL) { |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
115 fprintf(fp, "<nil>"); |
| 6 | 116 } |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
117 else { |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 } |
|
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
|
126 else { |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
127 object *s; |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
128 if (flags & PRINT_RAW) |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
129 s = strobject(op); |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
130 else |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
131 s = reprobject(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
|
132 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
|
133 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
|
134 else if (!is_stringobject(s)) { |
|
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
|
135 err_setstr(TypeError, |
|
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
|
136 "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
|
137 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
|
138 } |
|
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
|
139 else { |
|
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
|
140 fprintf(fp, "%s", getstringvalue(s)); |
|
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
|
141 } |
|
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
|
142 XDECREF(s); |
|
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
|
143 } |
|
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
|
144 } |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
145 else |
|
322
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
146 ret = (*op->ob_type->tp_print)(op, fp, flags); |
| 6 | 147 } |
|
322
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
148 if (ret == 0) { |
|
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
149 if (ferror(fp)) { |
| 473 | 150 err_errno(IOError); |
|
322
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
151 clearerr(fp); |
|
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
152 ret = -1; |
|
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
153 } |
|
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
154 } |
|
1a6cf1f8ccec
Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents:
307
diff
changeset
|
155 return ret; |
| 6 | 156 } |
| 157 | |
| 158 object * | |
| 159 reprobject(v) | |
| 160 object *v; | |
| 161 { | |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
162 if (intrcheck()) { |
| 6 | 163 err_set(KeyboardInterrupt); |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
164 return NULL; |
| 6 | 165 } |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
166 if (v == NULL) |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
167 return newstringobject("<NULL>"); |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
168 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
|
169 char buf[120]; |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
170 sprintf(buf, "<%.80s object at %lx>", |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
171 v->ob_type->tp_name, (long)v); |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
172 return newstringobject(buf); |
| 6 | 173 } |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
174 else |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
175 return (*v->ob_type->tp_repr)(v); |
| 6 | 176 } |
| 177 | |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
178 object * |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
179 strobject(v) |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
180 object *v; |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
181 { |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
182 if (v == NULL) |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
183 return newstringobject("<NULL>"); |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
184 if (is_stringobject(v)) { |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
185 INCREF(v); |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
186 return v; |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
187 } |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
188 else { |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
189 object *func = getattr(v, "__str__"); |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
190 object *args; |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
191 object *res; |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
192 if (func == NULL) { |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
193 err_clear(); |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
194 return reprobject(v); |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
195 } |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
196 args = newtupleobject(0); |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
197 if (args == NULL) |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
198 res = NULL; |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
199 else { |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
200 res = call_object(func, args); |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
201 DECREF(args); |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
202 } |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
203 DECREF(func); |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
204 return res; |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
205 } |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
206 } |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1361
diff
changeset
|
207 |
| 6 | 208 int |
| 209 cmpobject(v, w) | |
| 210 object *v, *w; | |
| 211 { | |
| 212 typeobject *tp; | |
| 213 if (v == w) | |
| 214 return 0; | |
| 215 if (v == NULL) | |
| 216 return -1; | |
| 217 if (w == NULL) | |
| 218 return 1; | |
|
307
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
219 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
|
220 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
|
221 w->ob_type->tp_as_number != NULL) { |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
222 if (coerce(&v, &w) != 0) { |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
223 err_clear(); |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
224 /* XXX Should report the error, |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
225 XXX but the interface isn't there... */ |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
226 } |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
227 else { |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
228 int cmp = (*v->ob_type->tp_compare)(v, w); |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
229 DECREF(v); |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
230 DECREF(w); |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
231 return cmp; |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
232 } |
|
35a2528f8a73
Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents:
284
diff
changeset
|
233 } |
| 6 | 234 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
|
235 } |
| 6 | 236 if (tp->tp_compare == NULL) |
| 237 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
|
238 return (*tp->tp_compare)(v, w); |
| 6 | 239 } |
| 240 | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
241 long |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
242 hashobject(v) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
243 object *v; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
244 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
245 typeobject *tp = v->ob_type; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
246 if (tp->tp_hash != NULL) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
247 return (*tp->tp_hash)(v); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
248 if (tp->tp_compare == NULL) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
249 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
|
250 /* If there's a cmp but no hash defined, the object can't be hashed */ |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
251 err_setstr(TypeError, "unhashable type"); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
252 return -1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
253 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
254 |
| 86 | 255 object * |
| 256 getattr(v, name) | |
| 257 object *v; | |
| 258 char *name; | |
| 259 { | |
| 260 if (v->ob_type->tp_getattr == NULL) { | |
| 261 err_setstr(TypeError, "attribute-less object"); | |
| 262 return NULL; | |
| 263 } | |
| 264 else { | |
| 265 return (*v->ob_type->tp_getattr)(v, name); | |
| 266 } | |
| 267 } | |
| 268 | |
| 269 int | |
|
1324
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
270 hasattr(v, name) |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
271 object *v; |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
272 char *name; |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
273 { |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
274 object *res = getattr(v, name); |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
275 if (res != NULL) { |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
276 DECREF(res); |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
277 return 1; |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
278 } |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
279 err_clear(); |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
280 return 0; |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
281 } |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
282 |
|
716be765a79b
* accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents:
1282
diff
changeset
|
283 int |
| 86 | 284 setattr(v, name, w) |
| 285 object *v; | |
| 286 char *name; | |
| 287 object *w; | |
| 288 { | |
| 289 if (v->ob_type->tp_setattr == NULL) { | |
| 290 if (v->ob_type->tp_getattr == NULL) | |
|
512
8414e1f9a5fe
Change error messages for impossible assignment slightly.
Guido van Rossum <guido@python.org>
parents:
473
diff
changeset
|
291 err_setstr(TypeError, |
|
8414e1f9a5fe
Change error messages for impossible assignment slightly.
Guido van Rossum <guido@python.org>
parents:
473
diff
changeset
|
292 "attribute-less object (assign or del)"); |
| 86 | 293 else |
|
512
8414e1f9a5fe
Change error messages for impossible assignment slightly.
Guido van Rossum <guido@python.org>
parents:
473
diff
changeset
|
294 err_setstr(TypeError, |
|
8414e1f9a5fe
Change error messages for impossible assignment slightly.
Guido van Rossum <guido@python.org>
parents:
473
diff
changeset
|
295 "object has read-only attributes"); |
| 95 | 296 return -1; |
| 86 | 297 } |
| 298 else { | |
| 299 return (*v->ob_type->tp_setattr)(v, name, w); | |
| 300 } | |
| 301 } | |
| 302 | |
|
1282
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
303 /* 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
|
304 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
|
305 |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
306 int |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
307 testbool(v) |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
308 object *v; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
309 { |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
310 int res; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
311 if (v == None) |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
312 res = 0; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 else |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
320 res = 1; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
321 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
|
322 res = 1; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
323 return res; |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
324 } |
|
e0464e7115ca
* pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
325 |
| 6 | 326 |
| 327 /* | |
| 328 NoObject is usable as a non-NULL undefined value, used by the macro None. | |
| 329 There is (and should be!) no way to create other objects of this type, | |
| 86 | 330 so there is exactly one (which is indestructible, by the way). |
| 6 | 331 */ |
| 332 | |
| 739 | 333 /* ARGSUSED */ |
| 86 | 334 static object * |
| 335 none_repr(op) | |
| 336 object *op; | |
| 337 { | |
| 338 return newstringobject("None"); | |
| 6 | 339 } |
| 340 | |
| 341 static typeobject Notype = { | |
| 342 OB_HEAD_INIT(&Typetype) | |
| 343 0, | |
| 86 | 344 "None", |
| 6 | 345 0, |
| 346 0, | |
| 347 0, /*tp_dealloc*/ /*never called*/ | |
|
1051
f54e64c8b9b7
* Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents:
1017
diff
changeset
|
348 0, /*tp_print*/ |
| 86 | 349 0, /*tp_getattr*/ |
| 350 0, /*tp_setattr*/ | |
| 351 0, /*tp_compare*/ | |
| 352 none_repr, /*tp_repr*/ | |
| 353 0, /*tp_as_number*/ | |
| 354 0, /*tp_as_sequence*/ | |
| 355 0, /*tp_as_mapping*/ | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
356 0, /*tp_hash */ |
| 6 | 357 }; |
| 358 | |
| 359 object NoObject = { | |
| 360 OB_HEAD_INIT(&Notype) | |
| 361 }; | |
| 362 | |
| 363 | |
| 364 #ifdef TRACE_REFS | |
| 365 | |
| 366 static object refchain = {&refchain, &refchain}; | |
| 367 | |
| 368 NEWREF(op) | |
| 369 object *op; | |
| 370 { | |
| 371 ref_total++; | |
| 372 op->ob_refcnt = 1; | |
| 373 op->_ob_next = refchain._ob_next; | |
| 374 op->_ob_prev = &refchain; | |
| 375 refchain._ob_next->_ob_prev = op; | |
| 376 refchain._ob_next = op; | |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
377 #ifdef COUNT_ALLOCS |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
378 inc_count(op->ob_type); |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
379 #endif |
| 6 | 380 } |
| 381 | |
| 86 | 382 UNREF(op) |
| 383 register object *op; | |
| 6 | 384 { |
| 86 | 385 register object *p; |
|
58
4975f7990b2b
Removed redundant prototype for err_nomem().
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
386 if (op->ob_refcnt < 0) { |
| 86 | 387 fprintf(stderr, "UNREF negative refcnt\n"); |
| 388 abort(); | |
| 389 } | |
|
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
|
390 if (op == &refchain || |
|
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
|
391 op->_ob_prev->_ob_next != op || op->_ob_next->_ob_prev != 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
|
392 fprintf(stderr, "UNREF invalid object\n"); |
|
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
|
393 abort(); |
|
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
|
394 } |
|
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
|
395 #ifdef SLOW_UNREF_CHECK |
| 86 | 396 for (p = refchain._ob_next; p != &refchain; p = p->_ob_next) { |
| 397 if (p == op) | |
| 398 break; | |
| 399 } | |
| 400 if (p == &refchain) { /* Not found */ | |
| 401 fprintf(stderr, "UNREF unknown object\n"); | |
|
58
4975f7990b2b
Removed redundant prototype for err_nomem().
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
402 abort(); |
|
4975f7990b2b
Removed redundant prototype for err_nomem().
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
403 } |
|
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
|
404 #endif |
| 6 | 405 op->_ob_next->_ob_prev = op->_ob_prev; |
| 406 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
|
407 op->_ob_next = op->_ob_prev = NULL; |
| 86 | 408 } |
| 409 | |
| 410 DELREF(op) | |
| 411 object *op; | |
| 412 { | |
| 413 UNREF(op); | |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
414 #ifdef COUNT_ALLOCS |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
415 op->ob_type->tp_free++; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1324
diff
changeset
|
416 #endif |
| 6 | 417 (*(op)->ob_type->tp_dealloc)(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
|
418 op->ob_type = NULL; |
| 6 | 419 } |
| 420 | |
| 421 printrefs(fp) | |
| 422 FILE *fp; | |
| 423 { | |
| 424 object *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
|
425 fprintf(fp, "Remaining objects (except strings referenced once):\n"); |
| 6 | 426 for (op = refchain._ob_next; op != &refchain; op = 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
|
427 if (op->ob_refcnt == 1 && is_stringobject(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
|
428 continue; /* Will be printed elsewhere */ |
| 6 | 429 fprintf(fp, "[%d] ", op->ob_refcnt); |
|
284
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
430 if (printobject(op, fp, 0) != 0) |
|
6ac402023cac
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
231
diff
changeset
|
431 err_clear(); |
| 6 | 432 putc('\n', fp); |
| 433 } | |
| 434 } | |
| 435 | |
| 436 #endif |
