Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 1 | /* List object interface */ |
| 2 | |
| 3 | /* |
| 4 | 123456789-123456789-123456789-123456789-123456789-123456789-123456789-12 |
| 5 | |
| 6 | Another generally useful object type is an list of object pointers. |
| 7 | This is a mutable type: the list items can be changed, and items can be |
| 8 | added or removed. Out-of-range indices or non-list objects are ignored. |
| 9 | |
| 10 | *** WARNING *** setlistitem does not increment the new item's reference |
| 11 | count, but does decrement the reference count of the item it replaces, |
| 12 | if not nil. It does *decrement* the reference count if it is *not* |
| 13 | inserted in the list. Similarly, getlistitem does not increment the |
| 14 | returned item's reference count. |
| 15 | */ |
| 16 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame^] | 17 | typedef struct { |
| 18 | OB_VARHEAD |
| 19 | object **ob_item; |
| 20 | } listobject; |
| 21 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 22 | extern typeobject Listtype; |
| 23 | |
| 24 | #define is_listobject(op) ((op)->ob_type == &Listtype) |
| 25 | |
| 26 | extern object *newlistobject PROTO((int size)); |
| 27 | extern int getlistsize PROTO((object *)); |
| 28 | extern object *getlistitem PROTO((object *, int)); |
| 29 | extern int setlistitem PROTO((object *, int, object *)); |
| 30 | extern int inslistitem PROTO((object *, int, object *)); |
| 31 | extern int addlistitem PROTO((object *, object *)); |
Guido van Rossum | 14da580 | 1990-10-30 13:32:39 +0000 | [diff] [blame] | 32 | extern int sortlist PROTO((object *)); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame^] | 33 | |
| 34 | /* Macro, trading safety for speed */ |
| 35 | #define GETLISTITEM(op, i) ((op)->ob_item[i]) |