vim-patch: finish port of 8.0.0{654,663,667}

Fix ex_function so that :endfunction passes the test.
Remove variables, added in 60c0252672.
This commit is contained in:
Jan Edmund Lazo 2018-07-07 08:16:07 -04:00
parent b5c0031d4e
commit 0ac67853b9
2 changed files with 36 additions and 28 deletions

View File

@ -19584,6 +19584,7 @@ static const char *find_option_end(const char **const arg, int *const opt_flags)
void ex_function(exarg_T *eap) void ex_function(exarg_T *eap)
{ {
char_u *theline; char_u *theline;
char_u *line_to_free = NULL;
int c; int c;
int saved_did_emsg; int saved_did_emsg;
int saved_wait_return = need_wait_return; int saved_wait_return = need_wait_return;
@ -19815,7 +19816,6 @@ void ex_function(exarg_T *eap)
/* When there is a line break use what follows for the function body. /* When there is a line break use what follows for the function body.
* Makes 'exe "func Test()\n...\nendfunc"' work. */ * Makes 'exe "func Test()\n...\nendfunc"' work. */
const char *const end = (const char *)p + STRLEN(p);
if (*p == '\n') { if (*p == '\n') {
line_arg = p + 1; line_arg = p + 1;
} else if (*p != NUL && *p != '"' && !eap->skip && !did_emsg) { } else if (*p != NUL && *p != '"' && !eap->skip && !did_emsg) {
@ -19865,12 +19865,18 @@ void ex_function(exarg_T *eap)
*p = NUL; *p = NUL;
line_arg = p + 1; line_arg = p + 1;
} }
} else if (eap->getline == NULL) } else {
theline = getcmdline(':', 0L, indent); xfree(line_to_free);
else if (eap->getline == NULL) {
theline = eap->getline(':', eap->cookie, indent); theline = getcmdline(':', 0L, indent);
if (KeyTyped) } else {
theline = eap->getline(':', eap->cookie, indent);
}
line_to_free = theline;
}
if (KeyTyped) {
lines_left = Rows - 1; lines_left = Rows - 1;
}
if (theline == NULL) { if (theline == NULL) {
EMSG(_("E126: Missing :endfunction")); EMSG(_("E126: Missing :endfunction"));
goto erret; goto erret;
@ -19902,25 +19908,24 @@ void ex_function(exarg_T *eap)
if (*p == '!') { if (*p == '!') {
p++; p++;
} }
const char *const comment_start = strchr((const char *)p, '"'); char_u *nextcmd = NULL;
const char *const endfunc_end = (comment_start
? strchr(comment_start, '\n')
: strpbrk((const char *)p, "\n|"));
p = (endfunc_end
? (char_u *)endfunc_end
: p + STRLEN(p));
if (*p == '|') { if (*p == '|') {
emsgf(_(e_trailing2), p); nextcmd = p + 1;
if (line_arg == NULL) { } else if (line_arg != NULL && *skipwhite(line_arg) != NUL) {
xfree(theline); nextcmd = line_arg;
} } else if (*p != NUL && *p != '"' && p_verbose > 0) {
goto erret; give_warning2((char_u *)_("W22: Text found after :endfunction: %s"),
p, true);
} }
if (line_arg == NULL) { if (nextcmd != NULL) {
xfree(theline); // Another command follows. If the line came from "eap" we
} else { // can simply point into it, otherwise we need to change
if ((const char *)p < end) { // "eap->cmdlinep".
eap->nextcmd = p + 1; eap->nextcmd = nextcmd;
if (line_to_free != NULL) {
xfree(*eap->cmdlinep);
*eap->cmdlinep = line_to_free;
line_to_free = NULL;
} }
} }
break; break;
@ -19997,11 +20002,7 @@ void ex_function(exarg_T *eap)
* allocates 250 bytes per line, this saves 80% on average. The cost * allocates 250 bytes per line, this saves 80% on average. The cost
* is an extra alloc/free. */ * is an extra alloc/free. */
p = vim_strsave(theline); p = vim_strsave(theline);
if (line_arg == NULL) ((char_u **)(newlines.ga_data))[newlines.ga_len++] = p;
xfree(theline);
theline = p;
((char_u **)(newlines.ga_data))[newlines.ga_len++] = theline;
/* Add NULL lines for continuation lines, so that the line count is /* Add NULL lines for continuation lines, so that the line count is
* equal to the index in the growarray. */ * equal to the index in the growarray. */
@ -20166,6 +20167,7 @@ errret_2:
ga_clear_strings(&newlines); ga_clear_strings(&newlines);
ret_free: ret_free:
xfree(skip_until); xfree(skip_until);
xfree(line_to_free);
xfree(fudi.fd_newkey); xfree(fudi.fd_newkey);
xfree(name); xfree(name);
did_emsg |= saved_did_emsg; did_emsg |= saved_did_emsg;

View File

@ -2763,6 +2763,12 @@ void give_warning(char_u *message, bool hl) FUNC_ATTR_NONNULL_ARG(1)
--no_wait_return; --no_wait_return;
} }
void give_warning2(char_u *const message, char_u *const a1, bool hl)
{
vim_snprintf((char *)IObuff, IOSIZE, (char *)message, a1);
give_warning(IObuff, hl);
}
/* /*
* Advance msg cursor to column "col". * Advance msg cursor to column "col".
*/ */