annotate Objects/object.c @ 1330:409ea74feb21 legacy-trunk

Minor fixes / changes for Mac compatibility.
author Guido van Rossum <guido@python.org>
date Thu, 29 Jul 1993 08:25:09 +0000
parents 716be765a79b
children a22a350d3a5d
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 object *
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 newobject(tp)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 typeobject *tp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 object *op = (object *) malloc(tp->tp_basicsize);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 if (op == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 return err_nomem();
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 NEWREF(op);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 op->ob_type = tp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 return op;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 varobject *
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 newvarobject(tp, size)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 typeobject *tp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 unsigned int size;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 varobject *op = (varobject *)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 malloc(tp->tp_basicsize + size * tp->tp_itemsize);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 if (op == NULL)
231
b31abf420e61 Enabled (and fixed) newvarobject()
Guido van Rossum <guido@python.org>
parents: 145
diff changeset
57 return (varobject *)err_nomem();
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 NEWREF(op);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 op->ob_type = tp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 op->ob_size = size;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 return op;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
64 int
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 printobject(op, fp, flags)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 object *op;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 FILE *fp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 int flags;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 {
322
1a6cf1f8ccec Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents: 307
diff changeset
70 int ret = 0;
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
71 if (intrcheck()) {
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
72 err_set(KeyboardInterrupt);
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
73 return -1;
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
74 }
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
75 if (op == NULL) {
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
76 fprintf(fp, "<nil>");
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 }
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
78 else {
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
79 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
80 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
81 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
82 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
83 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
84 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
85 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
86 }
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
87 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
88 object *s = reprobject(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
89 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
90 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
91 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
92 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
93 "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
94 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
95 }
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
96 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
97 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
98 }
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
99 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
100 }
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
101 }
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
102 else
322
1a6cf1f8ccec Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents: 307
diff changeset
103 ret = (*op->ob_type->tp_print)(op, fp, flags);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 }
322
1a6cf1f8ccec Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents: 307
diff changeset
105 if (ret == 0) {
1a6cf1f8ccec Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents: 307
diff changeset
106 if (ferror(fp)) {
473
4a7f0f06cd27 Use IOError.
Guido van Rossum <guido@python.org>
parents: 322
diff changeset
107 err_errno(IOError);
322
1a6cf1f8ccec Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents: 307
diff changeset
108 clearerr(fp);
1a6cf1f8ccec Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents: 307
diff changeset
109 ret = -1;
1a6cf1f8ccec Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents: 307
diff changeset
110 }
1a6cf1f8ccec Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents: 307
diff changeset
111 }
1a6cf1f8ccec Check for write errors after printing a value
Guido van Rossum <guido@python.org>
parents: 307
diff changeset
112 return ret;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
114
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 object *
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 reprobject(v)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 object *v;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 {
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
119 if (intrcheck()) {
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 err_set(KeyboardInterrupt);
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
121 return NULL;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 }
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
123 if (v == NULL)
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
124 return newstringobject("<NULL>");
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
125 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
126 char buf[120];
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
127 sprintf(buf, "<%.80s object at %lx>",
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
128 v->ob_type->tp_name, (long)v);
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
129 return newstringobject(buf);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 }
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
131 else
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
132 return (*v->ob_type->tp_repr)(v);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
134
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 int
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 cmpobject(v, w)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 object *v, *w;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 typeobject *tp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 if (v == w)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 return 0;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 if (v == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 return -1;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 if (w == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 return 1;
307
35a2528f8a73 Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
146 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
147 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
148 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
149 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
150 err_clear();
35a2528f8a73 Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
151 /* 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
152 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
153 }
35a2528f8a73 Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
154 else {
35a2528f8a73 Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
155 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
156 DECREF(v);
35a2528f8a73 Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
157 DECREF(w);
35a2528f8a73 Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
158 return cmp;
35a2528f8a73 Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
159 }
35a2528f8a73 Change cmpobject() to coerce numerical values before comparing them
Guido van Rossum <guido@python.org>
parents: 284
diff changeset
160 }
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 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
162 }
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 if (tp->tp_compare == NULL)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 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
165 return (*tp->tp_compare)(v, w);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
167
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
168 long
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
169 hashobject(v)
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
170 object *v;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
171 {
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
172 typeobject *tp = v->ob_type;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
173 if (tp->tp_hash != NULL)
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
174 return (*tp->tp_hash)(v);
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
175 if (tp->tp_compare == NULL)
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
176 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
177 /* 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
178 err_setstr(TypeError, "unhashable type");
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
179 return -1;
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
180 }
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
181
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
182 object *
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
183 getattr(v, name)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
184 object *v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
185 char *name;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
186 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
187 if (v->ob_type->tp_getattr == NULL) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
188 err_setstr(TypeError, "attribute-less object");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
189 return NULL;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
190 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
191 else {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
192 return (*v->ob_type->tp_getattr)(v, name);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
193 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
194 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
195
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
196 int
1324
716be765a79b * accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
197 hasattr(v, name)
716be765a79b * accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
198 object *v;
716be765a79b * accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
199 char *name;
716be765a79b * accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
200 {
716be765a79b * accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
201 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
202 if (res != NULL) {
716be765a79b * accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
203 DECREF(res);
716be765a79b * accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
204 return 1;
716be765a79b * accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
205 }
716be765a79b * accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
206 err_clear();
716be765a79b * accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
207 return 0;
716be765a79b * accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
208 }
716be765a79b * accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
209
716be765a79b * accessobject.c (ownercheck): allow a base class access to protected
Guido van Rossum <guido@python.org>
parents: 1282
diff changeset
210 int
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
211 setattr(v, name, w)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
212 object *v;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
213 char *name;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
214 object *w;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
215 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
216 if (v->ob_type->tp_setattr == NULL) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
217 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
218 err_setstr(TypeError,
8414e1f9a5fe Change error messages for impossible assignment slightly.
Guido van Rossum <guido@python.org>
parents: 473
diff changeset
219 "attribute-less object (assign or del)");
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
220 else
512
8414e1f9a5fe Change error messages for impossible assignment slightly.
Guido van Rossum <guido@python.org>
parents: 473
diff changeset
221 err_setstr(TypeError,
8414e1f9a5fe Change error messages for impossible assignment slightly.
Guido van Rossum <guido@python.org>
parents: 473
diff changeset
222 "object has read-only attributes");
95
a5bf7d5959ce Return -1 for errors.
Guido van Rossum <guido@python.org>
parents: 86
diff changeset
223 return -1;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
224 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
225 else {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
226 return (*v->ob_type->tp_setattr)(v, name, w);
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
227 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
228 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
229
1282
e0464e7115ca * pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
230 /* 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
231 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
232
e0464e7115ca * pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
233 int
e0464e7115ca * pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
234 testbool(v)
e0464e7115ca * pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
235 object *v;
e0464e7115ca * pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
236 {
e0464e7115ca * pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
237 int res;
e0464e7115ca * pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
238 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
239 res = 0;
e0464e7115ca * pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
240 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
241 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
242 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
243 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
244 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
245 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
246 else
e0464e7115ca * pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
247 res = 1;
e0464e7115ca * pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
248 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
249 res = 1;
e0464e7115ca * pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
250 return res;
e0464e7115ca * pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
251 }
e0464e7115ca * pythonrun.c: Print exception type+arg *after* stack trace instead of
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
252
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
253
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 /*
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 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
256 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
257 so there is exactly one (which is indestructible, by the way).
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
259
739
ab1b3486b226 Fix lint bug
Guido van Rossum <guido@python.org>
parents: 512
diff changeset
260 /* ARGSUSED */
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
261 static object *
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
262 none_repr(op)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
263 object *op;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
264 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
265 return newstringobject("None");
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
267
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 static typeobject Notype = {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 OB_HEAD_INIT(&Typetype)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 0,
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
271 "None",
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
272 0,
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 0,
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 0, /*tp_dealloc*/ /*never called*/
1051
f54e64c8b9b7 * Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents: 1017
diff changeset
275 0, /*tp_print*/
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
276 0, /*tp_getattr*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
277 0, /*tp_setattr*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
278 0, /*tp_compare*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
279 none_repr, /*tp_repr*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
280 0, /*tp_as_number*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
281 0, /*tp_as_sequence*/
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
282 0, /*tp_as_mapping*/
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1051
diff changeset
283 0, /*tp_hash */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 };
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
285
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
286 object NoObject = {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 OB_HEAD_INIT(&Notype)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
288 };
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
289
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
290
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 #ifdef TRACE_REFS
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
292
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 static object refchain = {&refchain, &refchain};
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
294
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
295 NEWREF(op)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 object *op;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 ref_total++;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
299 op->ob_refcnt = 1;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 op->_ob_next = refchain._ob_next;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 op->_ob_prev = &refchain;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
302 refchain._ob_next->_ob_prev = op;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
303 refchain._ob_next = op;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
304 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
305
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
306 UNREF(op)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
307 register object *op;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
308 {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
309 register object *p;
58
4975f7990b2b Removed redundant prototype for err_nomem().
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
310 if (op->ob_refcnt < 0) {
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
311 fprintf(stderr, "UNREF negative refcnt\n");
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
312 abort();
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
313 }
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
314 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
315 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
316 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
317 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
318 }
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
319 #ifdef SLOW_UNREF_CHECK
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
320 for (p = refchain._ob_next; p != &refchain; p = p->_ob_next) {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
321 if (p == op)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
322 break;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
323 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
324 if (p == &refchain) { /* Not found */
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
325 fprintf(stderr, "UNREF unknown object\n");
58
4975f7990b2b Removed redundant prototype for err_nomem().
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
326 abort();
4975f7990b2b Removed redundant prototype for err_nomem().
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
327 }
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
328 #endif
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 op->_ob_next->_ob_prev = op->_ob_prev;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 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
331 op->_ob_next = op->_ob_prev = NULL;
86
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
332 }
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
333
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
334 DELREF(op)
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
335 object *op;
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
336 {
a6934380c6e7 "Compiling" version
Guido van Rossum <guido@python.org>
parents: 58
diff changeset
337 UNREF(op);
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 (*(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
339 op->ob_type = NULL;
6
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
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 printrefs(fp)
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
343 FILE *fp;
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 {
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 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
346 fprintf(fp, "Remaining objects (except strings referenced once):\n");
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
347 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
348 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
349 continue; /* Will be printed elsewhere */
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 fprintf(fp, "[%d] ", op->ob_refcnt);
284
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
351 if (printobject(op, fp, 0) != 0)
6ac402023cac printobject now returns an error code
Guido van Rossum <guido@python.org>
parents: 231
diff changeset
352 err_clear();
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
353 putc('\n', fp);
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
354 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 }
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
356
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
357 #endif