aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/buffer.c4
-rw-r--r--src/nvim/eval.c13
-rw-r--r--src/nvim/ex_docmd.c20
-rw-r--r--src/nvim/ex_getln.c11
-rw-r--r--src/nvim/fileio.c9
-rw-r--r--src/nvim/globals.h3
-rw-r--r--src/nvim/memline.c25
-rw-r--r--src/nvim/os/env.c2
-rw-r--r--src/nvim/os/fs.c6
-rw-r--r--src/nvim/path.c50
-rw-r--r--src/nvim/quickfix.c4
-rw-r--r--src/nvim/shada.c6
-rw-r--r--src/nvim/syntax.c10
-rw-r--r--test/functional/provider/python3_spec.lua19
-rw-r--r--test/functional/provider/ruby_spec.lua22
-rw-r--r--test/unit/os/fs_spec.lua2
-rw-r--r--test/unit/path_spec.lua22
17 files changed, 122 insertions, 106 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 3958fb05e9..0cd6f628b5 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -2683,7 +2683,7 @@ void buflist_altfpos(win_T *win)
}
/// Check that "ffname" is not the same file as current file.
-/// Fname must have a full path (expanded by path_get_absolute_path()).
+/// Fname must have a full path (expanded by path_to_absolute()).
///
/// @param ffname full path name to check
bool otherfile(char_u *ffname)
@@ -2693,7 +2693,7 @@ bool otherfile(char_u *ffname)
}
/// Check that "ffname" is not the same file as the file loaded in "buf".
-/// Fname must have a full path (expanded by path_get_absolute_path()).
+/// Fname must have a full path (expanded by path_to_absolute()).
///
/// @param buf buffer to check
/// @param ffname full path name to check
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index feccec85c6..0f7a1eb004 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -13496,7 +13496,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, FunPtr fptr)
q[-1] = NUL;
q = (char *)path_tail((char_u *)p);
}
- if (q > p && !path_is_absolute_path((const char_u *)buf)) {
+ if (q > p && !path_is_absolute((const char_u *)buf)) {
// Symlink is relative to directory of argument. Replace the
// symlink with the resolved name in the same directory.
const size_t p_len = strlen(p);
@@ -13814,7 +13814,7 @@ static void f_rpcrequest(typval_T *argvars, typval_T *rettv, FunPtr fptr)
scid_T save_current_SID;
uint8_t *save_sourcing_name, *save_autocmd_fname, *save_autocmd_match;
linenr_T save_sourcing_lnum;
- int save_autocmd_fname_full, save_autocmd_bufnr;
+ int save_autocmd_bufnr;
void *save_funccalp;
if (l_provider_call_nesting) {
@@ -13825,16 +13825,14 @@ static void f_rpcrequest(typval_T *argvars, typval_T *rettv, FunPtr fptr)
save_sourcing_lnum = sourcing_lnum;
save_autocmd_fname = autocmd_fname;
save_autocmd_match = autocmd_match;
- save_autocmd_fname_full = autocmd_fname_full;
save_autocmd_bufnr = autocmd_bufnr;
save_funccalp = save_funccal();
- //
+
current_SID = provider_caller_scope.SID;
sourcing_name = provider_caller_scope.sourcing_name;
sourcing_lnum = provider_caller_scope.sourcing_lnum;
autocmd_fname = provider_caller_scope.autocmd_fname;
autocmd_match = provider_caller_scope.autocmd_match;
- autocmd_fname_full = provider_caller_scope.autocmd_fname_full;
autocmd_bufnr = provider_caller_scope.autocmd_bufnr;
restore_funccal(provider_caller_scope.funccalp);
}
@@ -13850,7 +13848,6 @@ static void f_rpcrequest(typval_T *argvars, typval_T *rettv, FunPtr fptr)
sourcing_lnum = save_sourcing_lnum;
autocmd_fname = save_autocmd_fname;
autocmd_match = save_autocmd_match;
- autocmd_fname_full = save_autocmd_fname_full;
autocmd_bufnr = save_autocmd_bufnr;
restore_funccal(save_funccalp);
}
@@ -22448,7 +22445,6 @@ typval_T eval_call_provider(char *provider, char *method, list_T *arguments)
.sourcing_lnum = sourcing_lnum,
.autocmd_fname = autocmd_fname,
.autocmd_match = autocmd_match,
- .autocmd_fname_full = autocmd_fname_full,
.autocmd_bufnr = autocmd_bufnr,
.funccalp = save_funccal()
};
@@ -22481,7 +22477,8 @@ typval_T eval_call_provider(char *provider, char *method, list_T *arguments)
restore_funccal(provider_caller_scope.funccalp);
provider_caller_scope = saved_provider_caller_scope;
provider_call_nesting--;
-
+ assert(provider_call_nesting >= 0);
+
return rettv;
}
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 95920acddc..99495aaa61 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -8550,22 +8550,22 @@ eval_vars (
resultbuf = result; /* remember allocated string */
break;
- case SPEC_AFILE: /* file name for autocommand */
- result = autocmd_fname;
- if (result != NULL && !autocmd_fname_full) {
- /* Still need to turn the fname into a full path. It is
- * postponed to avoid a delay when <afile> is not used. */
- autocmd_fname_full = TRUE;
- result = (char_u *)FullName_save((char *)autocmd_fname, FALSE);
- xfree(autocmd_fname);
- autocmd_fname = result;
+ case SPEC_AFILE: // file name for autocommand
+ if (autocmd_fname != NULL && !path_is_absolute(autocmd_fname)) {
+ // Still need to turn the fname into a full path. It was
+ // postponed to avoid a delay when <afile> is not used.
+ result = (char_u *)FullName_save((char *)autocmd_fname, false);
+ // Copy into `autocmd_fname`, don't reassign it. #8165
+ xstrlcpy((char *)autocmd_fname, (char *)result, MAXPATHL);
+ xfree(result);
}
+ result = autocmd_fname;
if (result == NULL) {
*errormsg = (char_u *)_(
"E495: no autocommand file name to substitute for \"<afile>\"");
return NULL;
}
- result = path_shorten_fname_if_possible(result);
+ result = path_try_shorten_fname(result);
break;
case SPEC_ABUF: /* buffer number for autocommand */
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index ccd00f2097..698419405a 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -4927,13 +4927,14 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
flags |= EW_FILE | EW_EXEC | EW_SHELLCMD;
bool mustfree = false; // Track memory allocation for *path.
- /* For an absolute name we don't use $PATH. */
- if (path_is_absolute_path(pat))
+ // For an absolute name we don't use $PATH.
+ if (path_is_absolute(pat)) {
path = (char_u *)" ";
- else if ((pat[0] == '.' && (vim_ispathsep(pat[1])
- || (pat[1] == '.' && vim_ispathsep(pat[2])))))
+ } else if (pat[0] == '.' && (vim_ispathsep(pat[1])
+ || (pat[1] == '.'
+ && vim_ispathsep(pat[2])))) {
path = (char_u *)".";
- else {
+ } else {
path = (char_u *)vim_getenv("PATH");
if (path == NULL) {
path = (char_u *)"";
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 91b0a695f1..52686f6651 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -4318,7 +4318,7 @@ void shorten_fnames(int force)
&& !path_with_url((char *)buf->b_fname)
&& (force
|| buf->b_sfname == NULL
- || path_is_absolute_path(buf->b_sfname))) {
+ || path_is_absolute(buf->b_sfname))) {
xfree(buf->b_sfname);
buf->b_sfname = NULL;
p = path_shorten_fname(buf->b_ffname, dirname);
@@ -6655,7 +6655,6 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io,
char_u *save_sourcing_name;
linenr_T save_sourcing_lnum;
char_u *save_autocmd_fname;
- int save_autocmd_fname_full;
int save_autocmd_bufnr;
char_u *save_autocmd_match;
int save_autocmd_busy;
@@ -6728,7 +6727,6 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io,
* Save the autocmd_* variables and info about the current buffer.
*/
save_autocmd_fname = autocmd_fname;
- save_autocmd_fname_full = autocmd_fname_full;
save_autocmd_bufnr = autocmd_bufnr;
save_autocmd_match = autocmd_match;
save_autocmd_busy = autocmd_busy;
@@ -6755,9 +6753,9 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io,
autocmd_fname = fname_io;
}
if (autocmd_fname != NULL) {
- autocmd_fname = vim_strsave(autocmd_fname);
+ // Allocate MAXPATHL for when eval_vars() resolves the fullpath.
+ autocmd_fname = vim_strnsave(autocmd_fname, MAXPATHL);
}
- autocmd_fname_full = false; // call FullName_save() later
/*
* Set the buffer number to be used for <abuf>.
@@ -6924,7 +6922,6 @@ static bool apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io,
sourcing_lnum = save_sourcing_lnum;
xfree(autocmd_fname);
autocmd_fname = save_autocmd_fname;
- autocmd_fname_full = save_autocmd_fname_full;
autocmd_bufnr = save_autocmd_bufnr;
autocmd_match = save_autocmd_match;
current_SID = save_current_SID;
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 4723a1e6b6..e857f5ff5b 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -416,7 +416,7 @@ EXTERN struct caller_scope {
scid_T SID;
uint8_t *sourcing_name, *autocmd_fname, *autocmd_match;
linenr_T sourcing_lnum;
- int autocmd_fname_full, autocmd_bufnr;
+ int autocmd_bufnr;
void *funccalp;
} provider_caller_scope;
EXTERN int provider_call_nesting INIT(= 0);
@@ -872,7 +872,6 @@ EXTERN char_u *last_cmdline INIT(= NULL); // last command line (for ":)
EXTERN char_u *repeat_cmdline INIT(= NULL); // command line for "."
EXTERN char_u *new_last_cmdline INIT(= NULL); // new value for last_cmdline
EXTERN char_u *autocmd_fname INIT(= NULL); // fname for <afile> on cmdline
-EXTERN int autocmd_fname_full; // autocmd_fname is full path
EXTERN int autocmd_bufnr INIT(= 0); // fnum for <abuf> on cmdline
EXTERN char_u *autocmd_match INIT(= NULL); // name for <amatch> on cmdline
EXTERN int did_cursorhold INIT(= false); // set when CursorHold t'gerd
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index c594782a1c..c11ca74f5c 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -1330,7 +1330,7 @@ recover_names (
names[2] = (char_u *)concat_fnames((char *)dir_name, ".sw?", TRUE);
num_names = 3;
} else {
- int len = STRLEN(dir_name);
+ int len = (int)STRLEN(dir_name);
p = dir_name + len;
if (after_pathsep((char *)dir_name, (char *)p)
&& len > 1
@@ -3020,20 +3020,17 @@ int resolve_symlink(const char_u *fname, char_u *buf)
}
buf[ret] = NUL;
- /*
- * Check whether the symlink is relative or absolute.
- * If it's relative, build a new path based on the directory
- * portion of the filename (if any) and the path the symlink
- * points to.
- */
- if (path_is_absolute_path(buf))
+ // Check whether the symlink is relative or absolute.
+ // If it's relative, build a new path based on the directory
+ // portion of the filename (if any) and the path the symlink
+ // points to.
+ if (path_is_absolute(buf)) {
STRCPY(tmp, buf);
- else {
- char_u *tail;
-
- tail = path_tail(tmp);
- if (STRLEN(tail) + STRLEN(buf) >= MAXPATHL)
+ } else {
+ char_u *tail = path_tail(tmp);
+ if (STRLEN(tail) + STRLEN(buf) >= MAXPATHL) {
return FAIL;
+ }
STRCPY(tail, buf);
}
}
@@ -3058,7 +3055,7 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf, char_u *dir_name
#ifdef HAVE_READLINK
char_u fname_buf[MAXPATHL];
#endif
- int len = STRLEN(dir_name);
+ int len = (int)STRLEN(dir_name);
s = dir_name + len;
if (after_pathsep((char *)dir_name, (char *)s)
diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c
index 999fcd434a..3fcb9415c7 100644
--- a/src/nvim/os/env.c
+++ b/src/nvim/os/env.c
@@ -886,7 +886,7 @@ bool os_setenv_append_path(const char *fname)
// No prescribed maximum on unix.
# define MAX_ENVPATHLEN INT_MAX
#endif
- if (!path_is_absolute_path((char_u *)fname)) {
+ if (!path_is_absolute((char_u *)fname)) {
internal_error("os_setenv_append_path()");
return false;
}
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index c0a97aeb34..b7c2714296 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -222,7 +222,7 @@ int os_exepath(char *buffer, size_t *size)
bool os_can_exe(const char_u *name, char_u **abspath, bool use_path)
FUNC_ATTR_NONNULL_ARG(1)
{
- bool no_path = !use_path || path_is_absolute_path(name);
+ bool no_path = !use_path || path_is_absolute(name);
#ifndef WIN32
// If the filename is "qualified" (relative or absolute) do not check $PATH.
no_path |= (name[0] == '.'
@@ -244,7 +244,7 @@ bool os_can_exe(const char_u *name, char_u **abspath, bool use_path)
#endif
if (ok) {
if (abspath != NULL) {
- *abspath = save_absolute_path(name);
+ *abspath = save_abs_path(name);
}
return true;
}
@@ -357,7 +357,7 @@ static bool is_executable_in_path(const char_u *name, char_u **abspath)
#endif
if (ok) {
if (abspath != NULL) { // Caller asked for a copy of the path.
- *abspath = save_absolute_path((char_u *)buf);
+ *abspath = save_abs_path((char_u *)buf);
}
rv = true;
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 21ac064c30..168d835a66 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -452,10 +452,10 @@ char *FullName_save(const char *fname, bool force)
/// Saves the absolute path.
/// @param name An absolute or relative path.
/// @return The absolute path of `name`.
-char_u *save_absolute_path(const char_u *name)
+char_u *save_abs_path(const char_u *name)
FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{
- if (!path_is_absolute_path(name)) {
+ if (!path_is_absolute(name)) {
return (char_u *)FullName_save((char *)name, true);
}
return vim_strsave((char_u *) name);
@@ -814,7 +814,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap)
STRCPY(buf, curdir); // relative to current directory
} else if (path_with_url((char *)buf)) {
continue; // URL can't be used here
- } else if (!path_is_absolute_path(buf)) {
+ } else if (!path_is_absolute(buf)) {
// Expand relative path to their full path equivalent
size_t len = STRLEN(curdir);
if (len + STRLEN(buf) + 3 > MAXPATHL) {
@@ -949,19 +949,17 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
}
}
- if (path_is_absolute_path(path)) {
- /*
- * Last resort: shorten relative to curdir if possible.
- * 'possible' means:
- * 1. It is under the current directory.
- * 2. The result is actually shorter than the original.
- *
- * Before curdir After
- * /foo/bar/file.txt /foo/bar ./file.txt
- * c:\foo\bar\file.txt c:\foo\bar .\file.txt
- * /file.txt / /file.txt
- * c:\file.txt c:\ .\file.txt
- */
+ if (path_is_absolute(path)) {
+ // Last resort: shorten relative to curdir if possible.
+ // 'possible' means:
+ // 1. It is under the current directory.
+ // 2. The result is actually shorter than the original.
+ //
+ // Before curdir After
+ // /foo/bar/file.txt /foo/bar ./file.txt
+ // c:\foo\bar\file.txt c:\foo\bar .\file.txt
+ // /file.txt / /file.txt
+ // c:\file.txt c:\ .\file.txt
short_name = path_shorten_fname(path, curdir);
if (short_name != NULL && short_name > path + 1
) {
@@ -1221,7 +1219,7 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file,
*/
if (path_has_exp_wildcard(p)) {
if ((flags & EW_PATH)
- && !path_is_absolute_path(p)
+ && !path_is_absolute(p)
&& !(p[0] == '.'
&& (vim_ispathsep(p[1])
|| (p[1] == '.' && vim_ispathsep(p[2]))))
@@ -1667,7 +1665,7 @@ int path_with_url(const char *fname)
*/
bool vim_isAbsName(char_u *name)
{
- return path_with_url((char *)name) != 0 || path_is_absolute_path(name);
+ return path_with_url((char *)name) != 0 || path_is_absolute(name);
}
/// Save absolute file name to "buf[len]".
@@ -1701,7 +1699,7 @@ int vim_FullName(const char *fname, char *buf, size_t len, bool force)
return OK;
}
- int rv = path_get_absolute_path((char_u *)fname, (char_u *)buf, len, force);
+ int rv = path_to_absolute((char_u *)fname, (char_u *)buf, len, force);
if (rv == FAIL) {
xstrlcpy(buf, fname, len); // something failed; use the filename
}
@@ -1910,7 +1908,7 @@ int pathcmp(const char *p, const char *q, int maxlen)
/// - Pointer into `full_path` if shortened.
/// - `full_path` unchanged if no shorter name is possible.
/// - NULL if `full_path` is NULL.
-char_u *path_shorten_fname_if_possible(char_u *full_path)
+char_u *path_try_shorten_fname(char_u *full_path)
{
char_u *dirname = xmalloc(MAXPATHL);
char_u *p = full_path;
@@ -2191,8 +2189,8 @@ int append_path(char *path, const char *to_append, size_t max_len)
/// @param force also expand when "fname" is already absolute.
///
/// @return FAIL for failure, OK for success.
-static int path_get_absolute_path(const char_u *fname, char_u *buf,
- size_t len, int force)
+static int path_to_absolute(const char_u *fname, char_u *buf, size_t len,
+ int force)
{
char_u *p;
*buf = NUL;
@@ -2201,7 +2199,7 @@ static int path_get_absolute_path(const char_u *fname, char_u *buf,
char *end_of_path = (char *) fname;
// expand it if forced or not an absolute path
- if (force || !path_is_absolute_path(fname)) {
+ if (force || !path_is_absolute(fname)) {
p = vim_strrchr(fname, '/');
#ifdef WIN32
if (p == NULL) {
@@ -2234,10 +2232,10 @@ static int path_get_absolute_path(const char_u *fname, char_u *buf,
return append_path((char *)buf, end_of_path, len);
}
-/// Check if the given file is absolute.
+/// Check if file `fname` is a full (absolute) path.
///
/// @return `TRUE` if "fname" is absolute.
-int path_is_absolute_path(const char_u *fname)
+int path_is_absolute(const char_u *fname)
{
#ifdef WIN32
// A name like "d:/foo" and "//server/share" is absolute
@@ -2262,7 +2260,7 @@ void path_guess_exepath(const char *argv0, char *buf, size_t bufsize)
{
char *path = getenv("PATH");
- if (path == NULL || path_is_absolute_path((char_u *)argv0)) {
+ if (path == NULL || path_is_absolute((char_u *)argv0)) {
xstrlcpy(buf, argv0, bufsize);
} else if (argv0[0] == '.' || strchr(argv0, PATHSEP)) {
// Relative to CWD.
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c
index 1aeadcec4a..2d8c353f92 100644
--- a/src/nvim/quickfix.c
+++ b/src/nvim/quickfix.c
@@ -3649,8 +3649,8 @@ void ex_vimgrep(exarg_T *eap)
cur_qf_start = qi->qf_lists[qi->qf_curlist].qf_start;
seconds = (time_t)0;
- for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) {
- fname = path_shorten_fname_if_possible(fnames[fi]);
+ for (fi = 0; fi < fcount && !got_int && tomatch > 0; fi++) {
+ fname = path_try_shorten_fname(fnames[fi]);
if (time(NULL) > seconds) {
/* Display the file name every second or so, show the user we are
* working on it. */
diff --git a/src/nvim/shada.c b/src/nvim/shada.c
index a1ce00f665..605d9c30a6 100644
--- a/src/nvim/shada.c
+++ b/src/nvim/shada.c
@@ -76,8 +76,8 @@ KHASH_SET_INIT_STR(strset)
(vim_rename((char_u *)a, (char_u *)b))
#define mb_strnicmp(a, b, c) \
(mb_strnicmp((char_u *)a, (char_u *)b, c))
-#define path_shorten_fname_if_possible(b) \
- ((char *)path_shorten_fname_if_possible((char_u *)b))
+#define path_try_shorten_fname(b) \
+ ((char *)path_try_shorten_fname((char_u *)b))
#define buflist_new(ffname, sfname, ...) \
(buflist_new((char_u *)ffname, (char_u *)sfname, __VA_ARGS__))
#define os_isdir(f) (os_isdir((char_u *) f))
@@ -1397,7 +1397,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
}
case kSDItemBufferList: {
for (size_t i = 0; i < cur_entry.data.buffer_list.size; i++) {
- char *const sfname = path_shorten_fname_if_possible(
+ char *const sfname = path_try_shorten_fname(
cur_entry.data.buffer_list.buffers[i].fname);
buf_T *const buf = buflist_new(
cur_entry.data.buffer_list.buffers[i].fname, sfname, 0,
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index b2c28183a6..8ec393e568 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -4239,11 +4239,11 @@ static void syn_cmd_include(exarg_T *eap, int syncing)
*/
eap->argt |= (XFILE | NOSPC);
separate_nextcmd(eap);
- if (*eap->arg == '<' || *eap->arg == '$' || path_is_absolute_path(eap->arg)) {
- /* For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the
- * file. Need to expand the file name first. In other cases
- * ":runtime!" is used. */
- source = TRUE;
+ if (*eap->arg == '<' || *eap->arg == '$' || path_is_absolute(eap->arg)) {
+ // For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the
+ // file. Need to expand the file name first. In other cases
+ // ":runtime!" is used.
+ source = true;
if (expand_filename(eap, syn_cmdlinep, &errormsg) == FAIL) {
if (errormsg != NULL)
EMSG(errormsg);
diff --git a/test/functional/provider/python3_spec.lua b/test/functional/provider/python3_spec.lua
index f06728ec0e..93ac3ae017 100644
--- a/test/functional/provider/python3_spec.lua
+++ b/test/functional/provider/python3_spec.lua
@@ -3,6 +3,7 @@ local eval, command, feed = helpers.eval, helpers.command, helpers.feed
local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert
local expect, write_file = helpers.expect, helpers.write_file
local feed_command = helpers.feed_command
+local source = helpers.source
local missing_provider = helpers.missing_provider
do
@@ -13,7 +14,7 @@ do
end
end
-describe('python3 commands and functions', function()
+describe('python3 provider', function()
before_each(function()
clear()
command('python3 import vim')
@@ -82,4 +83,20 @@ describe('python3 commands and functions', function()
it('py3eval', function()
eq({1, 2, {['key'] = 'val'}}, eval([[py3eval('[1, 2, {"key": "val"}]')]]))
end)
+
+ it('RPC call to expand("<afile>") during BufDelete #5245 #5617', function()
+ source([=[
+ python3 << EOF
+ import vim
+ def foo():
+ vim.eval('expand("<afile>:p")')
+ vim.eval('bufnr(expand("<afile>:p"))')
+ EOF
+ autocmd BufDelete * python3 foo()
+ autocmd BufUnload * python3 foo()]=])
+ feed_command("exe 'split' tempname()")
+ feed_command("bwipeout!")
+ feed_command('help help')
+ eq(2, eval('1+1')) -- Still alive?
+ end)
end)
diff --git a/test/functional/provider/ruby_spec.lua b/test/functional/provider/ruby_spec.lua
index a2c6c6a10e..e049ac7c41 100644
--- a/test/functional/provider/ruby_spec.lua
+++ b/test/functional/provider/ruby_spec.lua
@@ -1,16 +1,18 @@
local helpers = require('test.functional.helpers')(after_each)
+local clear = helpers.clear
+local command = helpers.command
+local curbufmeths = helpers.curbufmeths
local eq = helpers.eq
+local eval = helpers.eval
+local expect = helpers.expect
local feed = helpers.feed
-local clear = helpers.clear
+local feed_command = helpers.feed_command
local funcs = helpers.funcs
-local meths = helpers.meths
local insert = helpers.insert
-local expect = helpers.expect
-local command = helpers.command
-local write_file = helpers.write_file
-local curbufmeths = helpers.curbufmeths
+local meths = helpers.meths
local missing_provider = helpers.missing_provider
+local write_file = helpers.write_file
do
clear()
@@ -90,3 +92,11 @@ describe(':rubydo command', function()
eq(false, curbufmeths.get_option('modified'))
end)
end)
+
+describe('ruby provider', function()
+ it('RPC call to expand("<afile>") during BufDelete #5245 #5617', function()
+ command([=[autocmd BufDelete * ruby VIM::evaluate('expand("<afile>")')]=])
+ feed_command('help help')
+ eq(2, eval('1+1')) -- Still alive?
+ end)
+end)
diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua
index bc39507c08..78455ee324 100644
--- a/test/unit/os/fs_spec.lua
+++ b/test/unit/os/fs_spec.lua
@@ -199,7 +199,7 @@ describe('fs.c', function()
itp('returns the absolute path when given an executable inside $PATH', function()
local fullpath = exe('ls')
- eq(1, fs.path_is_absolute_path(to_cstr(fullpath)))
+ eq(1, fs.path_is_absolute(to_cstr(fullpath)))
end)
itp('returns the absolute path when given an executable relative to the current dir', function()
diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua
index ed597eaed7..e8ce660ce1 100644
--- a/test/unit/path_spec.lua
+++ b/test/unit/path_spec.lua
@@ -261,7 +261,7 @@ describe('path.c', function()
end)
end)
-describe('path_shorten_fname_if_possible', function()
+describe('path_try_shorten_fname', function()
local cwd = lfs.currentdir()
before_each(function()
@@ -273,22 +273,22 @@ describe('path_shorten_fname_if_possible', function()
lfs.rmdir('ut_directory')
end)
- describe('path_shorten_fname_if_possible', function()
+ describe('path_try_shorten_fname', function()
itp('returns shortened path if possible', function()
lfs.chdir('ut_directory')
local full = to_cstr(lfs.currentdir() .. '/subdir/file.txt')
- eq('subdir/file.txt', (ffi.string(cimp.path_shorten_fname_if_possible(full))))
+ eq('subdir/file.txt', (ffi.string(cimp.path_try_shorten_fname(full))))
end)
itp('returns `full_path` if a shorter version is not possible', function()
local old = lfs.currentdir()
lfs.chdir('ut_directory')
local full = old .. '/subdir/file.txt'
- eq(full, (ffi.string(cimp.path_shorten_fname_if_possible(to_cstr(full)))))
+ eq(full, (ffi.string(cimp.path_try_shorten_fname(to_cstr(full)))))
end)
itp('returns NULL if `full_path` is NULL', function()
- eq(NULL, (cimp.path_shorten_fname_if_possible(NULL)))
+ eq(NULL, (cimp.path_try_shorten_fname(NULL)))
end)
end)
end)
@@ -585,22 +585,22 @@ describe('path.c', function()
end)
end)
- describe('path_is_absolute_path', function()
- local function path_is_absolute_path(filename)
+ describe('path_is_absolute', function()
+ local function path_is_absolute(filename)
filename = to_cstr(filename)
- return cimp.path_is_absolute_path(filename)
+ return cimp.path_is_absolute(filename)
end
itp('returns true if filename starts with a slash', function()
- eq(OK, path_is_absolute_path('/some/directory/'))
+ eq(OK, path_is_absolute('/some/directory/'))
end)
itp('returns true if filename starts with a tilde', function()
- eq(OK, path_is_absolute_path('~/in/my/home~/directory'))
+ eq(OK, path_is_absolute('~/in/my/home~/directory'))
end)
itp('returns false if filename starts not with slash nor tilde', function()
- eq(FAIL, path_is_absolute_path('not/in/my/home~/directory'))
+ eq(FAIL, path_is_absolute('not/in/my/home~/directory'))
end)
end)
end)