Author: chromatic Date: Sat Jan 24 14:38:29 2009 New Revision: 35972 Modified: trunk/include/parrot/list.h trunk/src/list.c
Log: [src] Removed one use of deprecated SArray PMC. All tests pass. Modified: trunk/include/parrot/list.h ============================================================================== --- trunk/include/parrot/list.h (original) +++ trunk/include/parrot/list.h Sat Jan 24 14:38:29 2009 @@ -15,35 +15,34 @@ #define PARROT_LIST_H_GUARD typedef struct List_chunk { - Buffer data; /* item store */ - UINTVAL flags; /* chunk flags */ - UINTVAL items; /* items in this chunk */ - UINTVAL n_chunks; /* # of chunks with grow policy in flags */ - UINTVAL n_items; /* # of items with grow policy in flags */ + Buffer data; /* item store */ struct List_chunk *next; struct List_chunk *prev; + UINTVAL flags; /* chunk flags */ + UINTVAL items; /* items in this chunk */ + UINTVAL n_chunks; /* # of chunks with grow policy in flags */ + UINTVAL n_items; /* # of items with grow policy in flags */ } List_chunk; -#define sparse PObj_private0_FLAG +#define sparse PObj_private0_FLAG #define no_power_2 PObj_private1_FLAG #define fixed_items PObj_private2_FLAG -#define grow_items PObj_private3_FLAG +#define grow_items PObj_private3_FLAG typedef struct List { - Buffer chunk_list; /* pointers to chunks */ - UINTVAL length; /* number of items in list */ - UINTVAL start; /* offset, where array[0] is */ - PMC * container; /* the Array PMC */ - PARROT_DATA_TYPE item_type; /* item type */ - int item_size; /* item size */ - int items_per_chunk; /* override defaults */ - UINTVAL cap; /* list capacity in items */ - int grow_policy; /* fixed / variable len */ - UINTVAL collect_runs; /* counter, when chunklist was built */ - UINTVAL n_chunks; /* number of chunks */ - PMC * user_data; /* e.g. multiarray dimensions */ - List_chunk *first; /* first chunk holding data */ - List_chunk *last; /* last chunk */ + Buffer chunk_list; /* pointers to chunks */ + PMC *container; /* the Array PMC */ + List_chunk *first; /* first chunk holding data */ + List_chunk *last; /* last chunk */ + UINTVAL length; /* number of items in list */ + UINTVAL start; /* offset, where array[0] is */ + PARROT_DATA_TYPE item_type; /* item type */ + UINTVAL cap; /* list capacity in items */ + UINTVAL collect_runs; /* counter, when chunklist was built */ + UINTVAL n_chunks; /* number of chunks */ + int grow_policy; /* fixed / variable len */ + int items_per_chunk; /* override defaults */ + int item_size; /* item size */ } List; typedef enum { Modified: trunk/src/list.c ============================================================================== --- trunk/src/list.c (original) +++ trunk/src/list.c Sat Jan 24 14:38:29 2009 @@ -368,12 +368,14 @@ chunk->prev = NULL; Parrot_allocate_aligned(interp, (Buffer *)chunk, size); memset(PObj_bufstart((Buffer*)chunk), 0, size); + /* see also src/hash.c */ - if (list->container) { + if (list->container) GC_WRITE_BARRIER(interp, list->container, 0, chunk); - } + Parrot_unblock_GC_mark(interp); - /*Parrot_unblock_GC_sweep(interp); */ + + /* Parrot_unblock_GC_sweep(interp); */ return chunk; } @@ -524,6 +526,7 @@ } prev = chunk; } + if (changes) rebuild_chunk_ptrs(list, 0); } @@ -1268,32 +1271,33 @@ list->item_type = type; switch (type) { - case enum_type_sized: /* gets overridden below */ - case enum_type_char: - list->item_size = sizeof (char); - break; - case enum_type_short: - list->item_size = sizeof (short); - break; - case enum_type_int: - list->item_size = sizeof (int); - break; - case enum_type_INTVAL: - list->item_size = sizeof (INTVAL); - break; - case enum_type_FLOATVAL: - list->item_size = sizeof (FLOATVAL); - break; - case enum_type_PMC: - list->item_size = sizeof (PMC *); - break; - case enum_type_STRING: - list->item_size = sizeof (STRING *); - break; - default: - Parrot_ex_throw_from_c_args(interp, NULL, 1, "Unknown list type\n"); - break; + case enum_type_sized: /* gets overridden below */ + case enum_type_char: + list->item_size = sizeof (char); + break; + case enum_type_short: + list->item_size = sizeof (short); + break; + case enum_type_int: + list->item_size = sizeof (int); + break; + case enum_type_INTVAL: + list->item_size = sizeof (INTVAL); + break; + case enum_type_FLOATVAL: + list->item_size = sizeof (FLOATVAL); + break; + case enum_type_PMC: + list->item_size = sizeof (PMC *); + break; + case enum_type_STRING: + list->item_size = sizeof (STRING *); + break; + default: + Parrot_ex_throw_from_c_args(interp, NULL, 1, "Unknown list type\n"); + break; } + return list; } @@ -1312,11 +1316,13 @@ list_pmc_new(PARROT_INTERP, ARGMOD(PMC *container)) { ASSERT_ARGS(list_pmc_new) - List * const l = list_new(interp, enum_type_PMC); - l->container = container; + + List * const l = list_new(interp, enum_type_PMC); + l->container = container; PMC_data(container) = l; } + /* =item C<List * list_new_init> @@ -1329,9 +1335,6 @@ 3 ... item_size for enum_type_sized 4 ... items_per_chunk -After getting these values out of the key/value pairs, a new array with -these values is stored in user_data, where the keys are explicit. - =cut */ @@ -1391,7 +1394,9 @@ "Invalid initializer for list\n"); } } + list = list_new(interp, type); + if (list->item_type == enum_type_sized) { /* override item_size */ if (!item_size) @@ -1404,12 +1409,13 @@ ? (1 << (ld(items_per_chunk) + 1)) /* make power of 2 */ : MAX_ITEMS; } + if (size) list_set_length(interp, list, size); - /* make a private copy of init data */ - list->user_data = user_array = pmc_new(interp, enum_class_SArray); + /* set length */ VTABLE_set_integer_native(interp, user_array, 2); + /* store values */ VTABLE_set_integer_keyed_int(interp, user_array, 0, size); VTABLE_set_pmc_keyed_int(interp, user_array, 1, multi_key); @@ -1431,15 +1437,13 @@ list_pmc_new_init(PARROT_INTERP, ARGMOD(PMC *container), ARGIN(PMC *init)) { ASSERT_ARGS(list_pmc_new_init) - List * const l = list_new_init(interp, enum_type_PMC, init); - l->container = container; + + List * const l = list_new_init(interp, enum_type_PMC, init); + l->container = container; PMC_data(container) = l; - /* - * this is a new PMC, so no old value - */ - GC_WRITE_BARRIER(interp, container, NULL, l->user_data); } + /* =item C<List * list_clone> @@ -1510,9 +1514,7 @@ } } } - if (other->user_data) { - l->user_data = VTABLE_clone(interp, other->user_data); - } + rebuild_chunk_list(interp, l); Parrot_unblock_GC_mark(interp); Parrot_unblock_GC_sweep(interp); @@ -1552,9 +1554,8 @@ } } + pobject_lives(interp, (PObj *)list); - if (list->user_data) - pobject_lives(interp, (PObj *) list->user_data); } /*