Mercurial > cpython-lru_cache-weakref
annotate Objects/tupleobject.c @ 4439:fb1237bf7022 legacy-trunk
Changed version to plain "1.4".
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 22 Oct 1996 03:09:46 +0000 |
| parents | 36cc3ee54f28 |
| children | 65d2d8e67da3 |
| rev | line source |
|---|---|
| 145 | 1 /*********************************************************** |
|
2059
866c81068dbd
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
866c81068dbd
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
1848
diff
changeset
|
3 The Netherlands. |
| 145 | 4 |
| 5 All Rights Reserved | |
| 6 | |
| 7 Permission to use, copy, modify, and distribute this software and its | |
| 8 documentation for any purpose and without fee is hereby granted, | |
| 9 provided that the above copyright notice appear in all copies and that | |
| 10 both that copyright notice and this permission notice appear in | |
| 11 supporting documentation, and that the names of Stichting Mathematisch | |
| 12 Centrum or CWI not be used in advertising or publicity pertaining to | |
| 13 distribution of the software without specific, written prior permission. | |
| 14 | |
| 15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| 16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | |
| 18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
| 19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
| 20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
| 21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| 22 | |
| 23 ******************************************************************/ | |
| 24 | |
| 6 | 25 /* Tuple object implementation */ |
| 26 | |
| 86 | 27 #include "allobjects.h" |
| 6 | 28 |
|
1352
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
29 #ifndef MAXSAVESIZE |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
30 #define MAXSAVESIZE 20 |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
31 #endif |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
32 |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
33 #if MAXSAVESIZE > 0 |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
34 /* Entries 1 upto MAXSAVESIZE are free lists, entry 0 is the empty |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
35 tuple () of which at most one instance will be allocated. |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
36 */ |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
37 static tupleobject *free_tuples[MAXSAVESIZE]; |
|
1352
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
38 #endif |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
39 #ifdef COUNT_ALLOCS |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
40 int 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
|
41 int tuple_zero_allocs; |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
42 #endif |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
43 |
| 6 | 44 object * |
| 45 newtupleobject(size) | |
| 46 register int size; | |
| 47 { | |
| 48 register int i; | |
| 49 register tupleobject *op; | |
| 50 if (size < 0) { | |
| 27 | 51 err_badcall(); |
| 6 | 52 return NULL; |
| 53 } | |
|
1352
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
54 #if MAXSAVESIZE > 0 |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
55 if (size == 0 && free_tuples[0]) { |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
56 op = free_tuples[0]; |
|
1352
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
57 INCREF(op); |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
58 #ifdef COUNT_ALLOCS |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
59 tuple_zero_allocs++; |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
60 #endif |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
61 return (object *) op; |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
62 } |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
63 if (0 < size && size < MAXSAVESIZE && (op = free_tuples[size]) != NULL) { |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
64 free_tuples[size] = (tupleobject *) op->ob_item[0]; |
|
1352
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
65 #ifdef COUNT_ALLOCS |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
66 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
|
67 #endif |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
68 } else |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
69 #endif |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
70 { |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
71 op = (tupleobject *) |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
72 malloc(sizeof(tupleobject) + size * sizeof(object *)); |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
73 if (op == NULL) |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
74 return err_nomem(); |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
75 } |
| 6 | 76 op->ob_type = &Tupletype; |
| 77 op->ob_size = size; | |
| 78 for (i = 0; i < size; i++) | |
| 79 op->ob_item[i] = NULL; | |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1313
diff
changeset
|
80 NEWREF(op); |
|
1352
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
81 #if MAXSAVESIZE > 0 |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
82 if (size == 0) { |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
83 free_tuples[0] = op; |
|
1352
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
84 INCREF(op); /* extra INCREF so that this is never freed */ |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
85 } |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
86 #endif |
| 6 | 87 return (object *) op; |
| 88 } | |
| 89 | |
| 90 int | |
| 91 gettuplesize(op) | |
| 92 register object *op; | |
| 93 { | |
| 94 if (!is_tupleobject(op)) { | |
| 27 | 95 err_badcall(); |
| 6 | 96 return -1; |
| 97 } | |
| 98 else | |
| 99 return ((tupleobject *)op)->ob_size; | |
| 100 } | |
| 101 | |
| 102 object * | |
| 103 gettupleitem(op, i) | |
| 104 register object *op; | |
| 105 register int i; | |
| 106 { | |
| 107 if (!is_tupleobject(op)) { | |
| 27 | 108 err_badcall(); |
| 6 | 109 return NULL; |
| 110 } | |
| 111 if (i < 0 || i >= ((tupleobject *)op) -> ob_size) { | |
| 27 | 112 err_setstr(IndexError, "tuple index out of range"); |
| 6 | 113 return NULL; |
| 114 } | |
| 115 return ((tupleobject *)op) -> ob_item[i]; | |
| 116 } | |
| 117 | |
| 118 int | |
| 119 settupleitem(op, i, newitem) | |
| 120 register object *op; | |
| 121 register int i; | |
|
2504
425835b88099
a few peephole optimizations
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
122 object *newitem; |
| 6 | 123 { |
| 124 register object *olditem; | |
|
2504
425835b88099
a few peephole optimizations
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
125 register object **p; |
| 6 | 126 if (!is_tupleobject(op)) { |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
127 XDECREF(newitem); |
| 27 | 128 err_badcall(); |
| 129 return -1; | |
| 6 | 130 } |
| 131 if (i < 0 || i >= ((tupleobject *)op) -> ob_size) { | |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
132 XDECREF(newitem); |
| 27 | 133 err_setstr(IndexError, "tuple assignment index out of range"); |
| 134 return -1; | |
| 6 | 135 } |
|
2504
425835b88099
a few peephole optimizations
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
136 p = ((tupleobject *)op) -> ob_item + i; |
|
425835b88099
a few peephole optimizations
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
137 olditem = *p; |
|
425835b88099
a few peephole optimizations
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
138 *p = newitem; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
139 XDECREF(olditem); |
| 6 | 140 return 0; |
| 141 } | |
| 142 | |
| 143 /* Methods */ | |
| 144 | |
| 145 static void | |
| 146 tupledealloc(op) | |
| 147 register tupleobject *op; | |
| 148 { | |
| 149 register int i; | |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
150 for (i = 0; i < op->ob_size; i++) |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
151 XDECREF(op->ob_item[i]); |
|
1352
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
152 #if MAXSAVESIZE > 0 |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
153 if (0 < op->ob_size && op->ob_size < MAXSAVESIZE) { |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
154 op->ob_item[0] = (object *) free_tuples[op->ob_size]; |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
155 free_tuples[op->ob_size] = op; |
|
1352
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
156 } else |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
157 #endif |
|
4d1a15fc4748
intobject.c: Save references to small integers, so that they can be
Sjoerd Mullender <sjoerd@acm.org>
parents:
1347
diff
changeset
|
158 free((ANY *)op); |
| 6 | 159 } |
| 160 | |
|
288
9b43a983124c
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
258
diff
changeset
|
161 static int |
| 6 | 162 tupleprint(op, fp, flags) |
| 163 tupleobject *op; | |
| 164 FILE *fp; | |
| 165 int flags; | |
| 166 { | |
| 167 int i; | |
| 168 fprintf(fp, "("); | |
|
288
9b43a983124c
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
258
diff
changeset
|
169 for (i = 0; i < op->ob_size; i++) { |
|
9b43a983124c
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
258
diff
changeset
|
170 if (i > 0) |
| 6 | 171 fprintf(fp, ", "); |
|
1405
90c5e2bb4da5
* posixmodule.c: added set{uid,gid}.
Guido van Rossum <guido@python.org>
parents:
1380
diff
changeset
|
172 if (printobject(op->ob_item[i], fp, 0) != 0) |
|
288
9b43a983124c
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
258
diff
changeset
|
173 return -1; |
| 6 | 174 } |
| 175 if (op->ob_size == 1) | |
| 176 fprintf(fp, ","); | |
| 177 fprintf(fp, ")"); | |
|
288
9b43a983124c
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
258
diff
changeset
|
178 return 0; |
| 6 | 179 } |
| 180 | |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
181 static object * |
| 6 | 182 tuplerepr(v) |
| 183 tupleobject *v; | |
| 184 { | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
185 object *s, *comma; |
| 6 | 186 int i; |
| 187 s = newstringobject("("); | |
| 188 comma = newstringobject(", "); | |
| 189 for (i = 0; i < v->ob_size && s != NULL; i++) { | |
| 190 if (i > 0) | |
| 191 joinstring(&s, comma); | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
192 joinstring_decref(&s, reprobject(v->ob_item[i])); |
| 6 | 193 } |
| 194 DECREF(comma); | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
195 if (v->ob_size == 1) |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
196 joinstring_decref(&s, newstringobject(",")); |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
197 joinstring_decref(&s, newstringobject(")")); |
| 6 | 198 return s; |
| 199 } | |
| 200 | |
| 201 static int | |
| 202 tuplecompare(v, w) | |
| 203 register tupleobject *v, *w; | |
| 204 { | |
| 205 register int len = | |
| 206 (v->ob_size < w->ob_size) ? v->ob_size : w->ob_size; | |
| 207 register int i; | |
| 208 for (i = 0; i < len; i++) { | |
| 209 int cmp = cmpobject(v->ob_item[i], w->ob_item[i]); | |
| 210 if (cmp != 0) | |
| 211 return cmp; | |
| 212 } | |
| 213 return v->ob_size - w->ob_size; | |
| 214 } | |
| 215 | |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
216 static long |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
217 tuplehash(v) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
218 tupleobject *v; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
219 { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
220 register long x, y; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
221 register int len = v->ob_size; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
222 register object **p; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
223 x = 0x345678L; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
224 p = v->ob_item; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
225 while (--len >= 0) { |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
226 y = hashobject(*p++); |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
227 if (y == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
228 return -1; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
229 x = (x + x + x) ^ y; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
230 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
231 x ^= v->ob_size; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
232 if (x == -1) |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
233 x = -2; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
234 return x; |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
235 } |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
236 |
| 6 | 237 static int |
| 238 tuplelength(a) | |
| 239 tupleobject *a; | |
| 240 { | |
| 241 return a->ob_size; | |
| 242 } | |
| 243 | |
| 244 static object * | |
| 245 tupleitem(a, i) | |
| 246 register tupleobject *a; | |
| 247 register int i; | |
| 248 { | |
| 249 if (i < 0 || i >= a->ob_size) { | |
| 27 | 250 err_setstr(IndexError, "tuple index out of range"); |
| 6 | 251 return NULL; |
| 252 } | |
| 253 INCREF(a->ob_item[i]); | |
| 254 return a->ob_item[i]; | |
| 255 } | |
| 256 | |
| 257 static object * | |
| 258 tupleslice(a, ilow, ihigh) | |
| 259 register tupleobject *a; | |
| 260 register int ilow, ihigh; | |
| 261 { | |
| 262 register tupleobject *np; | |
| 263 register int i; | |
| 264 if (ilow < 0) | |
| 265 ilow = 0; | |
| 266 if (ihigh > a->ob_size) | |
| 267 ihigh = a->ob_size; | |
| 268 if (ihigh < ilow) | |
| 269 ihigh = ilow; | |
| 270 if (ilow == 0 && ihigh == a->ob_size) { | |
| 271 /* XXX can only do this if tuples are immutable! */ | |
| 272 INCREF(a); | |
| 273 return (object *)a; | |
| 274 } | |
| 275 np = (tupleobject *)newtupleobject(ihigh - ilow); | |
| 276 if (np == NULL) | |
| 277 return NULL; | |
| 278 for (i = ilow; i < ihigh; i++) { | |
| 279 object *v = a->ob_item[i]; | |
| 280 INCREF(v); | |
| 281 np->ob_item[i - ilow] = v; | |
| 282 } | |
| 283 return (object *)np; | |
| 284 } | |
| 285 | |
|
599
a347933a6d92
New function gettupleslice(v, i, j).
Guido van Rossum <guido@python.org>
parents:
288
diff
changeset
|
286 object * |
|
a347933a6d92
New function gettupleslice(v, i, j).
Guido van Rossum <guido@python.org>
parents:
288
diff
changeset
|
287 gettupleslice(op, i, j) |
|
a347933a6d92
New function gettupleslice(v, i, j).
Guido van Rossum <guido@python.org>
parents:
288
diff
changeset
|
288 object *op; |
|
a347933a6d92
New function gettupleslice(v, i, j).
Guido van Rossum <guido@python.org>
parents:
288
diff
changeset
|
289 int i, j; |
|
a347933a6d92
New function gettupleslice(v, i, j).
Guido van Rossum <guido@python.org>
parents:
288
diff
changeset
|
290 { |
|
a347933a6d92
New function gettupleslice(v, i, j).
Guido van Rossum <guido@python.org>
parents:
288
diff
changeset
|
291 if (op == NULL || !is_tupleobject(op)) { |
|
a347933a6d92
New function gettupleslice(v, i, j).
Guido van Rossum <guido@python.org>
parents:
288
diff
changeset
|
292 err_badcall(); |
|
a347933a6d92
New function gettupleslice(v, i, j).
Guido van Rossum <guido@python.org>
parents:
288
diff
changeset
|
293 return NULL; |
|
a347933a6d92
New function gettupleslice(v, i, j).
Guido van Rossum <guido@python.org>
parents:
288
diff
changeset
|
294 } |
|
a347933a6d92
New function gettupleslice(v, i, j).
Guido van Rossum <guido@python.org>
parents:
288
diff
changeset
|
295 return tupleslice((tupleobject *)op, i, j); |
|
a347933a6d92
New function gettupleslice(v, i, j).
Guido van Rossum <guido@python.org>
parents:
288
diff
changeset
|
296 } |
|
a347933a6d92
New function gettupleslice(v, i, j).
Guido van Rossum <guido@python.org>
parents:
288
diff
changeset
|
297 |
| 6 | 298 static object * |
| 299 tupleconcat(a, bb) | |
| 300 register tupleobject *a; | |
| 301 register object *bb; | |
| 302 { | |
| 303 register int size; | |
| 304 register int i; | |
| 305 tupleobject *np; | |
| 306 if (!is_tupleobject(bb)) { | |
| 27 | 307 err_badarg(); |
| 6 | 308 return NULL; |
| 309 } | |
| 310 #define b ((tupleobject *)bb) | |
| 311 size = a->ob_size + b->ob_size; | |
| 312 np = (tupleobject *) newtupleobject(size); | |
| 313 if (np == NULL) { | |
|
288
9b43a983124c
printobject now returns an error code
Guido van Rossum <guido@python.org>
parents:
258
diff
changeset
|
314 return NULL; |
| 6 | 315 } |
| 316 for (i = 0; i < a->ob_size; i++) { | |
| 317 object *v = a->ob_item[i]; | |
| 318 INCREF(v); | |
| 319 np->ob_item[i] = v; | |
| 320 } | |
| 321 for (i = 0; i < b->ob_size; i++) { | |
| 322 object *v = b->ob_item[i]; | |
| 323 INCREF(v); | |
| 324 np->ob_item[i + a->ob_size] = v; | |
| 325 } | |
| 326 return (object *)np; | |
| 327 #undef b | |
| 328 } | |
| 329 | |
|
258
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
330 static object * |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
331 tuplerepeat(a, n) |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
332 tupleobject *a; |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
333 int n; |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
334 { |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
335 int i, j; |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
336 int size; |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
337 tupleobject *np; |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
338 object **p; |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
339 if (n < 0) |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
340 n = 0; |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
341 if (a->ob_size*n == a->ob_size) { |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
342 /* Since tuples are immutable, we can return a shared |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
343 copy in this case */ |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
344 INCREF(a); |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
345 return (object *)a; |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
346 } |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
347 size = a->ob_size * n; |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
348 np = (tupleobject *) newtupleobject(size); |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
349 if (np == NULL) |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
350 return NULL; |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
351 p = np->ob_item; |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
352 for (i = 0; i < n; i++) { |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
353 for (j = 0; j < a->ob_size; j++) { |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
354 *p = a->ob_item[j]; |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
355 INCREF(*p); |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
356 p++; |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
357 } |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
358 } |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
359 return (object *) np; |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
360 } |
|
3b93bcea10f6
Finally implement tuple*number. From now on all sequence types
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
361 |
| 6 | 362 static sequence_methods tuple_as_sequence = { |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
363 (inquiry)tuplelength, /*sq_length*/ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
364 (binaryfunc)tupleconcat, /*sq_concat*/ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
365 (intargfunc)tuplerepeat, /*sq_repeat*/ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
366 (intargfunc)tupleitem, /*sq_item*/ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
367 (intintargfunc)tupleslice, /*sq_slice*/ |
| 6 | 368 0, /*sq_ass_item*/ |
| 369 0, /*sq_ass_slice*/ | |
| 370 }; | |
| 371 | |
| 372 typeobject Tupletype = { | |
| 373 OB_HEAD_INIT(&Typetype) | |
| 374 0, | |
| 375 "tuple", | |
| 376 sizeof(tupleobject) - sizeof(object *), | |
| 377 sizeof(object *), | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
378 (destructor)tupledealloc, /*tp_dealloc*/ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
379 (printfunc)tupleprint, /*tp_print*/ |
| 6 | 380 0, /*tp_getattr*/ |
| 381 0, /*tp_setattr*/ | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
382 (cmpfunc)tuplecompare, /*tp_compare*/ |
|
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
383 (reprfunc)tuplerepr, /*tp_repr*/ |
| 6 | 384 0, /*tp_as_number*/ |
| 385 &tuple_as_sequence, /*tp_as_sequence*/ | |
| 386 0, /*tp_as_mapping*/ | |
|
1848
b724599401ff
Merge back to main trunk
Guido van Rossum <guido@python.org>
parents:
1405
diff
changeset
|
387 (hashfunc)tuplehash, /*tp_hash*/ |
| 6 | 388 }; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
389 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
390 /* The following function breaks the notion that tuples are immutable: |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
391 it changes the size of a tuple. We get away with this only if there |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
392 is only one module referencing the object. You can also think of it |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
393 as creating a new tuple object and destroying the old one, only |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
394 more efficiently. In any case, don't use this if the tuple may |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
395 already be known to some other part of the code... |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
396 If last_is_sticky is set, the tuple will grow or shrink at the |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
397 front, otherwise it will grow or shrink at the end. */ |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
398 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
399 int |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
400 resizetuple(pv, newsize, last_is_sticky) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
401 object **pv; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
402 int newsize; |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
403 int last_is_sticky; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
404 { |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
405 register tupleobject *v; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
406 register tupleobject *sv; |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
407 int i; |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
408 int sizediff; |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
409 |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
410 v = (tupleobject *) *pv; |
|
2888
6abd14485884
better err checks in resizetuple
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
411 if (v == NULL || !is_tupleobject(v) || v->ob_refcnt != 1) { |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
412 *pv = 0; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
413 DECREF(v); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
414 err_badcall(); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
415 return -1; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
416 } |
|
2888
6abd14485884
better err checks in resizetuple
Guido van Rossum <guido@python.org>
parents:
2612
diff
changeset
|
417 sizediff = newsize - v->ob_size; |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
418 if (sizediff == 0) |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
419 return 0; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
420 /* XXX UNREF/NEWREF interface should be more symmetrical */ |
|
3586
36cc3ee54f28
new debugger symbol names
Guido van Rossum <guido@python.org>
parents:
2888
diff
changeset
|
421 #ifdef Py_REF_DEBUG |
|
2612
ca6b60d4ea90
fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents:
2504
diff
changeset
|
422 --_Py_RefTotal; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
423 #endif |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
424 UNREF(v); |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
425 if (last_is_sticky && sizediff < 0) { |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
426 /* shrinking: move entries to the front and zero moved entries */ |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
427 for (i = 0; i < newsize; i++) { |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
428 XDECREF(v->ob_item[i]); |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
429 v->ob_item[i] = v->ob_item[i - sizediff]; |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
430 v->ob_item[i - sizediff] = NULL; |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
431 } |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
432 } |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
433 for (i = newsize; i < v->ob_size; i++) { |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
434 XDECREF(v->ob_item[i]); |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
435 v->ob_item[i] = NULL; |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
436 } |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
437 sv = (tupleobject *) |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
438 realloc((char *)v, |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
439 sizeof(tupleobject) + newsize * sizeof(object *)); |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
440 *pv = (object *) sv; |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
441 if (sv == NULL) { |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
442 DEL(v); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
443 err_nomem(); |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
444 return -1; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
445 } |
|
1380
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
446 NEWREF(sv); |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
447 for (i = sv->ob_size; i < newsize; i++) |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
448 sv->ob_item[i] = NULL; |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
449 if (last_is_sticky && sizediff > 0) { |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
450 /* growing: move entries to the end and zero moved entries */ |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
451 for (i = newsize - 1; i >= sizediff; i--) { |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
452 sv->ob_item[i] = sv->ob_item[i - sizediff]; |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
453 sv->ob_item[i - sizediff] = NULL; |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
454 } |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
455 } |
|
a4aa83012af3
Fixed bugs in resizetuple and extended the interface.
Sjoerd Mullender <sjoerd@acm.org>
parents:
1369
diff
changeset
|
456 sv->ob_size = newsize; |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
457 return 0; |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1352
diff
changeset
|
458 } |
