eval: Do not use msgpack#string for error messages

This commit is contained in:
ZyX 2016-01-06 22:47:39 +03:00
parent bd4ca22cf0
commit c6f6033482
4 changed files with 3 additions and 54 deletions

View File

@ -4719,10 +4719,6 @@ msgpackdump({list}) {Nvim} *msgpackdump()*
4. Other strings are always dumped as BIN strings.
5. Points 3. and 4. do not apply to |msgpack-special-dict|s.
Note: error messages may use |msgpack#string()| function for
showing where error occurred. In case it is not
available it falls back to |string()|.
msgpackparse({list}) {Nvim} *msgpackparse()*
Convert a |readfile()|-style list to a list of VimL objects.
Example: >

View File

@ -12744,32 +12744,9 @@ static int conv_error(const char *const msg, const MPConvStack *const mpstack,
ga_concat(&msg_ga, IObuff);
} else {
typval_T key_tv = li->li_tv.vval.v_list->lv_first->li_tv;
trylevel++;
typval_T rettv;
int doesrange;
char *key;
bool free_key = false;
if (call_func((char_u *) "msgpack#string",
sizeof("msgpack#string") - 1,
&rettv, 1, &key_tv, 0L, 0L, &doesrange, true,
NULL) == FAIL
|| ((key = (char *) get_tv_string(&rettv)) == NULL)
|| did_throw
|| (msg_list != NULL && *msg_list != NULL)) {
key = tv2string(&key_tv, NULL);
free_key = true;
}
did_emsg = false;
discard_current_exception();
if (msg_list != NULL && *msg_list != NULL) {
free_global_msglist();
}
trylevel--;
char *const key = echo_string(&key_tv, NULL);
vim_snprintf((char *) IObuff, IOSIZE, key_pair_msg, key, idx);
clear_tv(&rettv);
if (free_key) {
xfree(key);
}
ga_concat(&msg_ga, IObuff);
}
break;

View File

@ -601,7 +601,7 @@ describe('msgpackdump() function', function()
it('fails to dump a recursive (key) map in a special dict, _VAL reference', function()
execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[[], []]]}')
execute('call add(todump._VAL[0][0], todump._VAL)')
eq('Vim(call):E952: Unable to dump msgpackdump() argument, index 0: container references itself in key [[[{E724@0}, []]]] at index 0 from special map, index 0',
eq('Vim(call):E952: Unable to dump msgpackdump() argument, index 0: container references itself in key [[[[...@0], []]]] at index 0 from special map, index 0',
exc_exec('call msgpackdump([todump])'))
end)

View File

@ -697,27 +697,3 @@ describe('In autoload/msgpack.vim', function()
end)
end)
end)
describe('msgpackdump() function', function()
before_each(reset)
it('uses msgpack#string for dumping fref error messages for special map keys', function()
nvim_command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[{"_TYPE": v:msgpack_types.string, "_VAL": ["abc"]}, [function("tr")]]]}')
eq('Vim(call):E951: Error while dumping msgpackdump() argument, index 0, key ="abc" at index 0 from special map, index 0: attempt to dump function reference',
exc_exec('call msgpackdump([todump])'))
end)
it('falls back to using string() in case of error (fref)', function()
nvim_command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[[function("tr")], []]]}')
nvim_command('call add(todump._VAL[0][0], todump._VAL[0][0])')
eq('Vim(call):E951: Error while dumping msgpackdump() argument, index 0, key [function(\'tr\'), {E724@0}] at index 0 from special map, index 0: attempt to dump function reference',
exc_exec('call msgpackdump([todump])'))
end)
it('falls back to using string() in case of error (recurse)', function()
nvim_command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[[], []]]}')
nvim_command('call add(todump._VAL[0][0], todump._VAL[0][0])')
eq('Vim(call):E952: Unable to dump msgpackdump() argument, index 0: container references itself in key [{E724@0}] at index 0 from special map, index 0',
exc_exec('call msgpackdump([todump])'))
end)
end)