comparison src/eval.c @ 15466:435fcefd2c8e v8.1.0741

patch 8.1.0741: viminfo with Blob is not tested commit https://github.com/vim/vim/commit/8c8b8bb56c724cc1bfc3d8520eec33f2d399697c Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 13 17:48:04 2019 +0100 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.
author Bram Moolenaar <Bram@vim.org>
date Sun, 13 Jan 2019 18:00:05 +0100
parents 3faa7cc8207c
children 55ccc2d353bd
comparison
equal deleted inserted replaced
15465:0f076f6c5356 15466:435fcefd2c8e
5880 r = *tofree; 5880 r = *tofree;
5881 break; 5881 break;
5882 } 5882 }
5883 5883
5884 case VAR_BLOB: 5884 case VAR_BLOB:
5885 if (tv->vval.v_blob == NULL) 5885 r = blob2string(tv->vval.v_blob, tofree, numbuf);
5886 {
5887 *tofree = NULL;
5888 r = (char_u *)"[]";
5889 }
5890 else
5891 {
5892 blob_T *b;
5893 int i;
5894 garray_T ga;
5895
5896 // Store bytes in the growarray.
5897 ga_init2(&ga, 1, 4000);
5898 b = tv->vval.v_blob;
5899 ga_append(&ga, '[');
5900 for (i = 0; i < blob_len(b); i++)
5901 {
5902 if (i > 0)
5903 ga_concat(&ga, (char_u *)",");
5904 vim_snprintf((char *)numbuf, NUMBUFLEN, "0x%02X",
5905 (int)blob_get(b, i));
5906 ga_concat(&ga, numbuf);
5907 }
5908 ga_append(&ga, ']');
5909 *tofree = ga.ga_data;
5910 r = *tofree;
5911 }
5912 break; 5886 break;
5913 5887
5914 case VAR_LIST: 5888 case VAR_LIST:
5915 if (tv->vval.v_list == NULL) 5889 if (tv->vval.v_list == NULL)
5916 { 5890 {
8946 8920
8947 tab = vim_strchr(tab, '\t'); 8921 tab = vim_strchr(tab, '\t');
8948 if (tab != NULL) 8922 if (tab != NULL)
8949 { 8923 {
8950 tv.v_type = type; 8924 tv.v_type = type;
8951 if (type == VAR_STRING || type == VAR_DICT || 8925 if (type == VAR_STRING || type == VAR_DICT
8952 type == VAR_LIST || type == VAR_BLOB) 8926 || type == VAR_LIST || type == VAR_BLOB)
8953 tv.vval.v_string = viminfo_readstring(virp, 8927 tv.vval.v_string = viminfo_readstring(virp,
8954 (int)(tab - virp->vir_line + 1), TRUE); 8928 (int)(tab - virp->vir_line + 1), TRUE);
8955 #ifdef FEAT_FLOAT 8929 #ifdef FEAT_FLOAT
8956 else if (type == VAR_FLOAT) 8930 else if (type == VAR_FLOAT)
8957 (void)string2float(tab + 1, &tv.vval.v_float); 8931 (void)string2float(tab + 1, &tv.vval.v_float);
8958 #endif 8932 #endif
8959 else 8933 else
8960 tv.vval.v_number = atol((char *)tab + 1); 8934 tv.vval.v_number = atol((char *)tab + 1);
8961 if (type == VAR_DICT || type == VAR_LIST || type == VAR_BLOB) 8935 if (type == VAR_DICT || type == VAR_LIST)
8962 { 8936 {
8963 typval_T *etv = eval_expr(tv.vval.v_string, NULL); 8937 typval_T *etv = eval_expr(tv.vval.v_string, NULL);
8964 8938
8965 if (etv == NULL) 8939 if (etv == NULL)
8966 /* Failed to parse back the dict or list, use it as a 8940 /* Failed to parse back the dict or list, use it as a
8971 vim_free(tv.vval.v_string); 8945 vim_free(tv.vval.v_string);
8972 tv = *etv; 8946 tv = *etv;
8973 vim_free(etv); 8947 vim_free(etv);
8974 } 8948 }
8975 } 8949 }
8950 else if (type == VAR_BLOB)
8951 {
8952 blob_T *blob = string2blob(tv.vval.v_string);
8953
8954 if (blob == NULL)
8955 // Failed to parse back the blob, use it as a string.
8956 tv.v_type = VAR_STRING;
8957 else
8958 {
8959 vim_free(tv.vval.v_string);
8960 tv.v_type = VAR_BLOB;
8961 tv.vval.v_blob = blob;
8962 }
8963 }
8976 8964
8977 /* when in a function use global variables */ 8965 /* when in a function use global variables */
8978 save_funccal(&funccal_entry); 8966 save_funccal(&funccal_entry);
8979 set_var(virp->vir_line + 1, &tv, FALSE); 8967 set_var(virp->vir_line + 1, &tv, FALSE);
8980 restore_funccal(); 8968 restore_funccal();
9035 case VAR_JOB: 9023 case VAR_JOB:
9036 case VAR_CHANNEL: 9024 case VAR_CHANNEL:
9037 continue; 9025 continue;
9038 } 9026 }
9039 fprintf(fp, "!%s\t%s\t", this_var->di_key, s); 9027 fprintf(fp, "!%s\t%s\t", this_var->di_key, s);
9040 p = echo_string(&this_var->di_tv, &tofree, numbuf, 0); 9028 if (this_var->di_tv.v_type == VAR_SPECIAL)
9029 {
9030 sprintf((char *)numbuf, "%ld",
9031 (long)this_var->di_tv.vval.v_number);
9032 p = numbuf;
9033 tofree = NULL;
9034 }
9035 else
9036 p = echo_string(&this_var->di_tv, &tofree, numbuf, 0);
9041 if (p != NULL) 9037 if (p != NULL)
9042 viminfo_writestring(fp, p); 9038 viminfo_writestring(fp, p);
9043 vim_free(tofree); 9039 vim_free(tofree);
9044 } 9040 }
9045 } 9041 }