diff options
Diffstat (limited to 'prism/util')
-rw-r--r-- | prism/util/pm_buffer.c | 6 | ||||
-rw-r--r-- | prism/util/pm_constant_pool.c | 16 | ||||
-rw-r--r-- | prism/util/pm_integer.c | 10 | ||||
-rw-r--r-- | prism/util/pm_list.c | 2 | ||||
-rw-r--r-- | prism/util/pm_list.h | 2 | ||||
-rw-r--r-- | prism/util/pm_newline_list.c | 8 | ||||
-rw-r--r-- | prism/util/pm_string.c | 4 | ||||
-rw-r--r-- | prism/util/pm_string_list.c | 4 |
8 files changed, 26 insertions, 26 deletions
diff --git a/prism/util/pm_buffer.c b/prism/util/pm_buffer.c index 048bc97363..87f79ddd2c 100644 --- a/prism/util/pm_buffer.c +++ b/prism/util/pm_buffer.c @@ -16,7 +16,7 @@ pm_buffer_init_capacity(pm_buffer_t *buffer, size_t capacity) { buffer->length = 0; buffer->capacity = capacity; - buffer->value = (char *) malloc(capacity); + buffer->value = (char *) xmalloc(capacity); return buffer->value != NULL; } @@ -60,7 +60,7 @@ pm_buffer_append_length(pm_buffer_t *buffer, size_t length) { buffer->capacity *= 2; } - buffer->value = realloc(buffer->value, buffer->capacity); + buffer->value = xrealloc(buffer->value, buffer->capacity); if (buffer->value == NULL) return false; } @@ -288,5 +288,5 @@ pm_buffer_rstrip(pm_buffer_t *buffer) { */ void pm_buffer_free(pm_buffer_t *buffer) { - free(buffer->value); + xfree(buffer->value); } diff --git a/prism/util/pm_constant_pool.c b/prism/util/pm_constant_pool.c index 0436086793..5f3b0e92c8 100644 --- a/prism/util/pm_constant_pool.c +++ b/prism/util/pm_constant_pool.c @@ -51,7 +51,7 @@ pm_constant_id_list_memsize(pm_constant_id_list_t *list) { void pm_constant_id_list_free(pm_constant_id_list_t *list) { if (list->ids != NULL) { - free(list->ids); + xfree(list->ids); } } @@ -111,7 +111,7 @@ pm_constant_pool_resize(pm_constant_pool_t *pool) { const uint32_t mask = next_capacity - 1; const size_t element_size = sizeof(pm_constant_pool_bucket_t) + sizeof(pm_constant_t); - void *next = calloc(next_capacity, element_size); + void *next = xcalloc(next_capacity, element_size); if (next == NULL) return false; pm_constant_pool_bucket_t *next_buckets = next; @@ -145,7 +145,7 @@ pm_constant_pool_resize(pm_constant_pool_t *pool) { // pool->constants and pool->buckets are allocated out of the same chunk // of memory, with the buckets coming first. - free(pool->buckets); + xfree(pool->buckets); pool->constants = next_constants; pool->buckets = next_buckets; pool->capacity = next_capacity; @@ -162,7 +162,7 @@ pm_constant_pool_init(pm_constant_pool_t *pool, uint32_t capacity) { capacity = next_power_of_two(capacity); const size_t element_size = sizeof(pm_constant_pool_bucket_t) + sizeof(pm_constant_t); - void *memory = calloc(capacity, element_size); + void *memory = xcalloc(capacity, element_size); if (memory == NULL) return false; pool->buckets = memory; @@ -237,12 +237,12 @@ pm_constant_pool_insert(pm_constant_pool_t *pool, const uint8_t *start, size_t l // an existing constant, then either way we don't want the given // memory. Either it's duplicated with the existing constant or // it's not necessary because we have a shared version. - free((void *) start); + xfree((void *) start); } else if (bucket->type == PM_CONSTANT_POOL_BUCKET_OWNED) { // If we're attempting to insert a shared constant and the // existing constant is owned, then we can free the owned // constant and replace it with the shared constant. - free((void *) constant->start); + xfree((void *) constant->start); constant->start = start; bucket->type = (unsigned int) (PM_CONSTANT_POOL_BUCKET_DEFAULT & 0x3); } @@ -314,9 +314,9 @@ pm_constant_pool_free(pm_constant_pool_t *pool) { // If an id is set on this constant, then we know we have content here. if (bucket->id != PM_CONSTANT_ID_UNSET && bucket->type == PM_CONSTANT_POOL_BUCKET_OWNED) { pm_constant_t *constant = &pool->constants[bucket->id - 1]; - free((void *) constant->start); + xfree((void *) constant->start); } } - free(pool->buckets); + xfree(pool->buckets); } diff --git a/prism/util/pm_integer.c b/prism/util/pm_integer.c index 98a09243ff..c03b930ad3 100644 --- a/prism/util/pm_integer.c +++ b/prism/util/pm_integer.c @@ -7,7 +7,7 @@ static pm_integer_word_t * pm_integer_node_create(pm_integer_t *integer, uint32_t value) { integer->length++; - pm_integer_word_t *node = malloc(sizeof(pm_integer_word_t)); + pm_integer_word_t *node = xmalloc(sizeof(pm_integer_word_t)); if (node == NULL) return NULL; *node = (pm_integer_word_t) { .next = NULL, .value = value }; @@ -94,7 +94,7 @@ pm_integer_divide_word(pm_integer_t *integer, pm_integer_word_t *word, uint32_t remainder = pm_integer_divide_word(integer, word->next, dividend); if (integer->length > 0 && word->next->value == 0) { - free(word->next); + xfree(word->next); word->next = NULL; integer->length--; } @@ -256,7 +256,7 @@ pm_integer_string(pm_buffer_t *buffer, const pm_integer_t *integer) { default: { // First, allocate a buffer that we'll copy the decimal digits into. size_t length = (integer->length + 1) * 10; - char *digits = calloc(length, sizeof(char)); + char *digits = xcalloc(length, sizeof(char)); if (digits == NULL) return; // Next, create a new integer that we'll use to store the result of @@ -276,7 +276,7 @@ pm_integer_string(pm_buffer_t *buffer, const pm_integer_t *integer) { // Finally, append the string to the buffer and free the digits. pm_buffer_append_string(buffer, current + 1, (size_t) (ending - current)); - free(digits); + xfree(digits); return; } } @@ -291,7 +291,7 @@ pm_integer_word_destroy(pm_integer_word_t *integer) { pm_integer_word_destroy(integer->next); } - free(integer); + xfree(integer); } /** diff --git a/prism/util/pm_list.c b/prism/util/pm_list.c index 62cfe47cfa..ad2294cd60 100644 --- a/prism/util/pm_list.c +++ b/prism/util/pm_list.c @@ -41,7 +41,7 @@ pm_list_free(pm_list_t *list) { while (node != NULL) { next = node->next; - free(node); + xfree(node); node = next; } diff --git a/prism/util/pm_list.h b/prism/util/pm_list.h index d29fe07c52..3512dee979 100644 --- a/prism/util/pm_list.h +++ b/prism/util/pm_list.h @@ -33,7 +33,7 @@ * } pm_int_node_t; * * pm_list_t list = { 0 }; - * pm_int_node_t *node = malloc(sizeof(pm_int_node_t)); + * pm_int_node_t *node = xmalloc(sizeof(pm_int_node_t)); * node->value = 5; * * pm_list_append(&list, &node->node); diff --git a/prism/util/pm_newline_list.c b/prism/util/pm_newline_list.c index 71226bb1de..f9dff4c166 100644 --- a/prism/util/pm_newline_list.c +++ b/prism/util/pm_newline_list.c @@ -6,7 +6,7 @@ */ bool pm_newline_list_init(pm_newline_list_t *list, const uint8_t *start, size_t capacity) { - list->offsets = (size_t *) calloc(capacity, sizeof(size_t)); + list->offsets = (size_t *) xcalloc(capacity, sizeof(size_t)); if (list->offsets == NULL) return false; list->start = start; @@ -29,11 +29,11 @@ pm_newline_list_append(pm_newline_list_t *list, const uint8_t *cursor) { size_t *original_offsets = list->offsets; list->capacity = (list->capacity * 3) / 2; - list->offsets = (size_t *) calloc(list->capacity, sizeof(size_t)); + list->offsets = (size_t *) xcalloc(list->capacity, sizeof(size_t)); if (list->offsets == NULL) return false; memcpy(list->offsets, original_offsets, list->size * sizeof(size_t)); - free(original_offsets); + xfree(original_offsets); } assert(*cursor == '\n'); @@ -84,5 +84,5 @@ pm_newline_list_line_column(const pm_newline_list_t *list, const uint8_t *cursor */ void pm_newline_list_free(pm_newline_list_t *list) { - free(list->offsets); + xfree(list->offsets); } diff --git a/prism/util/pm_string.c b/prism/util/pm_string.c index 4589f1e8c6..fea3f1d2cf 100644 --- a/prism/util/pm_string.c +++ b/prism/util/pm_string.c @@ -166,7 +166,7 @@ pm_string_ensure_owned(pm_string_t *string) { size_t length = pm_string_length(string); const uint8_t *source = pm_string_source(string); - uint8_t *memory = malloc(length); + uint8_t *memory = xmalloc(length); if (!memory) return; pm_string_owned_init(string, memory, length); @@ -217,7 +217,7 @@ pm_string_free(pm_string_t *string) { void *memory = (void *) string->source; if (string->type == PM_STRING_OWNED) { - free(memory); + xfree(memory); #ifdef PRISM_HAS_MMAP } else if (string->type == PM_STRING_MAPPED && string->length) { #if defined(_WIN32) diff --git a/prism/util/pm_string_list.c b/prism/util/pm_string_list.c index d49e4ed734..f6c2145987 100644 --- a/prism/util/pm_string_list.c +++ b/prism/util/pm_string_list.c @@ -12,7 +12,7 @@ pm_string_list_append(pm_string_list_t *string_list, pm_string_t *string) { string_list->capacity *= 2; } - string_list->strings = realloc(string_list->strings, string_list->capacity * sizeof(pm_string_t)); + string_list->strings = xrealloc(string_list->strings, string_list->capacity * sizeof(pm_string_t)); if (string_list->strings == NULL) abort(); } @@ -24,5 +24,5 @@ pm_string_list_append(pm_string_list_t *string_list, pm_string_t *string) { */ void pm_string_list_free(pm_string_list_t *string_list) { - free(string_list->strings); + xfree(string_list->strings); } |