refactor: add assertion for v_blob in tv_ptr() (#29554)

Also add test for using printf() and id() with a Blob.
This commit is contained in:
zeertzjq
2024-07-04 09:54:51 +08:00
committed by GitHub
parent 7f33c1967b
commit 033ea63b2f
2 changed files with 7 additions and 2 deletions

View File

@@ -629,12 +629,14 @@ static const void *tv_ptr(const typval_T *const tvs, int *const idxp)
#define OFF(attr) offsetof(union typval_vval_union, attr) #define OFF(attr) offsetof(union typval_vval_union, attr)
STATIC_ASSERT(OFF(v_string) == OFF(v_list) STATIC_ASSERT(OFF(v_string) == OFF(v_list)
&& OFF(v_string) == OFF(v_dict) && OFF(v_string) == OFF(v_dict)
&& OFF(v_string) == OFF(v_blob)
&& OFF(v_string) == OFF(v_partial) && OFF(v_string) == OFF(v_partial)
&& sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_list) && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_list)
&& sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_dict) && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_dict)
&& sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_blob)
&& sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_partial), && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_partial),
"Strings, dictionaries, lists and partials are expected to be pointers, " "Strings, Dictionaries, Lists, Blobs and Partials are expected to be pointers, "
"so that all three of them can be accessed via v_string"); "so that all of them can be accessed via v_string");
#undef OFF #undef OFF
const int idx = *idxp - 1; const int idx = *idxp - 1;
if (tvs[idx].v_type == VAR_UNKNOWN) { if (tvs[idx].v_type == VAR_UNKNOWN) {

View File

@@ -84,10 +84,13 @@ describe('printf()', function()
end end
api.nvim_del_var('__result') api.nvim_del_var('__result')
end end
check_printf('v:_null_string', true)
check_printf('v:_null_list', true) check_printf('v:_null_list', true)
check_printf('v:_null_dict', true) check_printf('v:_null_dict', true)
check_printf('v:_null_blob', true)
check_printf('[]') check_printf('[]')
check_printf('{}') check_printf('{}')
check_printf('0z')
check_printf('function("tr", ["a"])') check_printf('function("tr", ["a"])')
end) end)
end) end)