Make the ptrlist using the sparse allocator.
Christopher Li
maintainerPATCH 1/1 Make the ptrlist using the sparse allocator.
We can drop the whole allocator without freeing the ptrlist one by one.
Signed-off-by Christopher Li <[email protected]>
Index: sparse/ptrlist.h
===================================================================
allocate.c +1 -1
@@ -119,7 +119,7 @@ ALLOCATOR(expression, "expressions");ALLOCATOR (statement,"statements" );ALLOCATOR (string,"strings" );ALLOCATOR (scope,"scopes" ); -__ALLOCATOR (void,0 ,1 ,"bytes" , bytes); +__DO_ALLOCATOR (void,0 ,1 ,"bytes" , bytes);ALLOCATOR (basic_block,"basic_block" );ALLOCATOR (entrypoint,"entrypoint" );ALLOCATOR (instruction,"instruction" );
allocate.h +5 -2
@@ -31,7 +31,7 @@ extern void show_allocations(struct allo extern void protect_##x##_alloc(void);#define DECLARE_ALLOCATOR (x) __DECLARE_ALLOCATOR(struct x, x) -#define __ALLOCATOR (type, objsize, objalign, objname, x) \ +#define __DO_ALLOCATOR (type, objsize, objalign, objname, x) \ static struct allocator_struct x##_allocator = { \ .name = objname, \ .alignment = objalign, \
@@ -57,7 +57,10 @@ extern void show_allocations(struct allo protect_allocations(&x##_allocator); \ } -#define ALLOCATOR (x, n) __ALLOCATOR(struct x, sizeof(struct x), __alignof__(struct x), n, x) +#define __ALLOCATOR (t, n, x) \ + __DO_ALLOCATOR(t, sizeof(t), __alignof__(t), n, x) + +#define ALLOCATOR (x, n) __ALLOCATOR(struct x, n, x)DECLARE_ALLOCATOR (ident);DECLARE_ALLOCATOR (token);
ptrlist.c +11 -8
@@ -10,6 +10,11 @@#include <assert.h> #include "ptrlist.h" +#include "allocate.h" +#include "compat.h" + +__DECLARE_ALLOCATOR(struct ptr_list, ptrlist); +__ALLOCATOR(struct ptr_list, "ptr list", ptrlist);int ptr_list_size (struct ptr_list *head) {
@@ -72,14 +77,14 @@ restart:if (!entry->nr) {struct ptr_list *prev;if (next == entry) { -free (entry); +__free_ptrlist (entry); *listp =NULL ;return ; } prev = entry->prev; prev->next = next; next->prev = prev; -free (entry); +__free_ptrlist (entry);if (entry == head) { *listp = next; head = next;
@@ -95,7 +100,7 @@ restart:void split_ptr_list_head (struct ptr_list *head) {int old = head->nr, nr = old /2 ; -struct ptr_list *newlist =malloc (sizeof (*newlist)); +struct ptr_list *newlist =__alloc_ptrlist (0 );struct ptr_list *next = head->next; old -= nr;
@@ -122,9 +127,7 @@ void **__add_ptr_list(struct ptr_list ** ptr = (void *)(tag | (unsigned long )ptr);if (!list || (nr = (last = list->prev)->nr) >=LIST_NODE_NR ) { -struct ptr_list *newlist =malloc (sizeof (*newlist)); -assert (newlist); -memset (newlist,0 ,sizeof (*newlist)); +struct ptr_list *newlist =__alloc_ptrlist (0 );if (!list) { newlist->next = newlist; newlist->prev = newlist;
@@ -214,7 +217,7 @@ void * delete_ptr_list_last(struct ptr_l last->prev->next = first;if (last == first) *head =NULL ; -free (last); +__free_ptrlist (last); }return ptr; }
@@ -238,7 +241,7 @@ void __free_ptr_list(struct ptr_list **lwhile (list) { tmp = list; list = list->next; -free (tmp); +__free_ptrlist (tmp); } *listp =NULL ;
Josh Triplett
AppliedQuoted 4 lines · Christopher Li
We can drop the whole allocator without freeing the ptrlist one by one.
Signed-off-by Christopher Li <[email protected]>
Applied, though I'd love to see more descriptive names for __DO_ALLOCATOR and __ALLOCATOR.
- Josh Triplett