Compare commits
2 Commits
465f879437
...
7345815424
Author | SHA1 | Date |
---|---|---|
Juhani Krekelä | 7345815424 | |
Juhani Krekelä | 1ff08c0189 |
6
cmaybe.h
6
cmaybe.h
|
@ -56,11 +56,13 @@ struct __free_list {
|
||||||
)
|
)
|
||||||
#define TRY_MALLOC(size) TRY_MEMALLOC(malloc, size)
|
#define TRY_MALLOC(size) TRY_MEMALLOC(malloc, size)
|
||||||
|
|
||||||
static void __remove_free_list(struct __free_list **head, void *ptr) {
|
static void __remove_free_list(struct __free_list **head, void *ptr, void(*free)(void*)) {
|
||||||
struct __free_list **current = head;
|
struct __free_list **current = head;
|
||||||
while (*current != NULL) {
|
while (*current != NULL) {
|
||||||
if (current[0]->ptr == ptr) {
|
if (current[0]->ptr == ptr) {
|
||||||
|
struct __free_list *deleted = *current;
|
||||||
*current = current[0]->next;
|
*current = current[0]->next;
|
||||||
|
free(deleted);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
current = ¤t[0]->next;
|
current = ¤t[0]->next;
|
||||||
|
@ -68,7 +70,7 @@ static void __remove_free_list(struct __free_list **head, void *ptr) {
|
||||||
}
|
}
|
||||||
#define TRY_FREE(allocation) (\
|
#define TRY_FREE(allocation) (\
|
||||||
free(allocation),\
|
free(allocation),\
|
||||||
__remove_free_list(&__allocations, allocation)\
|
__remove_free_list(&__allocations, allocation, free)\
|
||||||
)
|
)
|
||||||
#define TRY_FREE_ALL() \
|
#define TRY_FREE_ALL() \
|
||||||
while (__allocations != NULL) {\
|
while (__allocations != NULL) {\
|
||||||
|
|
|
@ -50,7 +50,7 @@ MAYBE(intmax_t_array) convert_to_numbers(char *line) {
|
||||||
|
|
||||||
struct intmax_t_array numbers;
|
struct intmax_t_array numbers;
|
||||||
numbers.length = 0;
|
numbers.length = 0;
|
||||||
numbers.alloc_size = 64 * sizeof(intmax_t);
|
numbers.alloc_size = 8 * sizeof(intmax_t);
|
||||||
numbers.data = TRY_MALLOC(numbers.alloc_size * sizeof(intmax_t));
|
numbers.data = TRY_MALLOC(numbers.alloc_size * sizeof(intmax_t));
|
||||||
|
|
||||||
char *strtok_saveptr = NULL;
|
char *strtok_saveptr = NULL;
|
||||||
|
|
Loading…
Reference in New Issue