summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-04-03 12:33:32 -0400
committerKevin Newton <kddnewton@gmail.com>2024-04-03 17:34:12 -0400
commita64f1ab6883bd2e4fd3f23b1a57685daf1c3c989 (patch)
treeae02ac97d327a5b5e36272445be5db33900fb1d2
parenta33f19f78347d40f18d1811a3a2e87bba957dac3 (diff)
[ruby/prism] Fix up pm_node_list_grow
https://github.com/ruby/prism/commit/7784365d3f
-rw-r--r--prism/node.h12
-rw-r--r--prism/templates/src/node.c.erb10
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
@@ -18,18 +18,6 @@
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.
*
* @param list The list to append to.
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;
}
/**