summaryrefslogtreecommitdiff
path: root/src/alloc.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-01-08 15:39:39 +0000
committerBram Moolenaar <Bram@vim.org>2022-01-08 15:39:39 +0000
commit9f1a39a5d1cd7989ada2d1cb32f97d84360e050f (patch)
tree9ea5c2c61d570af5fa2cee2e1a7ef6d6d107569e /src/alloc.c
parent67ffb417861a90fd2c1b215a42fd230272ed94cb (diff)
downloadvim-git-9f1a39a5d1cd7989ada2d1cb32f97d84360e050f.tar.gz
patch 8.2.4040: keeping track of allocated lines is too complicatedv8.2.4040
Problem: Keeping track of allocated lines in user functions is too complicated. Solution: Instead of freeing individual lines keep them all until the end.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 3651a2e59..e3cd8578f 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -702,7 +702,7 @@ ga_init(garray_T *gap)
}
void
-ga_init2(garray_T *gap, int itemsize, int growsize)
+ga_init2(garray_T *gap, size_t itemsize, int growsize)
{
ga_init(gap);
gap->ga_itemsize = itemsize;
@@ -789,7 +789,7 @@ ga_concat_strings(garray_T *gap, char *sep)
* When out of memory nothing changes and FAIL is returned.
*/
int
-ga_add_string(garray_T *gap, char_u *p)
+ga_copy_string(garray_T *gap, char_u *p)
{
char_u *cp = vim_strsave(p);
@@ -806,6 +806,19 @@ ga_add_string(garray_T *gap, char_u *p)
}
/*
+ * Add string "p" to "gap".
+ * When out of memory "p" is freed and FAIL is returned.
+ */
+ int
+ga_add_string(garray_T *gap, char_u *p)
+{
+ if (ga_grow(gap, 1) == FAIL)
+ return FAIL;
+ ((char_u **)(gap->ga_data))[gap->ga_len++] = p;
+ return OK;
+}
+
+/*
* Concatenate a string to a growarray which contains bytes.
* When "s" is NULL does not do anything.
* Note: Does NOT copy the NUL at the end!