diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-01-13 17:48:04 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-01-13 17:48:04 +0100 |
commit | 8c8b8bb56c724cc1bfc3d8520eec33f2d399697c (patch) | |
tree | 62748a3e2cc6168a4d8eb8799ed8708c5575a278 /src/eval.c | |
parent | 8309b0559da6e9a581a7816572594c90c2d7f942 (diff) |
patch 8.1.0741: viminfo with Blob is not testedv8.1.0741
Problem: Viminfo with Blob is not tested.
Solution: Extend the viminfo test. Fix reading a blob. Fixed storing a
special variable value.
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/src/eval.c b/src/eval.c index e7dcf07499..835e44ccea 100644 --- a/src/eval.c +++ b/src/eval.c @@ -5882,33 +5882,7 @@ echo_string_core( } case VAR_BLOB: - if (tv->vval.v_blob == NULL) - { - *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; - } + r = blob2string(tv->vval.v_blob, tofree, numbuf); break; case VAR_LIST: @@ -8948,8 +8922,8 @@ read_viminfo_varlist(vir_T *virp, int writing) if (tab != NULL) { tv.v_type = type; - if (type == VAR_STRING || type == VAR_DICT || - type == VAR_LIST || type == VAR_BLOB) + if (type == VAR_STRING || type == VAR_DICT + || type == VAR_LIST || type == VAR_BLOB) tv.vval.v_string = viminfo_readstring(virp, (int)(tab - virp->vir_line + 1), TRUE); #ifdef FEAT_FLOAT @@ -8958,7 +8932,7 @@ read_viminfo_varlist(vir_T *virp, int writing) #endif else 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); @@ -8973,6 +8947,20 @@ read_viminfo_varlist(vir_T *virp, int writing) 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 */ save_funccal(&funccal_entry); @@ -9037,7 +9025,15 @@ write_viminfo_varlist(FILE *fp) continue; } fprintf(fp, "!%s\t%s\t", this_var->di_key, s); - p = echo_string(&this_var->di_tv, &tofree, numbuf, 0); + 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); if (p != NULL) viminfo_writestring(fp, p); vim_free(tofree); |