aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-02-28 14:27:47 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-02-28 15:21:30 +0800
commit761a559dbfed99e588d7f306c89331907b2d5a92 (patch)
tree76c130f2443612e2b5ebd0eafda8f74818205fc8 /src/nvim/eval
parent99faac86444a7f4c0790d150307c67d98db7c62e (diff)
downloadrneovim-761a559dbfed99e588d7f306c89331907b2d5a92.tar.gz
rneovim-761a559dbfed99e588d7f306c89331907b2d5a92.tar.bz2
rneovim-761a559dbfed99e588d7f306c89331907b2d5a92.zip
vim-patch:8.2.2777: Vim9: blob operations not tested in all ways
Problem: Vim9: blob operations not tested in all ways. Solution: Run tests with CheckLegacyAndVim9Success(). Make blob assign with index work. https://github.com/vim/vim/commit/51e933261b984db014e858d79387a826d2626fb6 Cherry-pick related changes from patches 8.2.{0633,0634}. N/A patches for version.c: vim-patch:8.2.2779: memory access error in remove() for blob Problem: Memory access error in remove() for blob. Solution: Adjust length for memmove(). https://github.com/vim/vim/commit/f7e92aae1581203306a340b4c0059cc74adea9d6 Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/eval')
-rw-r--r--src/nvim/eval/typval.c17
-rw-r--r--src/nvim/eval/typval.h6
2 files changed, 20 insertions, 3 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 7e94e03823..d56efe30da 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -2750,6 +2750,23 @@ int tv_blob_set_range(blob_T *dest, long n1, long n2, typval_T *src)
return OK;
}
+/// Store one byte "byte" in blob "blob" at "idx".
+/// Append one byte if needed.
+void tv_blob_set_append(blob_T *blob, int idx, uint8_t 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) {
+ if (idx == gap->ga_len) {
+ ga_grow(gap, 1);
+ gap->ga_len++;
+ }
+ tv_blob_set(blob, idx, byte);
+ }
+}
+
/// "remove({blob})" function
void tv_blob_remove(typval_T *argvars, typval_T *rettv, const char *arg_errmsg)
{
diff --git a/src/nvim/eval/typval.h b/src/nvim/eval/typval.h
index 3f59cd3547..4a2654f03e 100644
--- a/src/nvim/eval/typval.h
+++ b/src/nvim/eval/typval.h
@@ -372,7 +372,7 @@ static inline uint8_t tv_blob_get(const blob_T *const b, int idx)
return ((uint8_t *)b->bv_ga.ga_data)[idx];
}
-static inline void tv_blob_set(blob_T *b, int idx, uint8_t c)
+static inline void tv_blob_set(blob_T *blob, int idx, uint8_t c)
REAL_FATTR_ALWAYS_INLINE REAL_FATTR_NONNULL_ALL;
/// Store the byte `c` at index `idx` in the blob.
@@ -380,9 +380,9 @@ static inline void tv_blob_set(blob_T *b, int idx, uint8_t c)
/// @param[in] b Blob to index. Cannot be NULL.
/// @param[in] idx Index in a blob. Must be valid.
/// @param[in] c Value to store.
-static inline void tv_blob_set(blob_T *const b, int idx, uint8_t c)
+static inline void tv_blob_set(blob_T *const blob, int idx, uint8_t c)
{
- ((uint8_t *)b->bv_ga.ga_data)[idx] = c;
+ ((uint8_t *)blob->bv_ga.ga_data)[idx] = c;
}
/// Initialize VimL object