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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
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
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
4
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
5 All Rights Reserved
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
6
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
8 documentation for any purpose and without fee is hereby granted,
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
9 provided that the above copyright notice appear in all copies and that
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
10 both that copyright notice and this permission notice appear in
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
13 distribution of the software without specific, written prior permission.
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
14
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
22
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
23 ******************************************************************/
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 95
diff changeset
24
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
25 /* Generic object operations; and implementation of None (NoObject) */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
27 #include "allobjects.h"
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
29 #ifdef REF_DEBUG
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
30 long ref_total;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
31 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
33 /* Object allocation routines used by NEWOBJ and NEWVAROBJ macros.
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
34 These are used by the individual routines for object creation.
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
35 Do not call them otherwise, they do not initialize the object! */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 object *
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 newobject(tp)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 typeobject *tp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 object *op = (object *) malloc(tp->tp_basicsize);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 if (op == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 NEWREF(op);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 return op;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
87
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 varobject *
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 newvarobject(tp, size)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 typeobject *tp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 unsigned int size;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 varobject *op = (varobject *)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 malloc(tp->tp_basicsize + size * tp->tp_itemsize);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 op->ob_type = tp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 return op;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
102
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
103 int
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 printobject(op, fp, flags)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 object *op;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 FILE *fp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 int flags;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
4a7f0f06cd27 Use IOError.
Guido van Rossum <guido@python.org>
parents: 322
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
157
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 object *
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 reprobject(v)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 object *v;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 {
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
162 if (intrcheck()) {
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 int
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 cmpobject(v, w)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 object *v, *w;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 typeobject *tp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
213 if (v == w)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 return 0;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 if (v == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
216 return -1;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 if (w == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 if (tp->tp_compare == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
255 object *
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
256 getattr(v, name)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
257 object *v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
258 char *name;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
259 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
260 if (v->ob_type->tp_getattr == NULL) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
261 err_setstr(TypeError, "attribute-less object");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
262 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
263 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
264 else {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
265 return (*v->ob_type->tp_getattr)(v, name);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
266 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
267 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
268
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
284 setattr(v, name, w)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
285 object *v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
286 char *name;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
287 object *w;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
288 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
289 if (v->ob_type->tp_setattr == NULL) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
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
a5bf7d5959ce Return -1 for errors.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
296 return -1;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
297 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
298 else {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
299 return (*v->ob_type->tp_setattr)(v, name, w);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
300 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
301 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
326
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 /*
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 NoObject is usable as a non-NULL undefined value, used by the macro None.
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 There is (and should be!) no way to create other objects of this type,
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
330 so there is exactly one (which is indestructible, by the way).
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
332
739
ab1b3486b226 Fix lint bug
Guido van Rossum <guido@python.org>
parents: 512
diff changeset
333 /* ARGSUSED */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
334 static object *
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
335 none_repr(op)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
336 object *op;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
337 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
338 return newstringobject("None");
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
340
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 static typeobject Notype = {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 OB_HEAD_INIT(&Typetype)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
343 0,
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
344 "None",
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 0,
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 0,
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
349 0, /*tp_getattr*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
350 0, /*tp_setattr*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
351 0, /*tp_compare*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
352 none_repr, /*tp_repr*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
353 0, /*tp_as_number*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
354 0, /*tp_as_sequence*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
357 };
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
358
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
359 object NoObject = {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 OB_HEAD_INIT(&Notype)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 };
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
362
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
363
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 #ifdef TRACE_REFS
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
365
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 static object refchain = {&refchain, &refchain};
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
367
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 NEWREF(op)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 object *op;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 ref_total++;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 op->ob_refcnt = 1;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
373 op->_ob_next = refchain._ob_next;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 op->_ob_prev = &refchain;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 refchain._ob_next->_ob_prev = op;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
381
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
382 UNREF(op)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
383 register object *op;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
387 fprintf(stderr, "UNREF negative refcnt\n");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
388 abort();
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
396 for (p = refchain._ob_next; p != &refchain; p = p->_ob_next) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
397 if (p == op)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
398 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
399 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
400 if (p == &refchain) { /* Not found */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
405 op->_ob_next->_ob_prev = op->_ob_prev;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
408 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
409
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
410 DELREF(op)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
411 object *op;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
412 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
419 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
420
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
421 printrefs(fp)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
422 FILE *fp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 putc('\n', fp);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
433 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
435
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
436 #endif