forked from aniani/vim
patch 8.1.0741: viminfo with Blob is not tested
Problem: Viminfo with Blob is not tested. Solution: Extend the viminfo test. Fix reading a blob. Fixed storing a special variable value.
This commit is contained in:
parent
8309b0559d
commit
8c8b8bb56c
67
src/blob.c
67
src/blob.c
@ -167,4 +167,71 @@ write_blob(FILE *fd, blob_T *blob)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a blob to a readable form: "[0x11,0x34]"
|
||||||
|
*/
|
||||||
|
char_u *
|
||||||
|
blob2string(blob_T *blob, char_u **tofree, char_u *numbuf)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
garray_T ga;
|
||||||
|
|
||||||
|
if (blob == NULL)
|
||||||
|
{
|
||||||
|
*tofree = NULL;
|
||||||
|
return (char_u *)"[]";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store bytes in the growarray.
|
||||||
|
ga_init2(&ga, 1, 4000);
|
||||||
|
ga_append(&ga, '[');
|
||||||
|
for (i = 0; i < blob_len(blob); i++)
|
||||||
|
{
|
||||||
|
if (i > 0)
|
||||||
|
ga_concat(&ga, (char_u *)",");
|
||||||
|
vim_snprintf((char *)numbuf, NUMBUFLEN, "0x%02X", (int)blob_get(blob, i));
|
||||||
|
ga_concat(&ga, numbuf);
|
||||||
|
}
|
||||||
|
ga_append(&ga, ']');
|
||||||
|
*tofree = ga.ga_data;
|
||||||
|
return *tofree;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a string variable, in the format of blob2string(), to a blob.
|
||||||
|
* Return NULL when conversion failed.
|
||||||
|
*/
|
||||||
|
blob_T *
|
||||||
|
string2blob(char_u *str)
|
||||||
|
{
|
||||||
|
blob_T *blob = blob_alloc();
|
||||||
|
char_u *s = str;
|
||||||
|
|
||||||
|
if (*s != '[')
|
||||||
|
goto failed;
|
||||||
|
s = skipwhite(s + 1);
|
||||||
|
while (*s != ']')
|
||||||
|
{
|
||||||
|
if (s[0] != '0' || s[1] != 'x'
|
||||||
|
|| !vim_isxdigit(s[2]) || !vim_isxdigit(s[3]))
|
||||||
|
goto failed;
|
||||||
|
ga_append(&blob->bv_ga, (hex2nr(s[2]) << 4) + hex2nr(s[3]));
|
||||||
|
s += 4;
|
||||||
|
if (*s == ',')
|
||||||
|
s = skipwhite(s + 1);
|
||||||
|
else if (*s != ']')
|
||||||
|
goto failed;
|
||||||
|
}
|
||||||
|
s = skipwhite(s + 1);
|
||||||
|
if (*s != NUL)
|
||||||
|
goto failed; // text after final ']'
|
||||||
|
|
||||||
|
++blob->bv_refcount;
|
||||||
|
return blob;
|
||||||
|
|
||||||
|
failed:
|
||||||
|
blob_free(blob);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* defined(FEAT_EVAL) */
|
#endif /* defined(FEAT_EVAL) */
|
||||||
|
56
src/eval.c
56
src/eval.c
@ -5882,33 +5882,7 @@ echo_string_core(
|
|||||||
}
|
}
|
||||||
|
|
||||||
case VAR_BLOB:
|
case VAR_BLOB:
|
||||||
if (tv->vval.v_blob == NULL)
|
r = blob2string(tv->vval.v_blob, tofree, numbuf);
|
||||||
{
|
|
||||||
*tofree = NULL;
|
|
||||||
r = (char_u *)"[]";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
blob_T *b;
|
|
||||||
int i;
|
|
||||||
garray_T ga;
|
|
||||||
|
|
||||||
// Store bytes in the growarray.
|
|
||||||
ga_init2(&ga, 1, 4000);
|
|
||||||
b = tv->vval.v_blob;
|
|
||||||
ga_append(&ga, '[');
|
|
||||||
for (i = 0; i < blob_len(b); i++)
|
|
||||||
{
|
|
||||||
if (i > 0)
|
|
||||||
ga_concat(&ga, (char_u *)",");
|
|
||||||
vim_snprintf((char *)numbuf, NUMBUFLEN, "0x%02X",
|
|
||||||
(int)blob_get(b, i));
|
|
||||||
ga_concat(&ga, numbuf);
|
|
||||||
}
|
|
||||||
ga_append(&ga, ']');
|
|
||||||
*tofree = ga.ga_data;
|
|
||||||
r = *tofree;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VAR_LIST:
|
case VAR_LIST:
|
||||||
@ -8948,8 +8922,8 @@ read_viminfo_varlist(vir_T *virp, int writing)
|
|||||||
if (tab != NULL)
|
if (tab != NULL)
|
||||||
{
|
{
|
||||||
tv.v_type = type;
|
tv.v_type = type;
|
||||||
if (type == VAR_STRING || type == VAR_DICT ||
|
if (type == VAR_STRING || type == VAR_DICT
|
||||||
type == VAR_LIST || type == VAR_BLOB)
|
|| type == VAR_LIST || type == VAR_BLOB)
|
||||||
tv.vval.v_string = viminfo_readstring(virp,
|
tv.vval.v_string = viminfo_readstring(virp,
|
||||||
(int)(tab - virp->vir_line + 1), TRUE);
|
(int)(tab - virp->vir_line + 1), TRUE);
|
||||||
#ifdef FEAT_FLOAT
|
#ifdef FEAT_FLOAT
|
||||||
@ -8958,7 +8932,7 @@ read_viminfo_varlist(vir_T *virp, int writing)
|
|||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
tv.vval.v_number = atol((char *)tab + 1);
|
tv.vval.v_number = atol((char *)tab + 1);
|
||||||
if (type == VAR_DICT || type == VAR_LIST || type == VAR_BLOB)
|
if (type == VAR_DICT || type == VAR_LIST)
|
||||||
{
|
{
|
||||||
typval_T *etv = eval_expr(tv.vval.v_string, NULL);
|
typval_T *etv = eval_expr(tv.vval.v_string, NULL);
|
||||||
|
|
||||||
@ -8973,6 +8947,20 @@ read_viminfo_varlist(vir_T *virp, int writing)
|
|||||||
vim_free(etv);
|
vim_free(etv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (type == VAR_BLOB)
|
||||||
|
{
|
||||||
|
blob_T *blob = string2blob(tv.vval.v_string);
|
||||||
|
|
||||||
|
if (blob == NULL)
|
||||||
|
// Failed to parse back the blob, use it as a string.
|
||||||
|
tv.v_type = VAR_STRING;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vim_free(tv.vval.v_string);
|
||||||
|
tv.v_type = VAR_BLOB;
|
||||||
|
tv.vval.v_blob = blob;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* when in a function use global variables */
|
/* when in a function use global variables */
|
||||||
save_funccal(&funccal_entry);
|
save_funccal(&funccal_entry);
|
||||||
@ -9037,6 +9025,14 @@ write_viminfo_varlist(FILE *fp)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fprintf(fp, "!%s\t%s\t", this_var->di_key, s);
|
fprintf(fp, "!%s\t%s\t", this_var->di_key, s);
|
||||||
|
if (this_var->di_tv.v_type == VAR_SPECIAL)
|
||||||
|
{
|
||||||
|
sprintf((char *)numbuf, "%ld",
|
||||||
|
(long)this_var->di_tv.vval.v_number);
|
||||||
|
p = numbuf;
|
||||||
|
tofree = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
p = echo_string(&this_var->di_tv, &tofree, numbuf, 0);
|
p = echo_string(&this_var->di_tv, &tofree, numbuf, 0);
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
viminfo_writestring(fp, p);
|
viminfo_writestring(fp, p);
|
||||||
|
@ -10,4 +10,6 @@ void blob_set(blob_T *b, int idx, char_u c);
|
|||||||
int blob_equal(blob_T *b1, blob_T *b2);
|
int blob_equal(blob_T *b1, blob_T *b2);
|
||||||
int read_blob(FILE *fd, blob_T *blob);
|
int read_blob(FILE *fd, blob_T *blob);
|
||||||
int write_blob(FILE *fd, blob_T *blob);
|
int write_blob(FILE *fd, blob_T *blob);
|
||||||
|
char_u *blob2string(blob_T *blob, char_u **tofree, char_u *numbuf);
|
||||||
|
blob_T *string2blob(char_u *str);
|
||||||
/* vim: set ft=c : */
|
/* vim: set ft=c : */
|
||||||
|
@ -39,14 +39,36 @@ func Test_global_vars()
|
|||||||
" store a really long list, so line wrapping will occur in viminfo file
|
" store a really long list, so line wrapping will occur in viminfo file
|
||||||
let test_list = range(1,100)
|
let test_list = range(1,100)
|
||||||
let g:MY_GLOBAL_LIST = test_list
|
let g:MY_GLOBAL_LIST = test_list
|
||||||
|
let test_blob = 0z00112233445566778899aabbccddeeff
|
||||||
|
let g:MY_GLOBAL_BLOB = test_blob
|
||||||
|
let test_false = v:false
|
||||||
|
let g:MY_GLOBAL_FALSE = test_false
|
||||||
|
let test_true = v:true
|
||||||
|
let g:MY_GLOBAL_TRUE = test_true
|
||||||
|
let test_null = v:null
|
||||||
|
let g:MY_GLOBAL_NULL = test_null
|
||||||
|
let test_none = v:none
|
||||||
|
let g:MY_GLOBAL_NONE = test_none
|
||||||
|
|
||||||
set viminfo='100,<50,s10,h,!,nviminfo
|
set viminfo='100,<50,s10,h,!,nviminfo
|
||||||
wv! Xviminfo
|
wv! Xviminfo
|
||||||
|
|
||||||
unlet g:MY_GLOBAL_DICT
|
unlet g:MY_GLOBAL_DICT
|
||||||
unlet g:MY_GLOBAL_LIST
|
unlet g:MY_GLOBAL_LIST
|
||||||
|
unlet g:MY_GLOBAL_BLOB
|
||||||
|
unlet g:MY_GLOBAL_FALSE
|
||||||
|
unlet g:MY_GLOBAL_TRUE
|
||||||
|
unlet g:MY_GLOBAL_NULL
|
||||||
|
unlet g:MY_GLOBAL_NONE
|
||||||
|
|
||||||
rv! Xviminfo
|
rv! Xviminfo
|
||||||
call assert_equal(test_dict, g:MY_GLOBAL_DICT)
|
call assert_equal(test_dict, g:MY_GLOBAL_DICT)
|
||||||
call assert_equal(test_list, g:MY_GLOBAL_LIST)
|
call assert_equal(test_list, g:MY_GLOBAL_LIST)
|
||||||
|
call assert_equal(test_blob, g:MY_GLOBAL_BLOB)
|
||||||
|
call assert_equal(test_false, g:MY_GLOBAL_FALSE)
|
||||||
|
call assert_equal(test_true, g:MY_GLOBAL_TRUE)
|
||||||
|
call assert_equal(test_null, g:MY_GLOBAL_NULL)
|
||||||
|
call assert_equal(test_none, g:MY_GLOBAL_NONE)
|
||||||
|
|
||||||
call delete('Xviminfo')
|
call delete('Xviminfo')
|
||||||
set viminfo-=!
|
set viminfo-=!
|
||||||
|
@ -795,6 +795,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
741,
|
||||||
/**/
|
/**/
|
||||||
740,
|
740,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user