[vim/vim] Extend items() to support a blob (PR #18080)

17 views
Skip to first unread message

Yegappan Lakshmanan

unread,
Aug 21, 2025, 10:27:15 PMAug 21
to vim/vim, Subscribed

The items() function currently supports a List, Tuple, Dict or a String. Extend it to also support a Blob.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/18080

Commit Summary

  • 789d085 Extend items() to support blob

File Changes

(11 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18080@github.com>

Yegappan Lakshmanan

unread,
Aug 21, 2025, 10:31:24 PMAug 21
to vim/vim, Push

@yegappan pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18080/before/789d085bba14b83b8ae3118feb26023bad17e9b5/after/96c299651172b884b017d9e94757542dab28a636@github.com>

Christ van Willegen

unread,
Aug 21, 2025, 10:42:17 PMAug 21
to vim...@googlegroups.com, nor...@github.com

+/*
+ * "items(blob)" function
+ * Converts a Blob into a List of [index, byte] pairs.
+ * Caller must have already checked that argvars[0] is a Blob.
+ * A null blob behaves like an empty blob.
+ */
+ void
+blob2items(typval_T *argvars, typval_T *rettv)
+{
+ blob_T *blob = argvars[0].vval.v_blob;
+
+ if (rettv_list_alloc(rettv) == FAIL)
+ return;
+
+ for (int i = 0; i < blob_len(blob); i++)
+ {
+ list_T *l2 = list_alloc();
+ if (l2 == NULL)
+ return;


Memory leak rettv?

+
+ if (list_append_list(rettv->vval.v_list, l2) == FAIL)
+ {
+ vim_free(l2);
+ return;
+ }
+
+ if (list_append_number(l2, i) == FAIL
+ || list_append_number(l2, blob_get(blob, i)) == FAIL)
+ return;


Memory leak l2?


+ }
+}



Christ van Willegen

Yegappan Lakshmanan

unread,
Aug 21, 2025, 10:48:09 PMAug 21
to vim...@googlegroups.com, nor...@github.com
On Thu, Aug 21, 2025 at 7:42 PM Christ van Willegen <cvwil...@gmail.com> wrote:

+/*
+ * "items(blob)" function
+ * Converts a Blob into a List of [index, byte] pairs.
+ * Caller must have already checked that argvars[0] is a Blob.
+ * A null blob behaves like an empty blob.
+ */
+ void
+blob2items(typval_T *argvars, typval_T *rettv)
+{
+ blob_T *blob = argvars[0].vval.v_blob;
+
+ if (rettv_list_alloc(rettv) == FAIL)
+ return;
+
+ for (int i = 0; i < blob_len(blob); i++)
+ {
+ list_T *l2 = list_alloc();
+ if (l2 == NULL)
+ return;


Memory leak rettv?


No.  This function is expected to set rettv to a List.  In case of failure, this will return an empty List.
This is the same as how other types (List, Dict, Tuple, String) are handled.  The returned List
will be freed later.
 
+
+ if (list_append_list(rettv->vval.v_list, l2) == FAIL)
+ {
+ vim_free(l2);
+ return;
+ }
+
+ if (list_append_number(l2, i) == FAIL
+ || list_append_number(l2, blob_get(blob, i)) == FAIL)
+ return;


Memory leak l2?


No.  The list l2 is already added to rettv.

Regards,
Yegappan
 

+ }
+}


Yegappan Lakshmanan

unread,
Aug 22, 2025, 9:38:12 PMAug 22
to vim/vim, Push

@yegappan pushed 1 commit.

  • c646405 Extend items() to support blob

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18080/before/5e4fd5193cb39efa8fbcb96ef537214a64657906/after/c64640555c25d5d893cfbe40ac8f5d13b305df35@github.com>

Christian Brabandt

unread,
Aug 23, 2025, 7:18:05 AMAug 23
to vim/vim, Subscribed

Closed #18080 via da34f84.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18080/issue_event/19302240452@github.com>

Christian Brabandt

unread,
Aug 23, 2025, 7:18:05 AMAug 23
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#18080)

thanks


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/18080/c3216720430@github.com>

Reply all
Reply to author
Forward
0 new messages