From a64f1ab6883bd2e4fd3f23b1a57685daf1c3c989 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 3 Apr 2024 12:33:32 -0400 Subject: [PATCH] [ruby/prism] Fix up pm_node_list_grow https://github.com/ruby/prism/commit/7784365d3f --- prism/node.h | 12 ------------ prism/templates/src/node.c.erb | 10 +++++++--- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/prism/node.h b/prism/node.h index 8f32cb56bd..8736e59a94 100644 --- a/prism/node.h +++ b/prism/node.h @@ -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. * diff --git a/prism/templates/src/node.c.erb b/prism/templates/src/node.c.erb index 3390adcb16..e1c35f5a45 100644 --- a/prism/templates/src/node.c.erb +++ b/prism/templates/src/node.c.erb @@ -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; } /**