Mercurial > vim
comparison src/eval.c @ 17606:ff097edaae89 v8.1.1800
patch 8.1.1800: function call functions have too many arguments
commit https://github.com/vim/vim/commit/c6538bcc1cdd1fb83732f22fdc69bd9bb66f968a
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 3 18:17:11 2019 +0200
patch 8.1.1800: function call functions have too many arguments
Problem: Function call functions have too many arguments.
Solution: Pass values in a funcexe_T struct.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 03 Aug 2019 18:30:07 +0200 |
parents | e00d12c085a5 |
children | e259d11e2900 |
comparison
equal
deleted
inserted
replaced
17605:bb1b495f4e05 | 17606:ff097edaae89 |
---|---|
763 | 763 |
764 int | 764 int |
765 eval_expr_typval(typval_T *expr, typval_T *argv, int argc, typval_T *rettv) | 765 eval_expr_typval(typval_T *expr, typval_T *argv, int argc, typval_T *rettv) |
766 { | 766 { |
767 char_u *s; | 767 char_u *s; |
768 int dummy; | |
769 char_u buf[NUMBUFLEN]; | 768 char_u buf[NUMBUFLEN]; |
769 funcexe_T funcexe; | |
770 | 770 |
771 if (expr->v_type == VAR_FUNC) | 771 if (expr->v_type == VAR_FUNC) |
772 { | 772 { |
773 s = expr->vval.v_string; | 773 s = expr->vval.v_string; |
774 if (s == NULL || *s == NUL) | 774 if (s == NULL || *s == NUL) |
775 return FAIL; | 775 return FAIL; |
776 if (call_func(s, -1, rettv, argc, argv, NULL, | 776 vim_memset(&funcexe, 0, sizeof(funcexe)); |
777 0L, 0L, &dummy, TRUE, NULL, NULL) == FAIL) | 777 funcexe.evaluate = TRUE; |
778 if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) | |
778 return FAIL; | 779 return FAIL; |
779 } | 780 } |
780 else if (expr->v_type == VAR_PARTIAL) | 781 else if (expr->v_type == VAR_PARTIAL) |
781 { | 782 { |
782 partial_T *partial = expr->vval.v_partial; | 783 partial_T *partial = expr->vval.v_partial; |
783 | 784 |
784 s = partial_name(partial); | 785 s = partial_name(partial); |
785 if (s == NULL || *s == NUL) | 786 if (s == NULL || *s == NUL) |
786 return FAIL; | 787 return FAIL; |
787 if (call_func(s, -1, rettv, argc, argv, NULL, | 788 vim_memset(&funcexe, 0, sizeof(funcexe)); |
788 0L, 0L, &dummy, TRUE, partial, NULL) == FAIL) | 789 funcexe.evaluate = TRUE; |
790 funcexe.partial = partial; | |
791 if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL) | |
789 return FAIL; | 792 return FAIL; |
790 } | 793 } |
791 else | 794 else |
792 { | 795 { |
793 s = tv_get_string_buf_chk(expr, buf); | 796 s = tv_get_string_buf_chk(expr, buf); |
1090 char_u *func, | 1093 char_u *func, |
1091 int argc, | 1094 int argc, |
1092 typval_T *argv, | 1095 typval_T *argv, |
1093 typval_T *rettv) | 1096 typval_T *rettv) |
1094 { | 1097 { |
1095 int doesrange; | |
1096 int ret; | 1098 int ret; |
1099 funcexe_T funcexe; | |
1097 | 1100 |
1098 rettv->v_type = VAR_UNKNOWN; /* clear_tv() uses this */ | 1101 rettv->v_type = VAR_UNKNOWN; /* clear_tv() uses this */ |
1099 ret = call_func(func, -1, rettv, argc, argv, NULL, | 1102 vim_memset(&funcexe, 0, sizeof(funcexe)); |
1100 curwin->w_cursor.lnum, curwin->w_cursor.lnum, | 1103 funcexe.firstline = curwin->w_cursor.lnum; |
1101 &doesrange, TRUE, NULL, NULL); | 1104 funcexe.lastline = curwin->w_cursor.lnum; |
1105 funcexe.evaluate = TRUE; | |
1106 ret = call_func(func, -1, rettv, argc, argv, &funcexe); | |
1102 if (ret == FAIL) | 1107 if (ret == FAIL) |
1103 clear_tv(rettv); | 1108 clear_tv(rettv); |
1104 | 1109 |
1105 return ret; | 1110 return ret; |
1106 } | 1111 } |
4679 * the name invalid. */ | 4684 * the name invalid. */ |
4680 s = vim_strsave(s); | 4685 s = vim_strsave(s); |
4681 if (s == NULL) | 4686 if (s == NULL) |
4682 ret = FAIL; | 4687 ret = FAIL; |
4683 else | 4688 else |
4684 /* Invoke the function. */ | 4689 { |
4685 ret = get_func_tv(s, len, rettv, arg, | 4690 funcexe_T funcexe; |
4686 curwin->w_cursor.lnum, curwin->w_cursor.lnum, | 4691 |
4687 &len, evaluate, partial, NULL); | 4692 // Invoke the function. |
4693 funcexe.argv_func = NULL; | |
4694 funcexe.firstline = curwin->w_cursor.lnum; | |
4695 funcexe.lastline = curwin->w_cursor.lnum; | |
4696 funcexe.doesrange = &len; | |
4697 funcexe.evaluate = evaluate; | |
4698 funcexe.partial = partial; | |
4699 funcexe.selfdict = NULL; | |
4700 ret = get_func_tv(s, len, rettv, arg, &funcexe); | |
4701 } | |
4688 vim_free(s); | 4702 vim_free(s); |
4689 | 4703 |
4690 /* If evaluate is FALSE rettv->v_type was not set in | 4704 /* If evaluate is FALSE rettv->v_type was not set in |
4691 * get_func_tv, but it's needed in handle_subscript() to parse | 4705 * get_func_tv, but it's needed in handle_subscript() to parse |
4692 * what follows. So set it here. */ | 4706 * what follows. So set it here. */ |
7357 int verbose) /* give error messages */ | 7371 int verbose) /* give error messages */ |
7358 { | 7372 { |
7359 int ret = OK; | 7373 int ret = OK; |
7360 dict_T *selfdict = NULL; | 7374 dict_T *selfdict = NULL; |
7361 char_u *s; | 7375 char_u *s; |
7362 int len; | |
7363 typval_T functv; | 7376 typval_T functv; |
7364 | 7377 |
7365 // "." is ".name" lookup when we found a dict or when evaluating and | 7378 // "." is ".name" lookup when we found a dict or when evaluating and |
7366 // scriptversion is at least 2, where string concatenation is "..". | 7379 // scriptversion is at least 2, where string concatenation is "..". |
7367 while (ret == OK | 7380 while (ret == OK |
7375 && !VIM_ISWHITE(*(*arg - 1))) | 7388 && !VIM_ISWHITE(*(*arg - 1))) |
7376 { | 7389 { |
7377 if (**arg == '(') | 7390 if (**arg == '(') |
7378 { | 7391 { |
7379 partial_T *pt = NULL; | 7392 partial_T *pt = NULL; |
7393 funcexe_T funcexe; | |
7380 | 7394 |
7381 /* need to copy the funcref so that we can clear rettv */ | 7395 /* need to copy the funcref so that we can clear rettv */ |
7382 if (evaluate) | 7396 if (evaluate) |
7383 { | 7397 { |
7384 functv = *rettv; | 7398 functv = *rettv; |
7393 else | 7407 else |
7394 s = functv.vval.v_string; | 7408 s = functv.vval.v_string; |
7395 } | 7409 } |
7396 else | 7410 else |
7397 s = (char_u *)""; | 7411 s = (char_u *)""; |
7398 ret = get_func_tv(s, -1, rettv, arg, | 7412 |
7399 curwin->w_cursor.lnum, curwin->w_cursor.lnum, | 7413 funcexe.argv_func = NULL; |
7400 &len, evaluate, pt, selfdict); | 7414 funcexe.firstline = curwin->w_cursor.lnum; |
7415 funcexe.lastline = curwin->w_cursor.lnum; | |
7416 funcexe.doesrange = NULL; | |
7417 funcexe.evaluate = evaluate; | |
7418 funcexe.partial = pt; | |
7419 funcexe.selfdict = selfdict; | |
7420 ret = get_func_tv(s, -1, rettv, arg, &funcexe); | |
7401 | 7421 |
7402 /* Clear the funcref afterwards, so that deleting it while | 7422 /* Clear the funcref afterwards, so that deleting it while |
7403 * evaluating the arguments is possible (see test55). */ | 7423 * evaluating the arguments is possible (see test55). */ |
7404 if (evaluate) | 7424 if (evaluate) |
7405 clear_tv(&functv); | 7425 clear_tv(&functv); |