summaryrefslogtreecommitdiffstats
path: root/src/blob.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-04-17 20:44:56 +0200
committerBram Moolenaar <Bram@vim.org>2021-04-17 20:44:56 +0200
commit51e933261b984db014e858d79387a826d2626fb6 (patch)
tree29c07c5c1e9acbbffe79a9da8065c0098a094bb6 /src/blob.c
parent0995c81f2ffe276669daa004f7778ecc6f5ee09d (diff)
patch 8.2.2777: Vim9: blob operations not tested in all waysv8.2.2777
Problem: Vim9: blob operations not tested in all ways. Solution: Run tests with CheckLegacyAndVim9Success(). Make blob assign with index work.
Diffstat (limited to 'src/blob.c')
-rw-r--r--src/blob.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/blob.c b/src/blob.c
index 114dacdec2..9f59777073 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -125,13 +125,33 @@ blob_get(blob_T *b, int idx)
}
/*
- * Store one byte "c" in blob "b" at "idx".
+ * Store one byte "byte" in blob "blob" at "idx".
* Caller must make sure that "idx" is valid.
*/
void
-blob_set(blob_T *b, int idx, char_u c)
+blob_set(blob_T *blob, int idx, int byte)
{
- ((char_u*)b->bv_ga.ga_data)[idx] = c;
+ ((char_u*)blob->bv_ga.ga_data)[idx] = byte;
+}
+
+/*
+ * Store one byte "byte" in blob "blob" at "idx".
+ * Append one byte if needed.
+ */
+ void
+blob_set_append(blob_T *blob, int idx, int byte)
+{
+ garray_T *gap = &blob->bv_ga;
+
+ // Allow for appending a byte. Setting a byte beyond
+ // the end is an error otherwise.
+ if (idx < gap->ga_len
+ || (idx == gap->ga_len && ga_grow(gap, 1) == OK))
+ {
+ blob_set(blob, idx, byte);
+ if (idx == gap->ga_len)
+ ++gap->ga_len;
+ }
}
/*