blob: d403a5e329c8eb7c630b527bbc6ddbea7f56c83d [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001/***********************************************************
Guido van Rossumbab9d031992-04-05 14:26:55 +00002Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
Guido van Rossumf70e43a1991-02-19 12:39:46 +00003Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000025/* List object implementation */
26
Guido van Rossum3f5da241990-12-20 15:06:42 +000027#include "allobjects.h"
Guido van Rossumfa3da8a1992-01-27 16:53:23 +000028#include "modsupport.h"
Guido van Rossumff4949e1992-08-05 19:58:53 +000029#include "ceval.h"
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000030
31object *
32newlistobject(size)
33 int size;
34{
35 int i;
36 listobject *op;
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000037 MALLARG nbytes;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000038 if (size < 0) {
Guido van Rossum2a9096b1990-10-21 22:15:08 +000039 err_badcall();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000040 return NULL;
41 }
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000042 nbytes = size * sizeof(object *);
43 /* Check for overflow */
44 if (nbytes / sizeof(object *) != size) {
45 return err_nomem();
46 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000047 op = (listobject *) malloc(sizeof(listobject));
48 if (op == NULL) {
Guido van Rossum2a9096b1990-10-21 22:15:08 +000049 return err_nomem();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000050 }
51 if (size <= 0) {
52 op->ob_item = NULL;
53 }
54 else {
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000055 op->ob_item = (object **) malloc(nbytes);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000056 if (op->ob_item == NULL) {
57 free((ANY *)op);
Guido van Rossum2a9096b1990-10-21 22:15:08 +000058 return err_nomem();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000059 }
60 }
61 NEWREF(op);
62 op->ob_type = &Listtype;
63 op->ob_size = size;
64 for (i = 0; i < size; i++)
65 op->ob_item[i] = NULL;
66 return (object *) op;
67}
68
69int
70getlistsize(op)
71 object *op;
72{
73 if (!is_listobject(op)) {
Guido van Rossum2a9096b1990-10-21 22:15:08 +000074 err_badcall();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000075 return -1;
76 }
77 else
78 return ((listobject *)op) -> ob_size;
79}
80
81object *
82getlistitem(op, i)
83 object *op;
84 int i;
85{
86 if (!is_listobject(op)) {
Guido van Rossum2a9096b1990-10-21 22:15:08 +000087 err_badcall();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000088 return NULL;
89 }
90 if (i < 0 || i >= ((listobject *)op) -> ob_size) {
Guido van Rossum2a9096b1990-10-21 22:15:08 +000091 err_setstr(IndexError, "list index out of range");
Guido van Rossum85a5fbb1990-10-14 12:07:46 +000092 return NULL;
93 }
94 return ((listobject *)op) -> ob_item[i];
95}
96
97int
98setlistitem(op, i, newitem)
99 register object *op;
100 register int i;
101 register object *newitem;
102{
103 register object *olditem;
104 if (!is_listobject(op)) {
Guido van Rossume6f7d181991-10-20 20:20:40 +0000105 XDECREF(newitem);
Guido van Rossum2a9096b1990-10-21 22:15:08 +0000106 err_badcall();
107 return -1;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000108 }
109 if (i < 0 || i >= ((listobject *)op) -> ob_size) {
Guido van Rossume6f7d181991-10-20 20:20:40 +0000110 XDECREF(newitem);
Guido van Rossum2a9096b1990-10-21 22:15:08 +0000111 err_setstr(IndexError, "list assignment index out of range");
112 return -1;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000113 }
114 olditem = ((listobject *)op) -> ob_item[i];
115 ((listobject *)op) -> ob_item[i] = newitem;
Guido van Rossume6f7d181991-10-20 20:20:40 +0000116 XDECREF(olditem);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000117 return 0;
118}
119
120static int
121ins1(self, where, v)
122 listobject *self;
123 int where;
124 object *v;
125{
126 int i;
127 object **items;
Guido van Rossum2a9096b1990-10-21 22:15:08 +0000128 if (v == NULL) {
129 err_badcall();
130 return -1;
131 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000132 items = self->ob_item;
133 RESIZE(items, object *, self->ob_size+1);
Guido van Rossum2a9096b1990-10-21 22:15:08 +0000134 if (items == NULL) {
135 err_nomem();
136 return -1;
137 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000138 if (where < 0)
139 where = 0;
140 if (where > self->ob_size)
141 where = self->ob_size;
142 for (i = self->ob_size; --i >= where; )
143 items[i+1] = items[i];
144 INCREF(v);
145 items[where] = v;
146 self->ob_item = items;
147 self->ob_size++;
148 return 0;
149}
150
151int
152inslistitem(op, where, newitem)
153 object *op;
154 int where;
155 object *newitem;
156{
Guido van Rossum2a9096b1990-10-21 22:15:08 +0000157 if (!is_listobject(op)) {
158 err_badcall();
159 return -1;
160 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000161 return ins1((listobject *)op, where, newitem);
162}
163
164int
165addlistitem(op, newitem)
166 object *op;
167 object *newitem;
168{
Guido van Rossum2a9096b1990-10-21 22:15:08 +0000169 if (!is_listobject(op)) {
170 err_badcall();
171 return -1;
172 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000173 return ins1((listobject *)op,
174 (int) ((listobject *)op)->ob_size, newitem);
175}
176
177/* Methods */
178
179static void
180list_dealloc(op)
181 listobject *op;
182{
183 int i;
184 for (i = 0; i < op->ob_size; i++) {
Guido van Rossume6f7d181991-10-20 20:20:40 +0000185 XDECREF(op->ob_item[i]);
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000186 }
187 if (op->ob_item != NULL)
188 free((ANY *)op->ob_item);
189 free((ANY *)op);
190}
191
Guido van Rossum90933611991-06-07 16:10:43 +0000192static int
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000193list_print(op, fp, flags)
194 listobject *op;
195 FILE *fp;
196 int flags;
197{
198 int i;
199 fprintf(fp, "[");
Guido van Rossum90933611991-06-07 16:10:43 +0000200 for (i = 0; i < op->ob_size; i++) {
201 if (i > 0)
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000202 fprintf(fp, ", ");
Guido van Rossum90933611991-06-07 16:10:43 +0000203 if (printobject(op->ob_item[i], fp, flags) != 0)
204 return -1;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000205 }
206 fprintf(fp, "]");
Guido van Rossum90933611991-06-07 16:10:43 +0000207 return 0;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000208}
209
210object *
211list_repr(v)
212 listobject *v;
213{
214 object *s, *t, *comma;
215 int i;
216 s = newstringobject("[");
217 comma = newstringobject(", ");
218 for (i = 0; i < v->ob_size && s != NULL; i++) {
219 if (i > 0)
220 joinstring(&s, comma);
221 t = reprobject(v->ob_item[i]);
222 joinstring(&s, t);
223 DECREF(t);
224 }
225 DECREF(comma);
226 t = newstringobject("]");
227 joinstring(&s, t);
228 DECREF(t);
229 return s;
230}
231
232static int
233list_compare(v, w)
234 listobject *v, *w;
235{
236 int len = (v->ob_size < w->ob_size) ? v->ob_size : w->ob_size;
237 int i;
238 for (i = 0; i < len; i++) {
239 int cmp = cmpobject(v->ob_item[i], w->ob_item[i]);
240 if (cmp != 0)
241 return cmp;
242 }
243 return v->ob_size - w->ob_size;
244}
245
246static int
247list_length(a)
248 listobject *a;
249{
250 return a->ob_size;
251}
252
253static object *
254list_item(a, i)
255 listobject *a;
256 int i;
257{
258 if (i < 0 || i >= a->ob_size) {
Guido van Rossum2a9096b1990-10-21 22:15:08 +0000259 err_setstr(IndexError, "list index out of range");
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000260 return NULL;
261 }
262 INCREF(a->ob_item[i]);
263 return a->ob_item[i];
264}
265
266static object *
267list_slice(a, ilow, ihigh)
268 listobject *a;
269 int ilow, ihigh;
270{
271 listobject *np;
272 int i;
273 if (ilow < 0)
274 ilow = 0;
275 else if (ilow > a->ob_size)
276 ilow = a->ob_size;
277 if (ihigh < 0)
278 ihigh = 0;
279 if (ihigh < ilow)
280 ihigh = ilow;
281 else if (ihigh > a->ob_size)
282 ihigh = a->ob_size;
283 np = (listobject *) newlistobject(ihigh - ilow);
284 if (np == NULL)
285 return NULL;
286 for (i = ilow; i < ihigh; i++) {
287 object *v = a->ob_item[i];
288 INCREF(v);
289 np->ob_item[i - ilow] = v;
290 }
291 return (object *)np;
292}
293
294static object *
295list_concat(a, bb)
296 listobject *a;
297 object *bb;
298{
299 int size;
300 int i;
301 listobject *np;
302 if (!is_listobject(bb)) {
Guido van Rossum2a9096b1990-10-21 22:15:08 +0000303 err_badarg();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000304 return NULL;
305 }
306#define b ((listobject *)bb)
307 size = a->ob_size + b->ob_size;
308 np = (listobject *) newlistobject(size);
309 if (np == NULL) {
Guido van Rossum90933611991-06-07 16:10:43 +0000310 return NULL;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000311 }
312 for (i = 0; i < a->ob_size; i++) {
313 object *v = a->ob_item[i];
314 INCREF(v);
315 np->ob_item[i] = v;
316 }
317 for (i = 0; i < b->ob_size; i++) {
318 object *v = b->ob_item[i];
319 INCREF(v);
320 np->ob_item[i + a->ob_size] = v;
321 }
322 return (object *)np;
323#undef b
324}
325
Guido van Rossumed98d481991-03-06 13:07:53 +0000326static object *
327list_repeat(a, n)
328 listobject *a;
329 int n;
330{
331 int i, j;
332 int size;
333 listobject *np;
334 object **p;
335 if (n < 0)
336 n = 0;
337 size = a->ob_size * n;
338 np = (listobject *) newlistobject(size);
339 if (np == NULL)
340 return NULL;
341 p = np->ob_item;
342 for (i = 0; i < n; i++) {
343 for (j = 0; j < a->ob_size; j++) {
344 *p = a->ob_item[j];
345 INCREF(*p);
346 p++;
347 }
348 }
349 return (object *) np;
350}
351
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000352static int
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000353list_ass_slice(a, ilow, ihigh, v)
354 listobject *a;
355 int ilow, ihigh;
356 object *v;
357{
358 object **item;
359 int n; /* Size of replacement list */
360 int d; /* Change in size */
361 int k; /* Loop index */
362#define b ((listobject *)v)
363 if (v == NULL)
364 n = 0;
Guido van Rossum32dffaa1991-12-24 13:27:34 +0000365 else if (is_listobject(v)) {
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000366 n = b->ob_size;
Guido van Rossum32dffaa1991-12-24 13:27:34 +0000367 if (a == b) {
368 /* Special case "a[i:j] = a" -- copy b first */
369 int ret;
370 v = list_slice(b, 0, n);
371 ret = list_ass_slice(a, ilow, ihigh, v);
372 DECREF(v);
373 return ret;
374 }
375 }
Guido van Rossum2a9096b1990-10-21 22:15:08 +0000376 else {
377 err_badarg();
378 return -1;
379 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000380 if (ilow < 0)
381 ilow = 0;
382 else if (ilow > a->ob_size)
383 ilow = a->ob_size;
384 if (ihigh < 0)
385 ihigh = 0;
386 if (ihigh < ilow)
387 ihigh = ilow;
388 else if (ihigh > a->ob_size)
389 ihigh = a->ob_size;
390 item = a->ob_item;
391 d = n - (ihigh-ilow);
392 if (d <= 0) { /* Delete -d items; DECREF ihigh-ilow items */
393 for (k = ilow; k < ihigh; k++)
394 DECREF(item[k]);
395 if (d < 0) {
396 for (/*k = ihigh*/; k < a->ob_size; k++)
397 item[k+d] = item[k];
398 a->ob_size += d;
399 RESIZE(item, object *, a->ob_size); /* Can't fail */
400 a->ob_item = item;
401 }
402 }
403 else { /* Insert d items; DECREF ihigh-ilow items */
404 RESIZE(item, object *, a->ob_size + d);
Guido van Rossum2a9096b1990-10-21 22:15:08 +0000405 if (item == NULL) {
406 err_nomem();
407 return -1;
408 }
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000409 for (k = a->ob_size; --k >= ihigh; )
410 item[k+d] = item[k];
411 for (/*k = ihigh-1*/; k >= ilow; --k)
412 DECREF(item[k]);
413 a->ob_item = item;
414 a->ob_size += d;
415 }
416 for (k = 0; k < n; k++, ilow++) {
417 object *w = b->ob_item[k];
418 INCREF(w);
419 item[ilow] = w;
420 }
421 return 0;
422#undef b
423}
424
Guido van Rossum4a450d01991-04-03 19:05:18 +0000425static int
426list_ass_item(a, i, v)
427 listobject *a;
428 int i;
429 object *v;
430{
431 if (i < 0 || i >= a->ob_size) {
432 err_setstr(IndexError, "list assignment index out of range");
433 return -1;
434 }
435 if (v == NULL)
436 return list_ass_slice(a, i, i+1, v);
437 INCREF(v);
438 DECREF(a->ob_item[i]);
439 a->ob_item[i] = v;
440 return 0;
441}
442
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000443static object *
444ins(self, where, v)
445 listobject *self;
446 int where;
447 object *v;
448{
449 if (ins1(self, where, v) != 0)
450 return NULL;
451 INCREF(None);
452 return None;
453}
454
455static object *
456listinsert(self, args)
457 listobject *self;
458 object *args;
459{
460 int i;
461 if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 2) {
Guido van Rossum2a9096b1990-10-21 22:15:08 +0000462 err_badarg();
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000463 return NULL;
464 }
465 if (!getintarg(gettupleitem(args, 0), &i))
466 return NULL;
467 return ins(self, i, gettupleitem(args, 1));
468}
469
470static object *
471listappend(self, args)
472 listobject *self;
473 object *args;
474{
475 return ins(self, (int) self->ob_size, args);
476}
477
Guido van Rossume10a19e1992-08-03 19:05:37 +0000478static object *cmpfunc;
479
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000480static int
481cmp(v, w)
482 char *v, *w;
483{
Guido van Rossume10a19e1992-08-03 19:05:37 +0000484 object *t, *res;
485 long i;
486
487 if (err_occurred())
488 return 0;
489
490 if (cmpfunc == NULL)
491 return cmpobject(* (object **) v, * (object **) w);
492
493 /* Call the user-supplied comparison function */
494 t = newtupleobject(2);
495 if (t == NULL)
496 return 0;
497 INCREF(* (object **) v);
498 settupleitem(t, 0, * (object **) v);
499 INCREF(* (object **) w);
500 settupleitem(t, 1, * (object **) w);
501 res = call_object(cmpfunc, t);
502 DECREF(t);
503 if (res == NULL)
504 return 0;
505 if (!is_intobject(res)) {
506 err_setstr(TypeError, "comparison function should return int");
507 i = 0;
508 }
509 else {
510 i = getintvalue(res);
511 if (i < 0)
512 i = -1;
513 else if (i > 0)
514 i = 1;
515 }
516 DECREF(res);
517 return (int) i;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000518}
519
520static object *
521listsort(self, args)
522 listobject *self;
523 object *args;
524{
Guido van Rossume10a19e1992-08-03 19:05:37 +0000525 object *save_cmpfunc;
526 if (self->ob_size <= 1) {
527 INCREF(None);
528 return None;
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000529 }
Guido van Rossume10a19e1992-08-03 19:05:37 +0000530 save_cmpfunc = cmpfunc;
531 cmpfunc = args;
532 if (cmpfunc != NULL) {
533 /* Test the comparison function for obvious errors */
534 (void) cmp(&self->ob_item[0], &self->ob_item[1]);
535 if (err_occurred()) {
536 cmpfunc = save_cmpfunc;
537 return NULL;
538 }
539 }
540 qsort((char *)self->ob_item,
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000541 (int) self->ob_size, sizeof(object *), cmp);
Guido van Rossume10a19e1992-08-03 19:05:37 +0000542 cmpfunc = save_cmpfunc;
Guido van Rossum2a9096b1990-10-21 22:15:08 +0000543 if (err_occurred())
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000544 return NULL;
545 INCREF(None);
546 return None;
547}
548
Guido van Rossumed98d481991-03-06 13:07:53 +0000549static object *
550listreverse(self, args)
551 listobject *self;
552 object *args;
553{
554 register object **p, **q;
555 register object *tmp;
556
557 if (args != NULL) {
558 err_badarg();
559 return NULL;
560 }
561
562 if (self->ob_size > 1) {
563 for (p = self->ob_item, q = self->ob_item + self->ob_size - 1;
564 p < q; p++, q--) {
565 tmp = *p;
566 *p = *q;
567 *q = tmp;
568 }
569 }
570
571 INCREF(None);
572 return None;
573}
574
Guido van Rossum84c76f51990-10-30 13:32:20 +0000575int
576sortlist(v)
577 object *v;
578{
579 if (v == NULL || !is_listobject(v)) {
580 err_badcall();
581 return -1;
582 }
583 v = listsort((listobject *)v, (object *)NULL);
584 if (v == NULL)
585 return -1;
586 DECREF(v);
587 return 0;
588}
589
Guido van Rossumed98d481991-03-06 13:07:53 +0000590static object *
591listindex(self, args)
592 listobject *self;
593 object *args;
594{
595 int i;
596
597 if (args == NULL) {
598 err_badarg();
599 return NULL;
600 }
601 for (i = 0; i < self->ob_size; i++) {
602 if (cmpobject(self->ob_item[i], args) == 0)
Guido van Rossum7066dd71992-09-17 17:54:56 +0000603 return newintobject((long)i);
Guido van Rossumed98d481991-03-06 13:07:53 +0000604 }
Guido van Rossum87e7ea71991-12-10 14:00:03 +0000605 err_setstr(ValueError, "list.index(x): x not in list");
Guido van Rossumed98d481991-03-06 13:07:53 +0000606 return NULL;
607}
608
609static object *
Guido van Rossume6f7d181991-10-20 20:20:40 +0000610listcount(self, args)
611 listobject *self;
612 object *args;
613{
614 int count = 0;
615 int i;
616
617 if (args == NULL) {
618 err_badarg();
619 return NULL;
620 }
621 for (i = 0; i < self->ob_size; i++) {
622 if (cmpobject(self->ob_item[i], args) == 0)
623 count++;
624 }
625 return newintobject((long)count);
626}
627
628static object *
Guido van Rossumed98d481991-03-06 13:07:53 +0000629listremove(self, args)
630 listobject *self;
631 object *args;
632{
633 int i;
634
635 if (args == NULL) {
636 err_badarg();
637 return NULL;
638 }
639 for (i = 0; i < self->ob_size; i++) {
640 if (cmpobject(self->ob_item[i], args) == 0) {
641 if (list_ass_slice(self, i, i+1, (object *)NULL) != 0)
642 return NULL;
643 INCREF(None);
644 return None;
645 }
646
647 }
Guido van Rossum87e7ea71991-12-10 14:00:03 +0000648 err_setstr(ValueError, "list.remove(x): x not in list");
Guido van Rossumed98d481991-03-06 13:07:53 +0000649 return NULL;
650}
651
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000652static struct methodlist list_methods[] = {
653 {"append", listappend},
Guido van Rossume6f7d181991-10-20 20:20:40 +0000654 {"count", listcount},
Guido van Rossumed98d481991-03-06 13:07:53 +0000655 {"index", listindex},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000656 {"insert", listinsert},
657 {"sort", listsort},
Guido van Rossumed98d481991-03-06 13:07:53 +0000658 {"remove", listremove},
659 {"reverse", listreverse},
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000660 {NULL, NULL} /* sentinel */
661};
662
663static object *
664list_getattr(f, name)
665 listobject *f;
666 char *name;
667{
668 return findmethod(list_methods, (object *)f, name);
669}
670
671static sequence_methods list_as_sequence = {
672 list_length, /*sq_length*/
673 list_concat, /*sq_concat*/
Guido van Rossumed98d481991-03-06 13:07:53 +0000674 list_repeat, /*sq_repeat*/
Guido van Rossum85a5fbb1990-10-14 12:07:46 +0000675 list_item, /*sq_item*/
676 list_slice, /*sq_slice*/
677 list_ass_item, /*sq_ass_item*/
678 list_ass_slice, /*sq_ass_slice*/
679};
680
681typeobject Listtype = {
682 OB_HEAD_INIT(&Typetype)
683 0,
684 "list",
685 sizeof(listobject),
686 0,
687 list_dealloc, /*tp_dealloc*/
688 list_print, /*tp_print*/
689 list_getattr, /*tp_getattr*/
690 0, /*tp_setattr*/
691 list_compare, /*tp_compare*/
692 list_repr, /*tp_repr*/
693 0, /*tp_as_number*/
694 &list_as_sequence, /*tp_as_sequence*/
695 0, /*tp_as_mapping*/
696};