| 29 #include <assert.h> |
29 #include <assert.h> |
| 30 |
30 |
| 31 static void do_not_free(void* item) { |
31 static void do_not_free(void* item) { |
| 32 } |
32 } |
| 33 |
33 |
| 34 string_list_t* new_string_list_t() { |
34 string_list* new_string_list() { |
| 35 string_list_t* stringList = malloc(sizeof(string_list_t)); |
35 string_list* stringList = malloc(sizeof(string_list)); |
| 36 stringList->count = 0; |
36 stringList->count = 0; |
| 37 stringList->capacity = 32; |
37 stringList->capacity = 32; |
| 38 stringList->items = calloc(sizeof(char*), stringList->capacity); |
38 stringList->items = calloc(sizeof(char*), stringList->capacity); |
| 39 stringList->free_item = do_not_free; |
39 stringList->free_item = do_not_free; |
| 40 |
40 |
| 41 return stringList; |
41 return stringList; |
| 42 } |
42 } |
| 43 |
43 |
| 44 void destroy_string_list_t(string_list_t* list) { |
44 void destroy_string_list(string_list* list) { |
| 45 if (list) { |
45 if (list) { |
| 46 if (list->items) { |
46 if (list->items) { |
| 47 for (size_t i = 0 ; i < list->count ; i++) { |
47 for (size_t i = 0 ; i < list->count ; i++) { |
| 48 list->free_item(list->items[i]); |
48 list->free_item(list->items[i]); |
| 49 } |
49 } |