Re: [vim/vim] Make extend() accept blobs (PR #20958)
h_east (Vim Github Repository) <[email protected]> Thu, 06 Aug 2026 10:16:03 -0700
| Newsgroups | gmane.editors.vim.devel |
|---|---|
| Message-ID | <vim/vim/pull/20958/[email protected]> |
h-east left a comment (vim/vim#20958)
`VAR_ANY` there is not intentional for blobs, it is just the default.
`generate_PUSHBLOB()` goes through `generate_instr_type()`, which always passes
`&t_any` as the declared type (`vim9instr.c:88`), while `generate_NEWLIST()`
pushes a `list<any>` of its own (`vim9instr.c:1438`). `arg_same_as_prev()`
compares against `type_decl` (`evalfunc.c:1008`), so `[1]` is checked against
`list<any>` and rejects `42`, while `0z01` is checked against `any` and passes.
That default is deliberate: constants have no declared type, and
`NEWLIST`/`NEWDICT` are the exception because a container's member type can
still widen. It went unnoticed for blobs because `arg_same_as_prev()` is used
by `extend()` alone, and `extend()` did not take blobs until now.
This fixes it:
```c
if ((isn = generate_instr_type2(cctx, ISN_PUSHBLOB, &t_blob, &t_blob))
== NULL)
return FAIL;
```
It widens the declared type of every blob literal, but nothing else reads
`type_decl`: `vim9compile.c` never does, `arg_same_as_prev()` is used by
`extend()` alone, `arg_item_of_prev()` looks at it only for lists and dicts,
and blob index and slice overwrite it anyway (`vim9expr.c:227`).
Other things I noticed:
- `make test_listdict` aborts in `Test_extendnew_leak()`. `blob_extend_func()`
puts the copy into `rettv` up front, so the `blob_unref(b1)` at `cleanup:`
leaves `rettv->vval.v_blob` pointing at freed memory. `list_extend_func()`
keeps its copy in a local and moves it into `rettv` at `theend:`.
`extendnew(0z, 0z, 0z)` reaches it: the third argument is a blob, so
`tv_get_number_chk()` fails.
- `0z0102030102030` in `Test_listdict_extend()` has an odd number of hex
digits.
- `b->extend([])` in the same block: the second argument is not a blob.
- `EXXXX` in `errors.h` and in the `assert_fails()` needs a real number.
--
Reply to this email directly or view it on GitHub:
https://github.com/vim/vim/pull/20958#issuecomment-5207736540
You are receiving this because you are subscribed to this thread.
Message ID: <vim/vim/pull/20958/[email protected]>
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/vim/vim/pull/20958/c5207736540%40github.com.