aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/CMakeLists.txt7
-rw-r--r--config/config.h.in1
-rw-r--r--src/nvim/eval.c6
-rw-r--r--src/nvim/ex_docmd.c7
-rw-r--r--src/nvim/fileio.c120
-rw-r--r--src/nvim/globals.h10
-rw-r--r--src/nvim/iconv.h46
-rw-r--r--src/nvim/main.c3
-rw-r--r--src/nvim/mbyte.c173
-rw-r--r--src/nvim/mbyte.h2
-rw-r--r--src/nvim/search.c1
-rw-r--r--src/nvim/terminal.c2
-rw-r--r--src/nvim/version.c6
-rw-r--r--test/functional/helpers.lua10
-rw-r--r--test/functional/shada/buffers_spec.lua42
-rw-r--r--test/functional/shada/helpers.lua59
-rw-r--r--test/functional/shada/marks_spec.lua34
-rw-r--r--test/functional/shada/registers_spec.lua11
-rw-r--r--test/functional/shada/shada_spec.lua4
-rw-r--r--test/functional/shada/variables_spec.lua19
20 files changed, 170 insertions, 393 deletions
diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt
index d80686ff2e..0ca41d5dfd 100644
--- a/config/CMakeLists.txt
+++ b/config/CMakeLists.txt
@@ -20,13 +20,6 @@ endif()
check_symbol_exists(_NSGetEnviron crt_externs.h HAVE__NSGETENVIRON)
# Headers
-if(ICONV_INCLUDE_DIR)
- list(APPEND CMAKE_REQUIRED_INCLUDES "${ICONV_INCLUDE_DIR}")
-endif()
-check_include_files(iconv.h HAVE_ICONV_H)
-if(ICONV_INCLUDE_DIR)
- list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES "${ICONV_INCLUDE_DIR}")
-endif()
check_include_files(langinfo.h HAVE_LANGINFO_H)
check_include_files(locale.h HAVE_LOCALE_H)
check_include_files(pwd.h HAVE_PWD_H)
diff --git a/config/config.h.in b/config/config.h.in
index 40baff95e8..3216ab7556 100644
--- a/config/config.h.in
+++ b/config/config.h.in
@@ -22,7 +22,6 @@
#cmakedefine HAVE_GETPWNAM
#cmakedefine HAVE_GETPWUID
#cmakedefine HAVE_ICONV
-#cmakedefine HAVE_ICONV_H
#cmakedefine HAVE_LANGINFO_H
#cmakedefine HAVE_LOCALE_H
#cmakedefine HAVE_NL_LANGINFO_CODESET
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index cc9dfcf27b..77347d4701 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -11259,7 +11259,7 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
"fork",
#endif
"gettext",
-#if defined(HAVE_ICONV_H) && defined(USE_ICONV)
+#if defined(HAVE_ICONV)
"iconv",
#endif
"insert_expand",
@@ -11372,10 +11372,6 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
n = stdout_isatty;
} else if (STRICMP(name, "multi_byte_encoding") == 0) {
n = has_mbyte != 0;
-#if defined(USE_ICONV) && defined(DYNAMIC_ICONV)
- } else if (STRICMP(name, "iconv") == 0) {
- n = iconv_enabled(false);
-#endif
} else if (STRICMP(name, "syntax_items") == 0) {
n = syntax_present(curwin);
#ifdef UNIX
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index b315639681..bad844e9d5 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -4060,10 +4060,9 @@ static char_u *replace_makeprg(exarg_T *eap, char_u *p, char_u **cmdlinep)
return p;
}
-/*
- * Expand file name in Ex command argument.
- * Return FAIL for failure, OK otherwise.
- */
+// Expand file name in Ex command argument.
+// When an error is detected, "errormsgp" is set to a non-NULL pointer.
+// Return FAIL for failure, OK otherwise.
int expand_filename(exarg_T *eap, char_u **cmdlinep, char_u **errormsgp)
{
int has_wildcards; /* need to expand wildcards */
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index d03b9138d0..882bf1b830 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -163,22 +163,22 @@ typedef struct AutoPatCmd {
* Structure to pass arguments from buf_write() to buf_write_bytes().
*/
struct bw_info {
- int bw_fd; /* file descriptor */
- char_u *bw_buf; /* buffer with data to be written */
- int bw_len; /* length of data */
+ int bw_fd; // file descriptor
+ char_u *bw_buf; // buffer with data to be written
+ int bw_len; // length of data
#ifdef HAS_BW_FLAGS
- int bw_flags; /* FIO_ flags */
+ int bw_flags; // FIO_ flags
#endif
- char_u bw_rest[CONV_RESTLEN]; /* not converted bytes */
- int bw_restlen; /* nr of bytes in bw_rest[] */
- int bw_first; /* first write call */
- char_u *bw_conv_buf; /* buffer for writing converted chars */
- int bw_conv_buflen; /* size of bw_conv_buf */
- int bw_conv_error; /* set for conversion error */
- linenr_T bw_conv_error_lnum; /* first line with error or zero */
- linenr_T bw_start_lnum; /* line number at start of buffer */
-# ifdef USE_ICONV
- iconv_t bw_iconv_fd; /* descriptor for iconv() or -1 */
+ char_u bw_rest[CONV_RESTLEN]; // not converted bytes
+ int bw_restlen; // nr of bytes in bw_rest[]
+ int bw_first; // first write call
+ char_u *bw_conv_buf; // buffer for writing converted chars
+ int bw_conv_buflen; // size of bw_conv_buf
+ int bw_conv_error; // set for conversion error
+ linenr_T bw_conv_error_lnum; // first line with error or zero
+ linenr_T bw_start_lnum; // line number at start of buffer
+# ifdef HAVE_ICONV
+ iconv_t bw_iconv_fd; // descriptor for iconv() or -1
# endif
};
@@ -327,10 +327,10 @@ readfile(
char_u *fenc_next = NULL; // next item in 'fencs' or NULL
bool advance_fenc = false;
long real_size = 0;
-# ifdef USE_ICONV
- iconv_t iconv_fd = (iconv_t)-1; /* descriptor for iconv() or -1 */
- int did_iconv = FALSE; /* TRUE when iconv() failed and trying
- 'charconvert' next */
+# ifdef HAVE_ICONV
+ iconv_t iconv_fd = (iconv_t)-1; // descriptor for iconv() or -1
+ int did_iconv = false; // TRUE when iconv() failed and trying
+ // 'charconvert' next
# endif
int converted = FALSE; /* TRUE if conversion done */
int notconverted = FALSE; /* TRUE if conversion wanted but it
@@ -841,7 +841,7 @@ retry:
fileformat = EOL_UNKNOWN; /* detect from file */
}
-# ifdef USE_ICONV
+# ifdef HAVE_ICONV
if (iconv_fd != (iconv_t)-1) {
/* aborted conversion with iconv(), close the descriptor */
iconv_close(iconv_fd);
@@ -908,15 +908,14 @@ retry:
-# ifdef USE_ICONV
- /*
- * Try using iconv() if we can't convert internally.
- */
+# ifdef HAVE_ICONV
+ // Try using iconv() if we can't convert internally.
if (fio_flags == 0
&& !did_iconv
- )
+ ) {
iconv_fd = (iconv_t)my_iconv_open(
enc_utf8 ? (char_u *)"utf-8" : p_enc, fenc);
+ }
# endif
/*
@@ -925,12 +924,12 @@ retry:
*/
if (fio_flags == 0 && !read_stdin && !read_buffer && *p_ccv != NUL
&& !read_fifo
-# ifdef USE_ICONV
+# ifdef HAVE_ICONV
&& iconv_fd == (iconv_t)-1
# endif
) {
-# ifdef USE_ICONV
- did_iconv = FALSE;
+# ifdef HAVE_ICONV
+ did_iconv = false;
# endif
/* Skip conversion when it's already done (retry for wrong
* "fileformat"). */
@@ -950,7 +949,7 @@ retry:
}
} else {
if (fio_flags == 0
-# ifdef USE_ICONV
+# ifdef HAVE_ICONV
&& iconv_fd == (iconv_t)-1
# endif
) {
@@ -1023,20 +1022,23 @@ retry:
* ucs-4 to utf-8: 4 bytes become up to 6 bytes, size must be
* multiple of 4 */
real_size = (int)size;
-# ifdef USE_ICONV
- if (iconv_fd != (iconv_t)-1)
+# ifdef HAVE_ICONV
+ if (iconv_fd != (iconv_t)-1) {
size = size / ICONV_MULT;
- else
+ } else {
# endif
- if (fio_flags & FIO_LATIN1)
+ if (fio_flags & FIO_LATIN1) {
size = size / 2;
- else if (fio_flags & (FIO_UCS2 | FIO_UTF16))
+ } else if (fio_flags & (FIO_UCS2 | FIO_UTF16)) {
size = (size * 2 / 3) & ~1;
- else if (fio_flags & FIO_UCS4)
+ } else if (fio_flags & FIO_UCS4) {
size = (size * 2 / 3) & ~3;
- else if (fio_flags == FIO_UCSBOM)
- size = size / ICONV_MULT; /* worst case */
-
+ } else if (fio_flags == FIO_UCSBOM) {
+ size = size / ICONV_MULT; // worst case
+ }
+# ifdef HAVE_ICONV
+ }
+# endif
if (conv_restlen > 0) {
// Insert unconverted bytes from previous line.
memmove(ptr, conv_rest, conv_restlen); // -V614
@@ -1112,7 +1114,7 @@ retry:
/* When we did a conversion report an error. */
if (fio_flags != 0
-# ifdef USE_ICONV
+# ifdef HAVE_ICONV
|| iconv_fd != (iconv_t)-1
# endif
) {
@@ -1135,7 +1137,7 @@ retry:
* leave the UTF8 checking code to do it, as it
* works slightly differently. */
if (bad_char_behavior != BAD_KEEP && (fio_flags != 0
-# ifdef USE_ICONV
+# ifdef HAVE_ICONV
|| iconv_fd != (iconv_t)-1
# endif
)) {
@@ -1144,8 +1146,8 @@ retry:
--conv_restlen;
}
}
- fio_flags = 0; /* don't convert this */
-# ifdef USE_ICONV
+ fio_flags = 0; // don't convert this
+# ifdef HAVE_ICONV
if (iconv_fd != (iconv_t)-1) {
iconv_close(iconv_fd);
iconv_fd = (iconv_t)-1;
@@ -1216,7 +1218,7 @@ retry:
if (size <= 0)
break;
-# ifdef USE_ICONV
+# ifdef HAVE_ICONV
if (iconv_fd != (iconv_t)-1) {
/*
* Attempt conversion of the read bytes to 'encoding' using
@@ -1474,10 +1476,11 @@ retry:
* file is more likely than a conversion error. */
if (can_retry && !incomplete_tail)
break;
-# ifdef USE_ICONV
- /* When we did a conversion report an error. */
- if (iconv_fd != (iconv_t)-1 && conv_error == 0)
+# ifdef HAVE_ICONV
+ // When we did a conversion report an error.
+ if (iconv_fd != (iconv_t)-1 && conv_error == 0) {
conv_error = readfile_linenr(linecnt, ptr, p);
+ }
# endif
/* Remember the first linenr with an illegal byte */
if (conv_error == 0 && illegal_byte == 0)
@@ -1497,15 +1500,18 @@ retry:
if (p < ptr + size && !incomplete_tail) {
/* Detected a UTF-8 error. */
rewind_retry:
- /* Retry reading with another conversion. */
-# ifdef USE_ICONV
- if (*p_ccv != NUL && iconv_fd != (iconv_t)-1)
- /* iconv() failed, try 'charconvert' */
- did_iconv = TRUE;
- else
+ // Retry reading with another conversion.
+# ifdef HAVE_ICONV
+ if (*p_ccv != NUL && iconv_fd != (iconv_t)-1) {
+ // iconv() failed, try 'charconvert'
+ did_iconv = true;
+ } else {
# endif
// use next item from 'fileencodings'
advance_fenc = true;
+# ifdef HAVE_ICONV
+ }
+# endif
file_rewind = true;
goto retry;
}
@@ -1710,7 +1716,7 @@ failed:
}
if (fenc_alloced)
xfree(fenc);
-# ifdef USE_ICONV
+# ifdef HAVE_ICONV
if (iconv_fd != (iconv_t)-1) {
iconv_close(iconv_fd);
# ifndef __clang_analyzer__
@@ -2294,7 +2300,7 @@ buf_write(
write_info.bw_conv_error = FALSE;
write_info.bw_conv_error_lnum = 0;
write_info.bw_restlen = 0;
-# ifdef USE_ICONV
+# ifdef HAVE_ICONV
write_info.bw_iconv_fd = (iconv_t)-1;
# endif
@@ -3015,7 +3021,7 @@ nobackup:
if (converted && wb_flags == 0) {
-# ifdef USE_ICONV
+# ifdef HAVE_ICONV
// Use iconv() conversion when conversion is needed and it's not done
// internally.
write_info.bw_iconv_fd = (iconv_t)my_iconv_open(fenc,
@@ -3045,7 +3051,7 @@ nobackup:
}
}
if (converted && wb_flags == 0
-# ifdef USE_ICONV
+# ifdef HAVE_ICONV
&& write_info.bw_iconv_fd == (iconv_t)-1
# endif
&& wfname == fname
@@ -3573,7 +3579,7 @@ nofail:
xfree(buffer);
xfree(fenc_tofree);
xfree(write_info.bw_conv_buf);
-# ifdef USE_ICONV
+# ifdef HAVE_ICONV
if (write_info.bw_iconv_fd != (iconv_t)-1) {
iconv_close(write_info.bw_iconv_fd);
write_info.bw_iconv_fd = (iconv_t)-1;
@@ -3948,7 +3954,7 @@ static int buf_write_bytes(struct bw_info *ip)
}
}
-# ifdef USE_ICONV
+# ifdef HAVE_ICONV
if (ip->bw_iconv_fd != (iconv_t)-1) {
const char *from;
size_t fromlen;
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 4524c4b2c0..b095e759d9 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -655,16 +655,6 @@ EXTERN int inhibit_delete_count INIT(= 0);
/// Encoding used when 'fencs' is set to "default"
EXTERN char_u *fenc_default INIT(= NULL);
-# if defined(USE_ICONV) && defined(DYNAMIC_ICONV)
-/* Pointers to functions and variables to be loaded at runtime */
-EXTERN size_t (*iconv)(iconv_t cd, const char **inbuf, size_t *inbytesleft,
- char **outbuf, size_t *outbytesleft);
-EXTERN iconv_t (*iconv_open)(const char *tocode, const char *fromcode);
-EXTERN int (*iconv_close)(iconv_t cd);
-EXTERN int (*iconvctl)(iconv_t cd, int request, void *argument);
-EXTERN int* (*iconv_errno)(void);
-# endif
-
/// "State" is the main state of Vim.
/// There are other variables that modify the state:
/// Visual_mode: When State is NORMAL or INSERT.
diff --git a/src/nvim/iconv.h b/src/nvim/iconv.h
index d7234090c4..a7c9ad4040 100644
--- a/src/nvim/iconv.h
+++ b/src/nvim/iconv.h
@@ -1,52 +1,20 @@
#ifndef NVIM_ICONV_H
#define NVIM_ICONV_H
-// iconv can be linked at compile-time as well as loaded at runtime. In the
-// latter case, some function pointers need to be initialized after loading
-// the library (see `iconv_enabled()` in mbyte.c). These function pointers
-// are stored in globals.h. Since globals.h includes iconv.h to get the
-// definition of USE_ICONV, we can't include it from iconv.h. One way to
-// solve this conundrum would be perhaps to let cmake decide the value of
-// USE_ICONV, or to put the USE_ICONV definition in config.h.in directly. As
-// it stands, globals.h needs to be included alongside iconv.h.
-
#include "auto/config.h"
-// Use iconv() when it's available, either by linking to the library at
-// compile time or by loading it at runtime.
-#if (defined(HAVE_ICONV_H) && defined(HAVE_ICONV)) || defined(DYNAMIC_ICONV)
-# define USE_ICONV
-#endif
-
-// If we don't have the actual iconv header files present but USE_ICONV was
-// defined, we provide a type shim (pull in errno.h and define iconv_t).
-// This enables us to still load and use iconv dynamically at runtime.
-#ifdef USE_ICONV
+#ifdef HAVE_ICONV
# include <errno.h>
-# ifdef HAVE_ICONV_H
-# include <iconv.h>
-# else
-typedef void *iconv_t;
-# endif
-#endif
+# include <iconv.h>
// define some missing constants if necessary
-# ifdef USE_ICONV
# ifndef EILSEQ
# define EILSEQ 123
# endif
-# ifdef DYNAMIC_ICONV
-// on win32 iconv.dll is dynamically loaded
-# define ICONV_ERRNO (*iconv_errno())
-# define ICONV_E2BIG 7
-# define ICONV_EINVAL 22
-# define ICONV_EILSEQ 42
-# else
-# define ICONV_ERRNO errno
-# define ICONV_E2BIG E2BIG
-# define ICONV_EINVAL EINVAL
-# define ICONV_EILSEQ EILSEQ
-# endif
-# endif
+# define ICONV_ERRNO errno
+# define ICONV_E2BIG E2BIG
+# define ICONV_EINVAL EINVAL
+# define ICONV_EILSEQ EILSEQ
+#endif
#endif // NVIM_ICONV_H
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 9c342e62c0..6bb3c37b92 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -664,9 +664,6 @@ void getout(int exitval)
ui_call_set_title(cstr_as_string((char *)p_titleold));
}
-#if defined(USE_ICONV) && defined(DYNAMIC_ICONV)
- iconv_end();
-#endif
cs_end();
if (garbage_collect_at_exit) {
garbage_collect(false);
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index c9ac335f7b..fae7635d34 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -2062,7 +2062,7 @@ enc_locale_copy_enc:
return enc_canonize((char_u *)buf);
}
-# if defined(USE_ICONV)
+# if defined(HAVE_ICONV)
/*
@@ -2083,13 +2083,6 @@ void * my_iconv_open(char_u *to, char_u *from)
if (iconv_working == kBroken)
return (void *)-1; /* detected a broken iconv() previously */
-#ifdef DYNAMIC_ICONV
- // Check if the iconv.dll can be found.
- if (!iconv_enabled(true)) {
- return (void *)-1;
- }
-#endif
-
fd = iconv_open((char *)enc_skip(to), (char *)enc_skip(from));
if (fd != (iconv_t)-1 && iconv_working == kUnknown) {
@@ -2196,152 +2189,7 @@ static char_u *iconv_string(const vimconv_T *const vcp, char_u *str,
return result;
}
-# if defined(DYNAMIC_ICONV)
-// Dynamically load the "iconv.dll" on Win32.
-
-#ifndef DYNAMIC_ICONV // just generating prototypes
-# define HINSTANCE int
-#endif
-static HINSTANCE hIconvDLL = 0;
-static HINSTANCE hMsvcrtDLL = 0;
-
-# ifndef DYNAMIC_ICONV_DLL
-# define DYNAMIC_ICONV_DLL "iconv.dll"
-# define DYNAMIC_ICONV_DLL_ALT "libiconv-2.dll"
-# endif
-# ifndef DYNAMIC_MSVCRT_DLL
-# define DYNAMIC_MSVCRT_DLL "msvcrt.dll"
-# endif
-
-/*
- * Get the address of 'funcname' which is imported by 'hInst' DLL.
- */
-static void * get_iconv_import_func(HINSTANCE hInst,
- const char *funcname)
-{
- PBYTE pImage = (PBYTE)hInst;
- PIMAGE_DOS_HEADER pDOS = (PIMAGE_DOS_HEADER)hInst;
- PIMAGE_NT_HEADERS pPE;
- PIMAGE_IMPORT_DESCRIPTOR pImpDesc;
- PIMAGE_THUNK_DATA pIAT; /* Import Address Table */
- PIMAGE_THUNK_DATA pINT; /* Import Name Table */
- PIMAGE_IMPORT_BY_NAME pImpName;
-
- if (pDOS->e_magic != IMAGE_DOS_SIGNATURE)
- return NULL;
- pPE = (PIMAGE_NT_HEADERS)(pImage + pDOS->e_lfanew);
- if (pPE->Signature != IMAGE_NT_SIGNATURE)
- return NULL;
- pImpDesc = (PIMAGE_IMPORT_DESCRIPTOR)(pImage
- + pPE->OptionalHeader.DataDirectory[
- IMAGE_DIRECTORY_ENTRY_IMPORT]
- .VirtualAddress);
- for (; pImpDesc->FirstThunk; ++pImpDesc) {
- if (!pImpDesc->OriginalFirstThunk)
- continue;
- pIAT = (PIMAGE_THUNK_DATA)(pImage + pImpDesc->FirstThunk);
- pINT = (PIMAGE_THUNK_DATA)(pImage + pImpDesc->OriginalFirstThunk);
- for (; pIAT->u1.Function; ++pIAT, ++pINT) {
- if (IMAGE_SNAP_BY_ORDINAL(pINT->u1.Ordinal))
- continue;
- pImpName = (PIMAGE_IMPORT_BY_NAME)(pImage
- + (UINT_PTR)(pINT->u1.AddressOfData));
- if (strcmp(pImpName->Name, funcname) == 0)
- return (void *)pIAT->u1.Function;
- }
- }
- return NULL;
-}
-
-// Load library "name".
-HINSTANCE vimLoadLib(char *name)
-{
- HINSTANCE dll = NULL;
-
- // NOTE: Do not use mch_dirname() and mch_chdir() here, they may call
- // vimLoadLib() recursively, which causes a stack overflow.
- wchar_t old_dirw[MAXPATHL];
-
- // Path to exe dir.
- char *buf = xstrdup((char *)get_vim_var_str(VV_PROGPATH));
- // ptrdiff_t len = ;
- // assert(len > 0);
- buf[path_tail_with_sep(buf) - buf] = '\0';
-
- if (GetCurrentDirectoryW(MAXPATHL, old_dirw) != 0) {
- // Change directory to where the executable is, both to make
- // sure we find a .dll there and to avoid looking for a .dll
- // in the current directory.
- SetCurrentDirectory((LPCSTR)buf);
- // TODO(justinmk): use uv_dlopen instead. see os_libcall
- dll = LoadLibrary(name);
- SetCurrentDirectoryW(old_dirw);
- }
-
- return dll;
-}
-
-
-/*
- * Try opening the iconv.dll and return TRUE if iconv() can be used.
- */
-bool iconv_enabled(bool verbose)
-{
- if (hIconvDLL != 0 && hMsvcrtDLL != 0)
- return true;
- hIconvDLL = vimLoadLib(DYNAMIC_ICONV_DLL);
- if (hIconvDLL == 0) /* sometimes it's called libiconv.dll */
- hIconvDLL = vimLoadLib(DYNAMIC_ICONV_DLL_ALT);
- if (hIconvDLL != 0)
- hMsvcrtDLL = vimLoadLib(DYNAMIC_MSVCRT_DLL);
- if (hIconvDLL == 0 || hMsvcrtDLL == 0) {
- /* Only give the message when 'verbose' is set, otherwise it might be
- * done whenever a conversion is attempted. */
- if (verbose && p_verbose > 0) {
- verbose_enter();
- EMSG2(_(e_loadlib),
- hIconvDLL == 0 ? DYNAMIC_ICONV_DLL : DYNAMIC_MSVCRT_DLL);
- verbose_leave();
- }
- iconv_end();
- return false;
- }
-
- iconv = (void *)GetProcAddress(hIconvDLL, "libiconv");
- iconv_open = (void *)GetProcAddress(hIconvDLL, "libiconv_open");
- iconv_close = (void *)GetProcAddress(hIconvDLL, "libiconv_close");
- iconvctl = (void *)GetProcAddress(hIconvDLL, "libiconvctl");
- iconv_errno = get_iconv_import_func(hIconvDLL, "_errno");
- if (iconv_errno == NULL)
- iconv_errno = (void *)GetProcAddress(hMsvcrtDLL, "_errno");
- if (iconv == NULL || iconv_open == NULL || iconv_close == NULL
- || iconvctl == NULL || iconv_errno == NULL) {
- iconv_end();
- if (verbose && p_verbose > 0) {
- verbose_enter();
- EMSG2(_(e_loadfunc), "for libiconv");
- verbose_leave();
- }
- return false;
- }
- return true;
-}
-
-void iconv_end(void)
-{
- if (hIconvDLL != 0) {
- // TODO(justinmk): use uv_dlclose instead.
- FreeLibrary(hIconvDLL);
- }
- if (hMsvcrtDLL != 0) {
- FreeLibrary(hMsvcrtDLL);
- }
- hIconvDLL = 0;
- hMsvcrtDLL = 0;
-}
-
-# endif /* DYNAMIC_ICONV */
-# endif /* USE_ICONV */
+# endif // HAVE_ICONV
@@ -2372,10 +2220,11 @@ int convert_setup_ext(vimconv_T *vcp, char_u *from, bool from_unicode_is_utf8,
int from_is_utf8;
int to_is_utf8;
- /* Reset to no conversion. */
-# ifdef USE_ICONV
- if (vcp->vc_type == CONV_ICONV && vcp->vc_fd != (iconv_t)-1)
+ // Reset to no conversion.
+# ifdef HAVE_ICONV
+ if (vcp->vc_type == CONV_ICONV && vcp->vc_fd != (iconv_t)-1) {
iconv_close(vcp->vc_fd);
+ }
# endif
*vcp = (vimconv_T)MBYTE_NONE_CONV;
@@ -2410,9 +2259,9 @@ int convert_setup_ext(vimconv_T *vcp, char_u *from, bool from_unicode_is_utf8,
/* Internal utf-8 -> latin9 conversion. */
vcp->vc_type = CONV_TO_LATIN9;
}
-# ifdef USE_ICONV
- else {
- /* Use iconv() for conversion. */
+# ifdef HAVE_ICONV
+ else { // NOLINT(readability/braces)
+ // Use iconv() for conversion.
vcp->vc_fd = (iconv_t)my_iconv_open(
to_is_utf8 ? (char_u *)"utf-8" : to,
from_is_utf8 ? (char_u *)"utf-8" : from);
@@ -2564,8 +2413,8 @@ char_u * string_convert_ext(const vimconv_T *const vcp, char_u *ptr,
*lenp = (size_t)(d - retval);
break;
-# ifdef USE_ICONV
- case CONV_ICONV: /* conversion with vcp->vc_fd */
+# ifdef HAVE_ICONV
+ case CONV_ICONV: // conversion with vcp->vc_fd
retval = iconv_string(vcp, ptr, len, unconvlenp, lenp);
break;
# endif
diff --git a/src/nvim/mbyte.h b/src/nvim/mbyte.h
index ed48705c6d..536d58be1f 100644
--- a/src/nvim/mbyte.h
+++ b/src/nvim/mbyte.h
@@ -63,7 +63,7 @@ typedef enum {
typedef struct {
int vc_type; ///< Zero or more ConvFlags.
int vc_factor; ///< Maximal expansion factor.
-# ifdef USE_ICONV
+# ifdef HAVE_ICONV
iconv_t vc_fd; ///< Value for CONV_ICONV.
# endif
bool vc_fail; ///< What to do with invalid characters: if true, fail,
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 7d46b3b4d5..fe4fdf57ba 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -4242,6 +4242,7 @@ static void search_stat(int dirc, pos_T *pos,
// STRNICMP ignores case, but we should not ignore case.
// Unfortunately, there is no STRNICMP function.
if (!(chgtick == buf_get_changedtick(curbuf)
+ && lastpat != NULL // supress clang/NULL passed as nonnull parameter
&& STRNICMP(lastpat, spats[last_idx].pat, STRLEN(lastpat)) == 0
&& STRLEN(lastpat) == STRLEN(spats[last_idx].pat)
&& equalpos(lastpos, curwin->w_cursor)
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index d8d529d0f6..3b0f42aacd 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -1306,7 +1306,7 @@ static void refresh_screen(Terminal *term, buf_T *buf)
static void adjust_topline(Terminal *term, buf_T *buf, long added)
{
- FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
+ FOR_ALL_TAB_WINDOWS(tp, wp) {
if (wp->w_buffer == buf) {
linenr_T ml_end = buf->b_ml.ml_line_count;
bool following = ml_end == wp->w_cursor.lnum + added; // cursor at end?
diff --git a/src/nvim/version.c b/src/nvim/version.c
index e07865a410..74a4852def 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -52,12 +52,8 @@ static char *features[] = {
"-acl",
#endif
-#if (defined(HAVE_ICONV_H) && defined(USE_ICONV)) || defined(DYNAMIC_ICONV)
-# ifdef DYNAMIC_ICONV
-"+iconv/dyn",
-# else
+#if defined(HAVE_ICONV)
"+iconv",
-# endif
#else
"-iconv",
#endif
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 92c83b5f49..4dde733e1e 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -419,6 +419,14 @@ end
-- clear('-e')
-- clear{args={'-e'}, args_rm={'-i'}, env={TERM=term}}
function module.clear(...)
+ local argv, env = module.new_argv(...)
+ module.set_session(module.spawn(argv, nil, env))
+end
+
+-- Builds an argument list for use in clear().
+--
+--@see clear() for parameters.
+function module.new_argv(...)
local args = {unpack(module.nvim_argv)}
table.insert(args, '--headless')
local new_args
@@ -458,7 +466,7 @@ function module.clear(...)
for _, arg in ipairs(new_args) do
table.insert(args, arg)
end
- module.set_session(module.spawn(args, nil, env))
+ return args, env
end
function module.insert(...)
diff --git a/test/functional/shada/buffers_spec.lua b/test/functional/shada/buffers_spec.lua
index a4746c2205..04c9c01d7c 100644
--- a/test/functional/shada/buffers_spec.lua
+++ b/test/functional/shada/buffers_spec.lua
@@ -1,26 +1,22 @@
--- ShaDa buffer list saving/reading support
+-- shada buffer list saving/reading support
local helpers = require('test.functional.helpers')(after_each)
local nvim_command, funcs, eq, curbufmeths =
helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths
local shada_helpers = require('test.functional.shada.helpers')
-local reset, set_additional_cmd, clear =
- shada_helpers.reset, shada_helpers.set_additional_cmd,
- shada_helpers.clear
+local reset, clear = shada_helpers.reset, shada_helpers.clear
-describe('ShaDa support code', function()
+describe('shada support code', function()
local testfilename = 'Xtestfile-functional-shada-buffers'
local testfilename_2 = 'Xtestfile-functional-shada-buffers-2'
- before_each(reset)
after_each(clear)
it('is able to dump and restore buffer list', function()
- set_additional_cmd('set shada+=%')
- reset()
+ reset('set shada+=%')
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
nvim_command('qall')
- reset()
+ reset('set shada+=%')
eq(3, funcs.bufnr('$'))
eq('', funcs.bufname(1))
eq(testfilename, funcs.bufname(2))
@@ -28,11 +24,9 @@ describe('ShaDa support code', function()
end)
it('does not restore buffer list without % in &shada', function()
- set_additional_cmd('set shada+=%')
- reset()
+ reset('set shada+=%')
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
- set_additional_cmd('')
nvim_command('qall')
reset()
eq(1, funcs.bufnr('$'))
@@ -40,61 +34,57 @@ describe('ShaDa support code', function()
end)
it('does not dump buffer list without % in &shada', function()
+ reset()
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
- set_additional_cmd('set shada+=%')
nvim_command('qall')
- reset()
+ reset('set shada+=%')
eq(1, funcs.bufnr('$'))
eq('', funcs.bufname(1))
end)
it('does not dump unlisted buffer', function()
- set_additional_cmd('set shada+=%')
- reset()
+ reset('set shada+=%')
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
curbufmeths.set_option('buflisted', false)
nvim_command('qall')
- reset()
+ reset('set shada+=%')
eq(2, funcs.bufnr('$'))
eq('', funcs.bufname(1))
eq(testfilename, funcs.bufname(2))
end)
it('does not dump quickfix buffer', function()
- set_additional_cmd('set shada+=%')
- reset()
+ reset('set shada+=%')
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
curbufmeths.set_option('buftype', 'quickfix')
nvim_command('qall')
- reset()
+ reset('set shada+=%')
eq(2, funcs.bufnr('$'))
eq('', funcs.bufname(1))
eq(testfilename, funcs.bufname(2))
end)
it('does not dump unnamed buffers', function()
- set_additional_cmd('set shada+=% hidden')
- reset()
+ reset('set shada+=% hidden')
curbufmeths.set_lines(0, 1, true, {'foo'})
nvim_command('enew')
curbufmeths.set_lines(0, 1, true, {'bar'})
eq(2, funcs.bufnr('$'))
nvim_command('qall!')
- reset()
+ reset('set shada+=% hidden')
eq(1, funcs.bufnr('$'))
eq('', funcs.bufname(1))
end)
it('restores 1 buffer with %1 in &shada, #5759', function()
- set_additional_cmd('set shada+=%1')
- reset()
+ reset('set shada+=%1')
nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2)
nvim_command('qall')
- reset()
+ reset('set shada+=%1')
eq(2, funcs.bufnr('$'))
eq('', funcs.bufname(1))
eq(testfilename, funcs.bufname(2))
diff --git a/test/functional/shada/helpers.lua b/test/functional/shada/helpers.lua
index d5e061bb50..fb3ec4a87c 100644
--- a/test/functional/shada/helpers.lua
+++ b/test/functional/shada/helpers.lua
@@ -1,47 +1,39 @@
local helpers = require('test.functional.helpers')(nil)
-local spawn, set_session, meths, nvim_prog =
- helpers.spawn, helpers.set_session, helpers.meths, helpers.nvim_prog
-local write_file, merge_args = helpers.write_file, helpers.merge_args
+local meths = helpers.meths
+local write_file = helpers.write_file
+local concat_tables = helpers.concat_tables
local mpack = require('mpack')
local tmpname = helpers.tmpname()
-local append_argv = nil
-local function nvim_argv(shada_file, embed)
- if embed == nil then
- embed = true
+-- o={
+-- args=…,
+-- args_rm=…,
+-- shadafile=…,
+-- }
+local function reset(o)
+ assert(o == nil or type(o) == 'table' or type(o) == 'string')
+ o = o and o or {}
+ local args_rm = o.args_rm or {}
+ table.insert(args_rm, '-i')
+ local args={
+ '-i', o.shadafile or tmpname,
+ }
+ if type(o) == 'string' then
+ args = concat_tables(args, {'--cmd', o})
+ elseif o.args then
+ args = concat_tables(args, o.args)
end
- local argv = {nvim_prog, '-u', 'NONE', '-i', shada_file or tmpname, '-N',
- '--cmd', 'set shortmess+=I background=light noswapfile',
- '--headless', embed and '--embed' or nil}
- if helpers.prepend_argv or append_argv then
- return merge_args(helpers.prepend_argv, argv, append_argv)
- else
- return argv
- end
-end
-
-local reset = function(shada_file)
- set_session(spawn(nvim_argv(shada_file)))
+ helpers.clear{
+ args_rm=args_rm,
+ args=args,
+ }
meths.set_var('tmpname', tmpname)
end
-local set_additional_cmd = function(s)
- append_argv = {'--cmd', s}
-end
-
-local function add_argv(...)
- if select('#', ...) == 0 then
- append_argv = nil
- else
- append_argv = {...}
- end
-end
-
local clear = function()
os.remove(tmpname)
- append_argv = nil
end
local get_shada_rw = function(fname)
@@ -89,10 +81,7 @@ end
return {
reset=reset,
- set_additional_cmd=set_additional_cmd,
- add_argv=add_argv,
clear=clear,
get_shada_rw=get_shada_rw,
read_shada_file=read_shada_file,
- nvim_argv=nvim_argv,
}
diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua
index e6450e68b3..e319fd9e6b 100644
--- a/test/functional/shada/marks_spec.lua
+++ b/test/functional/shada/marks_spec.lua
@@ -6,11 +6,7 @@ local meths, curwinmeths, curbufmeths, nvim_command, funcs, eq =
local exc_exec, redir_exec = helpers.exc_exec, helpers.redir_exec
local shada_helpers = require('test.functional.shada.helpers')
-local reset, set_additional_cmd, clear =
- shada_helpers.reset, shada_helpers.set_additional_cmd,
- shada_helpers.clear
-local add_argv = shada_helpers.add_argv
-local nvim_argv = shada_helpers.nvim_argv
+local reset, clear = shada_helpers.reset, shada_helpers.clear
local nvim_current_line = function()
return curwinmeths.get_cursor()[1]
@@ -71,8 +67,7 @@ describe('ShaDa support code', function()
nvim_command('2')
nvim_command('kB')
nvim_command('wshada')
- set_additional_cmd('set shada=\'0,f0')
- reset()
+ reset('set shada=\'0,f0')
nvim_command('language C')
nvim_command('normal! `A')
eq(testfilename, funcs.fnamemodify(curbufmeths.get_name(), ':t'))
@@ -223,17 +218,32 @@ describe('ShaDa support code', function()
-- during -c used to add item with zero lnum to jump list.
it('does not create incorrect file for non-existent buffers when writing from -c',
function()
- add_argv('--cmd', 'silent edit ' .. non_existent_testfilename, '-c', 'qall')
- local argv = nvim_argv(nil, false) -- no --embed
+ local argv = helpers.new_argv{
+ args_rm={
+ '-i',
+ '--embed', -- no --embed
+ },
+ args={
+ '-i', meths.get_var('tmpname'), -- Use same shada file as parent.
+ '--cmd', 'silent edit '..non_existent_testfilename,
+ '-c', 'qall'},
+ }
eq('', funcs.system(argv))
eq(0, exc_exec('rshada'))
end)
it('does not create incorrect file for non-existent buffers opened from -c',
function()
- add_argv('-c', 'silent edit ' .. non_existent_testfilename,
- '-c', 'autocmd VimEnter * qall')
- local argv = nvim_argv(nil, false) -- no --embed
+ local argv = helpers.new_argv{
+ args_rm={
+ '-i',
+ '--embed', -- no --embed
+ },
+ args={
+ '-i', meths.get_var('tmpname'), -- Use same shada file as parent.
+ '-c', 'silent edit '..non_existent_testfilename,
+ '-c', 'autocmd VimEnter * qall'},
+ }
eq('', funcs.system(argv))
eq(0, exc_exec('rshada'))
end)
diff --git a/test/functional/shada/registers_spec.lua b/test/functional/shada/registers_spec.lua
index 71af14aba8..1f06cbe350 100644
--- a/test/functional/shada/registers_spec.lua
+++ b/test/functional/shada/registers_spec.lua
@@ -3,9 +3,7 @@ local helpers = require('test.functional.helpers')(after_each)
local nvim_command, funcs, eq = helpers.command, helpers.funcs, helpers.eq
local shada_helpers = require('test.functional.shada.helpers')
-local reset, set_additional_cmd, clear =
- shada_helpers.reset, shada_helpers.set_additional_cmd,
- shada_helpers.clear
+local reset, clear = shada_helpers.reset, shada_helpers.clear
local setreg = function(name, contents, typ)
if type(contents) == 'string' then
@@ -52,9 +50,8 @@ describe('ShaDa support code', function()
setreg('c', {'d', 'e', ''}, 'c')
setreg('l', {'a', 'b', 'cde'}, 'l')
setreg('b', {'bca', 'abc', 'cba'}, 'b3')
- set_additional_cmd('set shada=\'0,<0')
nvim_command('qall')
- reset()
+ reset('set shada=\'0,<0')
eq({{'d', 'e', ''}, 'v'}, getreg('c'))
eq({{'a', 'b', 'cde'}, 'V'}, getreg('l'))
eq({{'bca', 'abc', 'cba'}, '\0223'}, getreg('b'))
@@ -76,9 +73,8 @@ describe('ShaDa support code', function()
setreg('c', {'d', 'e', ''}, 'c')
setreg('l', {'a', 'b', 'cde'}, 'l')
setreg('b', {'bca', 'abc', 'cba'}, 'b3')
- set_additional_cmd('set shada=\'0,\\"0')
nvim_command('qall')
- reset()
+ reset('set shada=\'0,\\"0')
eq({{'d', 'e', ''}, 'v'}, getreg('c'))
eq({{'a', 'b', 'cde'}, 'V'}, getreg('l'))
eq({{'bca', 'abc', 'cba'}, '\0223'}, getreg('b'))
@@ -142,7 +138,6 @@ describe('ShaDa support code', function()
reset()
-- \171 is U+00AB LEFT-POINTING DOUBLE ANGLE QUOTATION MARK in latin1
setreg('e', {'\171«'}, 'c')
- set_additional_cmd('')
nvim_command('qall')
reset()
eq({{'\171«'}, 'v'}, getreg('e'))
diff --git a/test/functional/shada/shada_spec.lua b/test/functional/shada/shada_spec.lua
index 5f7daf73e5..ff63aed235 100644
--- a/test/functional/shada/shada_spec.lua
+++ b/test/functional/shada/shada_spec.lua
@@ -15,7 +15,6 @@ local shada_helpers = require('test.functional.shada.helpers')
local reset, clear, get_shada_rw =
shada_helpers.reset, shada_helpers.clear, shada_helpers.get_shada_rw
local read_shada_file = shada_helpers.read_shada_file
-local set_additional_cmd = shada_helpers.set_additional_cmd
local wshada, _, shada_fname, clean =
get_shada_rw('Xtest-functional-shada-shada.shada')
@@ -244,8 +243,7 @@ describe('ShaDa support code', function()
funcs.mkdir(dirname, '', 0)
eq(0, funcs.filewritable(dirname))
- set_additional_cmd('set shada=')
- reset(dirshada)
+ reset{shadafile=dirshada, args={'--cmd', 'set shada='}}
meths.set_option('shada', '\'10')
eq('Vim(wshada):E886: System error while opening ShaDa file '
.. 'Xtest-functional-shada-shada.d/main.shada for reading to merge '
diff --git a/test/functional/shada/variables_spec.lua b/test/functional/shada/variables_spec.lua
index f817bcef74..74bbceddcc 100644
--- a/test/functional/shada/variables_spec.lua
+++ b/test/functional/shada/variables_spec.lua
@@ -4,9 +4,7 @@ local meths, funcs, nvim_command, eq, exc_exec =
helpers.meths, helpers.funcs, helpers.command, helpers.eq, helpers.exc_exec
local shada_helpers = require('test.functional.shada.helpers')
-local reset, set_additional_cmd, clear =
- shada_helpers.reset, shada_helpers.set_additional_cmd,
- shada_helpers.clear
+local reset, clear = shada_helpers.reset, shada_helpers.clear
describe('ShaDa support code', function()
before_each(reset)
@@ -25,8 +23,7 @@ describe('ShaDa support code', function()
local autotest = function(tname, varname, varval, val_is_expr)
it('is able to dump and read back ' .. tname .. ' variable automatically',
function()
- set_additional_cmd('set shada+=!')
- reset()
+ reset('set shada+=!')
if val_is_expr then
nvim_command('let g:' .. varname .. ' = ' .. varval)
varval = meths.get_var(varname)
@@ -36,7 +33,7 @@ describe('ShaDa support code', function()
-- Exit during `reset` is not a regular exit: it does not write shada
-- automatically
nvim_command('qall')
- reset()
+ reset('set shada+=!')
eq(varval, meths.get_var(varname))
end)
end
@@ -55,8 +52,7 @@ describe('ShaDa support code', function()
meths.set_var('STRVAR', 'foo')
nvim_command('set shada+=!')
nvim_command('wshada')
- set_additional_cmd('set shada-=!')
- reset()
+ reset('set shada-=!')
nvim_command('rshada')
eq(0, funcs.exists('g:STRVAR'))
end)
@@ -98,7 +94,6 @@ describe('ShaDa support code', function()
meths.set_var('LSTVAR', {'«'})
meths.set_var('DCTVAR', {['«']='«'})
meths.set_var('NESTEDVAR', {['«']={{'«'}, {['«']='«'}, {a='Test'}}})
- set_additional_cmd('')
nvim_command('qall')
reset()
eq('«', meths.get_var('STRVAR'))
@@ -131,11 +126,10 @@ describe('ShaDa support code', function()
nvim_command('let F = function("tr")')
meths.set_var('U', '10')
nvim_command('set shada+=!')
- set_additional_cmd('set shada+=!')
eq('Vim(wshada):E5004: Error while dumping variable g:F, itself: attempt to dump function reference',
exc_exec('wshada'))
meths.set_option('shada', '')
- reset()
+ reset('set shada+=!')
eq('10', meths.get_var('U'))
end)
@@ -148,8 +142,7 @@ describe('ShaDa support code', function()
eq('Vim(wshada):E5005: Unable to dump variable g:L: container references itself in index 0',
exc_exec('wshada'))
meths.set_option('shada', '')
- set_additional_cmd('set shada+=!')
- reset()
+ reset('set shada+=!')
eq('10', meths.get_var('U'))
end)
end)