Merge remote-tracking branch 'vim/master'

This commit is contained in:
ichizok
2020-11-19 04:34:56 +09:00
21 changed files with 293 additions and 128 deletions
+1
View File
@@ -1305,6 +1305,7 @@ au BufNewFile,BufRead *.pml setf promela
" Google protocol buffers
au BufNewFile,BufRead *.proto setf proto
au BufNewFile,BufRead *.pbtxt setf pbtxt
" Protocols
au BufNewFile,BufRead */etc/protocols setf protocols
+11 -68
View File
@@ -161,7 +161,6 @@ static char *null_libintl_bindtextdomain(const char *, const char *);
static int dyn_libintl_init(char *dir);
static void dyn_libintl_end(void);
static wchar_t *oldenv = NULL;
static HINSTANCE hLibintlDLL = 0;
static char *(*dyn_libintl_gettext)(const char *) = null_libintl_gettext;
static char *(*dyn_libintl_textdomain)(const char *) = null_libintl_textdomain;
@@ -205,17 +204,17 @@ dyn_libintl_init(char *dir)
if (buf != NULL && buf2 != NULL)
{
GetEnvironmentVariableW(L"PATH", buf, len);
#ifdef _WIN64
# ifdef _WIN64
_snwprintf(buf2, len2, L"%S\\GvimExt64;%s", dir, buf);
#else
# else
_snwprintf(buf2, len2, L"%S\\GvimExt32;%s", dir, buf);
#endif
# endif
SetEnvironmentVariableW(L"PATH", buf2);
hLibintlDLL = LoadLibrary(GETTEXT_DLL);
#ifdef GETTEXT_DLL_ALT
# ifdef GETTEXT_DLL_ALT
if (!hLibintlDLL)
hLibintlDLL = LoadLibrary(GETTEXT_DLL_ALT);
#endif
# endif
SetEnvironmentVariableW(L"PATH", buf);
}
free(buf);
@@ -273,56 +272,7 @@ null_libintl_textdomain(const char* /* domainname */)
dyn_gettext_load(void)
{
char szBuff[BUFSIZE];
char szLang[BUFSIZE];
DWORD len;
HKEY keyhandle;
int gotlang = 0;
strcpy(szLang, "LANG=");
// First try getting the language from the registry, this can be
// used to overrule the system language.
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0,
KEY_READ, &keyhandle) == ERROR_SUCCESS)
{
len = BUFSIZE;
if (RegQueryValueEx(keyhandle, "lang", 0, NULL, (BYTE*)szBuff, &len)
== ERROR_SUCCESS)
{
szBuff[len] = 0;
strcat(szLang, szBuff);
gotlang = 1;
}
RegCloseKey(keyhandle);
}
if (!gotlang && getenv("LANG") == NULL)
{
// Get the language from the system.
// Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
// LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
// only the first two.
len = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
(LPTSTR)szBuff, BUFSIZE);
if (len >= 2 && _strnicmp(szBuff, "en", 2) != 0)
{
// There are a few exceptions (probably more)
if (_strnicmp(szBuff, "cht", 3) == 0
|| _strnicmp(szBuff, "zht", 3) == 0)
strcpy(szBuff, "zh_TW");
else if (_strnicmp(szBuff, "chs", 3) == 0
|| _strnicmp(szBuff, "zhc", 3) == 0)
strcpy(szBuff, "zh_CN");
else if (_strnicmp(szBuff, "jp", 2) == 0)
strcpy(szBuff, "ja");
else
szBuff[2] = 0; // truncate to two-letter code
strcat(szLang, szBuff);
gotlang = 1;
}
}
if (gotlang)
putenv(szLang);
// Try to locate the runtime files. The path is used to find libintl.dll
// and the vim.mo files.
@@ -378,10 +328,8 @@ DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /* lpReserved */)
inc_cRefThisDLL()
{
#ifdef FEAT_GETTEXT
if (g_cRefThisDll == 0) {
if (g_cRefThisDll == 0)
dyn_gettext_load();
oldenv = GetEnvironmentStringsW();
}
#endif
InterlockedIncrement((LPLONG)&g_cRefThisDll);
}
@@ -390,13 +338,8 @@ inc_cRefThisDLL()
dec_cRefThisDLL()
{
#ifdef FEAT_GETTEXT
if (InterlockedDecrement((LPLONG)&g_cRefThisDll) == 0) {
if (InterlockedDecrement((LPLONG)&g_cRefThisDll) == 0)
dyn_gettext_free();
if (oldenv != NULL) {
FreeEnvironmentStringsW(oldenv);
oldenv = NULL;
}
}
#else
InterlockedDecrement((LPLONG)&g_cRefThisDll);
#endif
@@ -967,8 +910,8 @@ STDMETHODIMP CShellExt::InvokeGvim(HWND hParent,
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
oldenv == NULL ? 0 : CREATE_UNICODE_ENVIRONMENT,
oldenv, // Use unmodified environment block.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi) // Pointer to PROCESS_INFORMATION structure.
@@ -1057,8 +1000,8 @@ STDMETHODIMP CShellExt::InvokeSingleGvim(HWND hParent,
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
oldenv == NULL ? 0 : CREATE_UNICODE_ENVIRONMENT,
oldenv, // Use unmodified environment block.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi) // Pointer to PROCESS_INFORMATION structure.
+4 -2
View File
@@ -2446,16 +2446,18 @@ win_line(
&& conceal_cursor_line(wp)
&& (int)wp->w_virtcol <= vcol + n_skip)
{
# ifdef FEAT_RIGHTLEFT
# ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
wp->w_wcol = wp->w_width - col + boguscols - 1;
else
# endif
# endif
wp->w_wcol = col - boguscols;
wp->w_wrow = row;
did_wcol = TRUE;
curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
# ifdef FEAT_PROP_POPUP
curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
# endif
}
#endif
+2
View File
@@ -301,3 +301,5 @@ EXTERN char e_cmd_mapping_must_end_with_cr_before_second_cmd[]
INIT(=N_("E1136: <Cmd> mapping must end with <CR> before second <Cmd>"));
EXTERN char e_cmd_maping_must_not_include_str_key[]
INIT(= N_("E1137: <Cmd> mapping must not include %s key"));
EXTERN char e_using_bool_as_number[]
INIT(= N_("E1138: Using a Bool as a Number"));
+1 -5
View File
@@ -3704,11 +3704,7 @@ getcmdkeycmd(
else if (IS_SPECIAL(c1))
{
if (c1 == K_SNR)
{
ga_append(&line_ga, (char)K_SPECIAL);
ga_append(&line_ga, (char)KS_EXTRA);
ga_append(&line_ga, (char)KE_SNR);
}
ga_concat(&line_ga, (char_u *)"<SNR>");
else
{
semsg(e_cmd_maping_must_not_include_str_key,
+6 -3
View File
@@ -2134,7 +2134,10 @@ gui_mch_wait_for_chars(int wtime)
break;
}
else if (input_available()
|| MsgWaitForMultipleObjects(0, NULL, FALSE, 100,
// TODO: The 10 msec is a compromise between laggy response
// and consuming more CPU time. Better would be to handle
// channel messages when they arrive.
|| MsgWaitForMultipleObjects(0, NULL, FALSE, 10,
QS_ALLINPUT) != WAIT_TIMEOUT)
break;
}
@@ -8458,7 +8461,7 @@ make_tooltip(BalloonEval *beval, char *text, POINT pt)
TOOLINFOW *pti;
int ToolInfoSize;
if (multiline_balloon_available() == TRUE)
if (multiline_balloon_available())
ToolInfoSize = sizeof(TOOLINFOW_NEW);
else
ToolInfoSize = sizeof(TOOLINFOW);
@@ -8481,7 +8484,7 @@ make_tooltip(BalloonEval *beval, char *text, POINT pt)
pti->hinst = 0; // Don't use string resources
pti->uId = ID_BEVAL_TOOLTIP;
if (multiline_balloon_available() == TRUE)
if (multiline_balloon_available())
{
RECT rect;
TOOLINFOW_NEW *ptin = (TOOLINFOW_NEW *)pti;
+4 -3
View File
@@ -3465,8 +3465,9 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
if ((redo_yank || oap->op_type != OP_YANK)
&& ((!VIsual_active || oap->motion_force)
// Also redo Operator-pending Visual mode mappings
|| (VIsual_active && cap->cmdchar == ':'
&& oap->op_type != OP_COLON))
|| (VIsual_active
&& (cap->cmdchar == ':' || cap->cmdchar == K_COMMAND)
&& oap->op_type != OP_COLON))
&& cap->cmdchar != 'D'
#ifdef FEAT_FOLDING
&& oap->op_type != OP_FOLD
@@ -3688,7 +3689,7 @@ do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
get_op_char(oap->op_type),
get_extra_op_char(oap->op_type),
oap->motion_force, cap->cmdchar, cap->nchar);
else if (cap->cmdchar != ':')
else if (cap->cmdchar != ':' && cap->cmdchar != K_COMMAND)
{
int nchar = oap->op_type == OP_REPLACE ? cap->nchar : NUL;
+4
View File
@@ -14,6 +14,10 @@ ufunc_T *find_func(char_u *name, int is_global, cctx_T *cctx);
int func_is_global(ufunc_T *ufunc);
int func_name_refcount(char_u *name);
void copy_func(char_u *lambda, char_u *global);
int funcdepth_increment(void);
void funcdepth_decrement(void);
int funcdepth_get(void);
void funcdepth_restore(int depth);
int call_user_func_check(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, funcexe_T *funcexe, dict_T *selfdict);
void save_funccal(funccal_entry_T *entry);
void restore_funccal(void);
+24 -14
View File
@@ -3869,9 +3869,14 @@ syn_cmd_list(
msg_puts(_("no syncing"));
else
{
msg_puts(_("syncing starts "));
msg_outnum(curwin->w_s->b_syn_sync_minlines);
msg_puts(_(" lines before top line"));
if (curwin->w_s->b_syn_sync_minlines == MAXLNUM)
msg_puts(_("syncing starts at the first line"));
else
{
msg_puts(_("syncing starts "));
msg_outnum(curwin->w_s->b_syn_sync_minlines);
msg_puts(_(" lines before top line"));
}
syn_match_msg();
}
return;
@@ -3935,19 +3940,24 @@ syn_lines_msg(void)
|| curwin->w_s->b_syn_sync_minlines > 0)
{
msg_puts("; ");
if (curwin->w_s->b_syn_sync_minlines > 0)
if (curwin->w_s->b_syn_sync_minlines == MAXLNUM)
msg_puts(_("from the first line"));
else
{
msg_puts(_("minimal "));
msg_outnum(curwin->w_s->b_syn_sync_minlines);
if (curwin->w_s->b_syn_sync_maxlines)
msg_puts(", ");
if (curwin->w_s->b_syn_sync_minlines > 0)
{
msg_puts(_("minimal "));
msg_outnum(curwin->w_s->b_syn_sync_minlines);
if (curwin->w_s->b_syn_sync_maxlines)
msg_puts(", ");
}
if (curwin->w_s->b_syn_sync_maxlines > 0)
{
msg_puts(_("maximal "));
msg_outnum(curwin->w_s->b_syn_sync_maxlines);
}
msg_puts(_(" lines before top line"));
}
if (curwin->w_s->b_syn_sync_maxlines > 0)
{
msg_puts(_("maximal "));
msg_outnum(curwin->w_s->b_syn_sync_maxlines);
}
msg_puts(_(" lines before top line"));
}
}
+1
View File
@@ -345,6 +345,7 @@ let s:filename_checks = {
\ 'papp': ['file.papp', 'file.pxml', 'file.pxsl'],
\ 'pascal': ['file.pas', 'file.pp', 'file.dpr', 'file.lpr'],
\ 'passwd': ['any/etc/passwd', 'any/etc/passwd-', 'any/etc/passwd.edit', 'any/etc/shadow', 'any/etc/shadow-', 'any/etc/shadow.edit', 'any/var/backups/passwd.bak', 'any/var/backups/shadow.bak', '/etc/passwd', '/etc/passwd-', '/etc/passwd.edit', '/etc/shadow', '/etc/shadow-', '/etc/shadow.edit', '/var/backups/passwd.bak', '/var/backups/shadow.bak'],
\ 'pbtxt': ['file.pbtxt'],
\ 'pccts': ['file.g'],
\ 'pdf': ['file.pdf'],
\ 'perl': ['file.plx', 'file.al', 'file.psgi', 'gitolite.rc', '.gitolite.rc', 'example.gitolite.rc'],
+36
View File
@@ -1324,4 +1324,40 @@ func Test_map_cmdkey_cmdline_mode()
%bw!
endfunc
func Test_map_cmdkey_redo()
func SelectDash()
call search('^---\n\zs', 'bcW')
norm! V
call search('\n\ze---$', 'W')
endfunc
let text =<< trim END
---
aaa
---
bbb
bbb
---
ccc
ccc
ccc
---
END
new Xcmdtext
call setline(1, text)
onoremap <silent> i- <Cmd>call SelectDash()<CR>
call feedkeys('2Gdi-', 'xt')
call assert_equal(['---', '---'], getline(1, 2))
call feedkeys('j.', 'xt')
call assert_equal(['---', '---', '---'], getline(1, 3))
call feedkeys('j.', 'xt')
call assert_equal(['---', '---', '---', '---'], getline(1, 4))
bwipe!
call delete('Xcmdtext')
delfunc SelectDash
ounmap i-
endfunc
" vim: shiftwidth=2 sts=2 expandtab
+3
View File
@@ -316,6 +316,8 @@ func Test_syntax_arg_skipped()
syn sync ccomment
endif
call assert_notmatch('on C-style comments', execute('syntax sync'))
syn sync fromstart
call assert_match('syncing starts at the first line', execute('syntax sync'))
syn clear
endfunc
@@ -735,6 +737,7 @@ func Test_syntax_foldlevel()
redir END
call assert_equal("\nsyntax foldlevel start", @c)
syn sync fromstart
call assert_match('from the first line$', execute('syn sync'))
let a = map(range(3,9), 'foldclosed(v:val)')
call assert_equal([3,3,3,3,3,3,3], a) " attached cascade folds together
let a = map(range(10,15), 'foldclosed(v:val)')
+1 -1
View File
@@ -1271,7 +1271,7 @@ func Test_terminal_popup_insert_cmd()
call assert_equal('n', mode())
call feedkeys("\<C-D>", 'xt')
sleep 50m
call WaitFor({-> popup_list() == []})
delfunc StartTermInPopup
iunmap <F3>
endfunc
+6
View File
@@ -749,6 +749,9 @@ def Test_disassemble_const_expr()
enddef
def ReturnInIf(): string
if 1 < 0
return "maybe"
endif
if g:cond
return "yes"
else
@@ -759,6 +762,9 @@ enddef
def Test_disassemble_return_in_if()
var instr = execute('disassemble ReturnInIf')
assert_match('ReturnInIf\_s*' ..
'if 1 < 0\_s*' ..
' return "maybe"\_s*' ..
'endif\_s*' ..
'if g:cond\_s*' ..
'0 LOADG g:cond\_s*' ..
'1 COND2BOOL\_s*' ..
+26 -2
View File
@@ -1292,6 +1292,13 @@ func Test_expr5_fails()
call CheckDefFailure(["var x = 'a' .. 0z32"], 'E1105:', 1)
call CheckDefFailure(["var x = 'a' .. function('len')"], 'E1105:', 1)
call CheckDefFailure(["var x = 'a' .. function('len', ['a'])"], 'E1105:', 1)
call CheckScriptFailure(['vim9script', 'var x = 1 + v:none'], 'E611:', 2)
call CheckScriptFailure(['vim9script', 'var x = 1 + v:null'], 'E611:', 2)
call CheckScriptFailure(['vim9script', 'var x = 1 + v:true'], 'E1138:', 2)
call CheckScriptFailure(['vim9script', 'var x = 1 + v:false'], 'E1138:', 2)
call CheckScriptFailure(['vim9script', 'var x = 1 + true'], 'E1138:', 2)
call CheckScriptFailure(['vim9script', 'var x = 1 + false'], 'E1138:', 2)
endfunc
func Test_expr5_fails_channel()
@@ -2293,12 +2300,29 @@ def Test_expr7_parens_vim9script()
CheckScriptSuccess(lines)
enddef
def Test_expr7_negate()
def Test_expr7_negate_add()
assert_equal(-99, -99)
assert_equal(-99, - 99)
assert_equal(99, --99)
assert_equal(99, -- 99)
assert_equal(99, - - 99)
assert_equal(99, +99)
assert_equal(-99, -+99)
assert_equal(-99, -+ 99)
assert_equal(-99, - +99)
assert_equal(-99, - + 99)
assert_equal(-99, +-99)
assert_equal(-99, + -99)
assert_equal(-99, + - 99)
var nr = 88
assert_equal(-88, -nr)
assert_equal(88, --nr)
assert_equal(-88, - nr)
assert_equal(-88, - +nr)
assert_equal(88, -- nr)
assert_equal(88, + nr)
assert_equal(88, --+ nr)
assert_equal(88, - - nr)
enddef
def Echo(arg: any): string
+39
View File
@@ -49,6 +49,36 @@ def TestCompilingError()
call delete('XTest_compile_error')
enddef
def CallRecursive(n: number): number
return CallRecursive(n + 1)
enddef
def CallMapRecursive(l: list<number>): number
return map(l, {_, v -> CallMapRecursive([v])})[0]
enddef
def Test_funcdepth_error()
set maxfuncdepth=10
var caught = false
try
CallRecursive(1)
catch /E132:/
caught = true
endtry
assert_true(caught)
caught = false
try
CallMapRecursive([1])
catch /E132:/
caught = true
endtry
assert_true(caught)
set maxfuncdepth&
enddef
def ReturnString(): string
return 'string'
enddef
@@ -1426,6 +1456,15 @@ def Test_nested_lambda()
CheckScriptSuccess(lines)
enddef
def Shadowed(): list<number>
var FuncList: list<func: number> = [{ -> 42}]
return FuncList->map({_, Shadowed -> Shadowed()})
enddef
def Test_lambda_arg_shadows_func()
assert_equal([42], Shadowed())
enddef
def Line_continuation_in_def(dir: string = ''): string
var path: string = empty(dir)
\ ? 'empty'
+4 -1
View File
@@ -213,7 +213,10 @@ tv_get_bool_or_number_chk(typval_T *varp, int *denote, int want_bool)
case VAR_SPECIAL:
if (!want_bool && in_vim9script())
{
emsg(_("E611: Using a Special as a Number"));
if (varp->v_type == VAR_BOOL)
emsg(_(e_using_bool_as_number));
else
emsg(_("E611: Using a Special as a Number"));
break;
}
return varp->vval.v_number == VVAL_TRUE ? 1 : 0;
+48 -8
View File
@@ -1373,6 +1373,50 @@ failed:
func_clear_free(fp, TRUE);
}
static int funcdepth = 0;
/*
* Increment the function call depth count.
* Return FAIL when going over 'maxfuncdepth'.
* Otherwise return OK, must call funcdepth_decrement() later!
*/
int
funcdepth_increment(void)
{
if (funcdepth >= p_mfd)
{
emsg(_("E132: Function call depth is higher than 'maxfuncdepth'"));
return FAIL;
}
++funcdepth;
return OK;
}
void
funcdepth_decrement(void)
{
--funcdepth;
}
/*
* Get the current function call depth.
*/
int
funcdepth_get(void)
{
return funcdepth;
}
/*
* Restore the function call depth. This is for cases where there is no
* garantee funcdepth_decrement() can be called exactly the same number of
* times as funcdepth_increment().
*/
void
funcdepth_restore(int depth)
{
funcdepth = depth;
}
/*
* Call a user function.
@@ -1391,7 +1435,6 @@ call_user_func(
funccall_T *fc;
int save_did_emsg;
int default_arg_err = FALSE;
static int depth = 0;
dictitem_T *v;
int fixvar_idx = 0; // index in fixvar[]
int i;
@@ -1406,15 +1449,13 @@ call_user_func(
#endif
ESTACK_CHECK_DECLARATION
// If depth of calling is getting too high, don't execute the function
if (depth >= p_mfd)
// If depth of calling is getting too high, don't execute the function.
if (funcdepth_increment() == FAIL)
{
emsg(_("E132: Function call depth is higher than 'maxfuncdepth'"));
rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = -1;
return;
}
++depth;
line_breakcheck(); // check for CTRL-C hit
@@ -1437,7 +1478,7 @@ call_user_func(
{
// Execute the function, possibly compiling it first.
call_def_function(fp, argcount, argvars, funcexe->partial, rettv);
--depth;
funcdepth_decrement();
current_funccal = fc->caller;
free_funccal(fc);
return;
@@ -1783,8 +1824,7 @@ call_user_func(
}
did_emsg |= save_did_emsg;
--depth;
funcdepth_decrement();
cleanup_function_call(fc);
}
+26
View File
@@ -765,6 +765,32 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2013,
/**/
2012,
/**/
2011,
/**/
2010,
/**/
2009,
/**/
2008,
/**/
2007,
/**/
2006,
/**/
2005,
/**/
2004,
/**/
2003,
/**/
2002,
/**/
2001,
/**/
2000,
/**/
+31 -21
View File
@@ -2626,7 +2626,7 @@ compile_call(
char_u fname_buf[FLEN_FIXED + 1];
char_u *tofree = NULL;
int error = FCERR_NONE;
ufunc_T *ufunc;
ufunc_T *ufunc = NULL;
int res = FAIL;
int is_autoload;
@@ -2712,13 +2712,19 @@ compile_call(
goto theend;
}
// If we can find the function by name generate the right call.
// Skip global functions here, a local funcref takes precedence.
ufunc = find_func(name, FALSE, cctx);
if (ufunc != NULL && !func_is_global(ufunc))
// An argument or local variable can be a function reference, this
// overrules a function name.
if (lookup_local(namebuf, varlen, cctx) == NULL
&& arg_exists(namebuf, varlen, NULL, NULL, NULL, cctx) != OK)
{
res = generate_CALL(cctx, ufunc, argcount);
goto theend;
// If we can find the function by name generate the right call.
// Skip global functions here, a local funcref takes precedence.
ufunc = find_func(name, FALSE, cctx);
if (ufunc != NULL && !func_is_global(ufunc))
{
res = generate_CALL(cctx, ufunc, argcount);
goto theend;
}
}
// If the name is a variable, load it and use PCALL.
@@ -3356,6 +3362,8 @@ compile_leader(cctx_T *cctx, int numeric_only, char_u *start, char_u **end)
while (p > start)
{
--p;
while (VIM_ISWHITE(*p))
--p;
if (*p == '-' || *p == '+')
{
int negate = *p == '-';
@@ -4688,21 +4696,24 @@ compile_return(char_u *arg, int set_return_type, cctx_T *cctx)
if (compile_expr0(&p, cctx) == FAIL)
return NULL;
stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
if (set_return_type)
cctx->ctx_ufunc->uf_ret_type = stack_type;
else
if (cctx->ctx_skip != SKIP_YES)
{
if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID
&& stack_type->tt_type != VAR_VOID
&& stack_type->tt_type != VAR_UNKNOWN)
stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
if (set_return_type)
cctx->ctx_ufunc->uf_ret_type = stack_type;
else
{
emsg(_(e_returning_value_in_function_without_return_type));
return NULL;
}
if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1,
if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID
&& stack_type->tt_type != VAR_VOID
&& stack_type->tt_type != VAR_UNKNOWN)
{
emsg(_(e_returning_value_in_function_without_return_type));
return NULL;
}
if (need_type(stack_type, cctx->ctx_ufunc->uf_ret_type, -1,
cctx, FALSE, FALSE) == FAIL)
return NULL;
return NULL;
}
}
}
else
@@ -4719,8 +4730,7 @@ compile_return(char_u *arg, int set_return_type, cctx_T *cctx)
// No argument, return zero.
generate_PUSHNR(cctx, 0);
}
if (generate_instr(cctx, ISN_RETURN) == NULL)
if (cctx->ctx_skip != SKIP_YES && generate_instr(cctx, ISN_RETURN) == NULL)
return NULL;
// "return val | endif" is possible
+15
View File
@@ -227,6 +227,10 @@ call_dfunc(int cdf_idx, int argcount_arg, ectx_T *ectx)
== FAIL)
return FAIL;
// If depth of calling is getting too high, don't execute the function.
if (funcdepth_increment() == FAIL)
return FAIL;
// Move the vararg-list to below the missing optional arguments.
if (vararg_count > 0 && arg_to_add > 0)
*STACK_TV_BOT(arg_to_add - 1) = *STACK_TV_BOT(-1);
@@ -503,6 +507,7 @@ func_return(ectx_T *ectx)
ectx->ec_stack.ga_len = top + 1;
*STACK_TV_BOT(-1) = *STACK_TV(idx);
funcdepth_decrement();
return OK;
}
@@ -835,6 +840,7 @@ call_def_function(
cmdmod_T save_cmdmod;
int restore_cmdmod = FALSE;
int trylevel_at_start = trylevel;
int orig_funcdepth;
// Get pointer to item in the stack.
#define STACK_TV(idx) (((typval_T *)ectx.ec_stack.ga_data) + idx)
@@ -870,11 +876,19 @@ call_def_function(
}
}
// If depth of calling is getting too high, don't execute the function.
orig_funcdepth = funcdepth_get();
if (funcdepth_increment() == FAIL)
return FAIL;
CLEAR_FIELD(ectx);
ectx.ec_dfunc_idx = ufunc->uf_dfunc_idx;
ga_init2(&ectx.ec_stack, sizeof(typval_T), 500);
if (ga_grow(&ectx.ec_stack, 20) == FAIL)
{
funcdepth_decrement();
return FAIL;
}
ga_init2(&ectx.ec_trystack, sizeof(trycmd_T), 10);
ga_init2(&ectx.ec_funcrefs, sizeof(partial_T *), 10);
@@ -2941,6 +2955,7 @@ failed_early:
if (ret != OK && did_emsg == did_emsg_before)
semsg(_(e_unknown_error_while_executing_str),
printable_func_name(ufunc));
funcdepth_restore(orig_funcdepth);
return ret;
}