summaryrefslogtreecommitdiff
path: root/prism/util/pm_integer.c
diff options
context:
space:
mode:
authorHASUMI Hitoshi <[email protected]>2024-02-27 14:25:22 +0900
committergit <[email protected]>2024-03-04 16:40:23 +0000
commitc4bd6da2988ecdf3e6d00be78e58a4eba6192bed (patch)
treef5cc0976ae7ff16bac9913f02ec4d32adef41160 /prism/util/pm_integer.c
parent61ea202f8b10060e000f79a936e5e608eacb50ee (diff)
[ruby/prism] Make alloc interface replaceable
- Add `x` prefix to malloc, calloc, realloc, and free (eg: malloc -> xmalloc) - By default, they are replaced with stdlib's functions at build - You can use custom functions by defining `PRISM_CUSTOM_ALLOCATOR` macro https://github.com/ruby/prism/commit/7a878af619
Diffstat (limited to 'prism/util/pm_integer.c')
-rw-r--r--prism/util/pm_integer.c10
1 files changed, 5 insertions, 5 deletions
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);
}
/**