[ruby/prism] Fix up pm_node_list_grow

https://github.com/ruby/prism/commit/7784365d3f
This commit is contained in:
Kevin Newton 2024-04-03 12:33:32 -04:00
Родитель a33f19f783
Коммит a64f1ab688
2 изменённых файлов: 7 добавлений и 15 удалений

Просмотреть файл

@ -17,18 +17,6 @@
#define PM_NODE_LIST_FOREACH(list, index, node) \
for (size_t index = 0; index < (list)->size && ((node) = (list)->nodes[index]); index++)
/**
* Attempts to grow the node list to the next size. If there is already
* capacity in the list, this function does nothing. Otherwise it reallocates
* the list to be twice as large as it was before. If the reallocation fails,
* this function returns false, otherwise it returns true.
*
* @param list The list to grow.
* @param size The number of nodes to grow the list by.
* @return True if the list was successfully grown, false otherwise.
*/
bool pm_node_list_grow(pm_node_list_t *list, size_t size);
/**
* Append a new node onto the end of the node list.
*

Просмотреть файл

@ -20,7 +20,7 @@ pm_node_list_memsize(pm_node_list_t *node_list, pm_memsize_t *memsize) {
* the list to be twice as large as it was before. If the reallocation fails,
* this function returns false, otherwise it returns true.
*/
bool
static bool
pm_node_list_grow(pm_node_list_t *list, size_t size) {
size_t requested_size = list->size + size;
@ -45,8 +45,12 @@ pm_node_list_grow(pm_node_list_t *list, size_t size) {
next_capacity = double_capacity;
}
list->nodes = (pm_node_t **) xrealloc(list->nodes, sizeof(pm_node_t *) * next_capacity);
return list->nodes != NULL;
pm_node_t **nodes = (pm_node_t **) xrealloc(list->nodes, sizeof(pm_node_t *) * next_capacity);
if (nodes == NULL) return false;
list->nodes = nodes;
list->capacity = next_capacity;
return true;
}
/**