diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-01-23 16:33:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-23 16:33:45 +0000 |
commit | f08051c2e61f63b2088a42d641393253b8ca1ca1 (patch) | |
tree | 04b2d5c875e6df790ce416a2e8363126101460e9 | |
parent | 3b7548504344d72b0228e1bd29a7f28df813a3bd (diff) | |
download | rneovim-f08051c2e61f63b2088a42d641393253b8ca1ca1.tar.gz rneovim-f08051c2e61f63b2088a42d641393253b8ca1ca1.tar.bz2 rneovim-f08051c2e61f63b2088a42d641393253b8ca1ca1.zip |
feat!: make iconv a non-optional dep
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | cmake.config/CMakeLists.txt | 5 | ||||
-rw-r--r-- | cmake.config/config.h.in | 1 | ||||
-rw-r--r-- | runtime/doc/news.txt | 2 | ||||
-rwxr-xr-x | src/nvim/CMakeLists.txt | 9 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 2 | ||||
-rw-r--r-- | src/nvim/fileio.c | 97 | ||||
-rw-r--r-- | src/nvim/iconv.h | 20 | ||||
-rw-r--r-- | src/nvim/lua/stdlib.c | 6 | ||||
-rw-r--r-- | src/nvim/mbyte.c | 15 | ||||
-rw-r--r-- | src/nvim/mbyte_defs.h | 2 | ||||
-rw-r--r-- | src/nvim/version.c | 6 |
12 files changed, 37 insertions, 133 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c83a8dd617..b3ad290c7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -342,11 +342,6 @@ install_helper( FILES ${CMAKE_SOURCE_DIR}/src/man/nvim.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) -option(ENABLE_LIBICONV "enable libiconv" ON) -if(ENABLE_LIBICONV) - find_package(Iconv REQUIRED) -endif() - # # Go down the tree. # diff --git a/cmake.config/CMakeLists.txt b/cmake.config/CMakeLists.txt index 0ea2124401..6de86cbaf2 100644 --- a/cmake.config/CMakeLists.txt +++ b/cmake.config/CMakeLists.txt @@ -51,11 +51,6 @@ check_function_exists(getpwent HAVE_GETPWENT) check_function_exists(getpwnam HAVE_GETPWNAM) check_function_exists(getpwuid HAVE_GETPWUID) check_function_exists(readv HAVE_READV) - -if(Iconv_FOUND) - set(HAVE_ICONV 1) -endif() - check_function_exists(opendir HAVE_OPENDIR) check_function_exists(readlink HAVE_READLINK) check_function_exists(setpgid HAVE_SETPGID) diff --git a/cmake.config/config.h.in b/cmake.config/config.h.in index f946fa6124..c8377bf45c 100644 --- a/cmake.config/config.h.in +++ b/cmake.config/config.h.in @@ -24,7 +24,6 @@ #cmakedefine HAVE_GETPWENT #cmakedefine HAVE_GETPWNAM #cmakedefine HAVE_GETPWUID -#cmakedefine HAVE_ICONV #cmakedefine HAVE_LANGINFO_H #cmakedefine HAVE_LOCALE_H #cmakedefine HAVE_NL_LANGINFO_CODESET diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 83272a0d87..853ca23e5d 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -45,6 +45,8 @@ The following changes may require adaptations in user config or plugins. - `printheader` - `printmbcharset` +• libiconv is now a required build dependency. + ============================================================================== NEW FEATURES *news-features* diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 725d7987e7..ac067efef9 100755 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -34,12 +34,9 @@ find_package(LIBVTERM 0.3 REQUIRED) target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${LIBVTERM_INCLUDE_DIRS}) target_link_libraries(main_lib INTERFACE ${LIBVTERM_LIBRARIES}) -if(Iconv_FOUND) - target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${Iconv_INCLUDE_DIRS}) - if(Iconv_LIBRARIES) - target_link_libraries(main_lib INTERFACE ${Iconv_LIBRARIES}) - endif() -endif() +find_package(Iconv REQUIRED) +target_include_directories(main_lib SYSTEM BEFORE INTERFACE ${Iconv_INCLUDE_DIRS}) +target_link_libraries(main_lib INTERFACE ${Iconv_LIBRARIES}) option(ENABLE_LIBINTL "enable libintl" ON) if(ENABLE_LIBINTL) diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index c64aad659f..5a31288ecd 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -3082,9 +3082,7 @@ static void f_has(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) "fork", #endif "gettext", -#if defined(HAVE_ICONV) "iconv", -#endif "insert_expand", "jumplist", "keymap", diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index a4105e379f..9da9d6199e 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -118,9 +118,7 @@ struct bw_info { 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 }; #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -248,11 +246,9 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, char *fenc_next = NULL; // next item in 'fencs' or NULL bool advance_fenc = false; long real_size = 0; -#ifdef HAVE_ICONV iconv_t iconv_fd = (iconv_t)-1; // descriptor for iconv() or -1 bool did_iconv = false; // true when iconv() failed and trying // 'charconvert' next -#endif bool converted = false; // true if conversion done bool notconverted = false; // true if conversion wanted but it wasn't possible char conv_rest[CONV_RESTLEN]; @@ -779,13 +775,11 @@ retry: } } -#ifdef HAVE_ICONV if (iconv_fd != (iconv_t)-1) { // aborted conversion with iconv(), close the descriptor iconv_close(iconv_fd); iconv_fd = (iconv_t)-1; } -#endif if (advance_fenc) { // Try the next entry in 'fileencodings'. @@ -838,25 +832,17 @@ retry: fio_flags = get_fio_flags(fenc); } -#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("utf-8", fenc); } -#endif // Use the 'charconvert' expression when conversion is required // and we can't do it internally or with iconv(). if (fio_flags == 0 && !read_stdin && !read_buffer && *p_ccv != NUL - && !read_fifo -#ifdef HAVE_ICONV - && iconv_fd == (iconv_t)-1 -#endif - ) { -#ifdef HAVE_ICONV + && !read_fifo && iconv_fd == (iconv_t)-1) { did_iconv = false; -#endif // Skip conversion when it's already done (retry for wrong // "fileformat"). if (tmpname == NULL) { @@ -874,11 +860,7 @@ retry: } } } else { - if (fio_flags == 0 -#ifdef HAVE_ICONV - && iconv_fd == (iconv_t)-1 -#endif - ) { + if (fio_flags == 0 && iconv_fd == (iconv_t)-1) { // Conversion wanted but we can't. // Try the next conversion in 'fileencodings' advance_fenc = true; @@ -961,12 +943,9 @@ retry: // ucs-4 to utf-8: 4 bytes become up to 6 bytes, size must be // multiple of 4 real_size = (int)size; -#ifdef HAVE_ICONV if (iconv_fd != (iconv_t)-1) { size = size / ICONV_MULT; - } else { -#endif - if (fio_flags & FIO_LATIN1) { + } else if (fio_flags & FIO_LATIN1) { size = size / 2; } else if (fio_flags & (FIO_UCS2 | FIO_UTF16)) { size = (size * 2 / 3) & ~1; @@ -975,9 +954,7 @@ retry: } 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, (size_t)conv_restlen); // -V614 @@ -1049,11 +1026,7 @@ retry: // not be converted. Truncated file? // When we did a conversion report an error. - if (fio_flags != 0 -#ifdef HAVE_ICONV - || iconv_fd != (iconv_t)-1 -#endif - ) { + if (fio_flags != 0 || iconv_fd != (iconv_t)-1) { if (can_retry) { goto rewind_retry; } @@ -1074,23 +1047,17 @@ retry: // character if we were converting; if we weren't, // leave the UTF8 checking code to do it, as it // works slightly differently. - if (bad_char_behavior != BAD_KEEP && (fio_flags != 0 -#ifdef HAVE_ICONV - || iconv_fd != (iconv_t)-1 -#endif - )) { // NOLINT(whitespace/parens) + if (bad_char_behavior != BAD_KEEP && (fio_flags != 0 || iconv_fd != (iconv_t)-1)) { while (conv_restlen > 0) { *(--ptr) = (char)bad_char_behavior; conv_restlen--; } } 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; } -#endif } } } @@ -1155,7 +1122,6 @@ retry: break; } -#ifdef HAVE_ICONV if (iconv_fd != (iconv_t)-1) { // Attempt conversion of the read bytes to 'encoding' using iconv(). const char *fromp = ptr; @@ -1202,7 +1168,6 @@ retry: memmove(line_start, buffer, (size_t)linerest); size = (top - ptr); } -#endif if (fio_flags != 0) { unsigned int u8c; @@ -1420,12 +1385,12 @@ retry: if (can_retry && !incomplete_tail) { break; } -#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, (char *)p); } -#endif + // Remember the first linenr with an illegal byte if (conv_error == 0 && illegal_byte == 0) { illegal_byte = readfile_linenr(linecnt, ptr, (char *)p); @@ -1448,17 +1413,13 @@ retry: // Detected a UTF-8 error. rewind_retry: // 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 + // use next item from 'fileencodings' + advance_fenc = true; + } file_rewind = true; goto retry; } @@ -1683,11 +1644,9 @@ failed: if (fenc_alloced) { xfree(fenc); } -#ifdef HAVE_ICONV if (iconv_fd != (iconv_t)-1) { iconv_close(iconv_fd); } -#endif if (!read_buffer && !read_stdin) { close(fd); // errors are ignored @@ -2233,9 +2192,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en write_info.bw_conv_error = false; write_info.bw_conv_error_lnum = 0; write_info.bw_restlen = 0; -#ifdef HAVE_ICONV write_info.bw_iconv_fd = (iconv_t)-1; -#endif // After writing a file changedtick changes but we don't want to display // the line. @@ -2996,7 +2953,6 @@ nobackup: } if (converted && wb_flags == 0) { -#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, "utf-8"); @@ -3009,28 +2965,21 @@ nobackup: } write_info.bw_first = true; } else { -#endif - - // When the file needs to be converted with 'charconvert' after - // writing, write to a temp file instead and let the conversion - // overwrite the original file. - if (*p_ccv != NUL) { - wfname = vim_tempname(); - if (wfname == NULL) { // Can't write without a tempfile! - SET_ERRMSG(_("E214: Can't find temp file for writing")); - goto restore_backup; + // When the file needs to be converted with 'charconvert' after + // writing, write to a temp file instead and let the conversion + // overwrite the original file. + if (*p_ccv != NUL) { + wfname = vim_tempname(); + if (wfname == NULL) { // Can't write without a tempfile! + SET_ERRMSG(_("E214: Can't find temp file for writing")); + goto restore_backup; + } } } } -#ifdef HAVE_ICONV -} -#endif - if (converted && wb_flags == 0 -#ifdef HAVE_ICONV && write_info.bw_iconv_fd == (iconv_t)-1 -#endif && wfname == fname) { if (!forceit) { SET_ERRMSG(_("E213: Cannot convert (add ! to write without conversion)")); @@ -3551,12 +3500,10 @@ nofail: } xfree(fenc_tofree); xfree(write_info.bw_conv_buf); -#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; } -#endif #ifdef HAVE_ACL os_free_acl(acl); #endif @@ -3801,7 +3748,7 @@ static bool time_differs(const FileInfo *file_info, long mtime, long mtime_ns) F || file_info->stat.st_mtim.tv_sec - mtime > 1 || mtime - file_info->stat.st_mtim.tv_sec > 1; #else - || (long)file_info->stat.st_mtim.tv_sec != mtime; + || file_info->stat.st_mtim.tv_sec != mtime; #endif } @@ -3914,7 +3861,6 @@ static int buf_write_bytes(struct bw_info *ip) } } -#ifdef HAVE_ICONV if (ip->bw_iconv_fd != (iconv_t)-1) { const char *from; size_t fromlen; @@ -3973,7 +3919,6 @@ static int buf_write_bytes(struct bw_info *ip) buf = ip->bw_conv_buf; len = (int)(to - ip->bw_conv_buf); } -#endif } if (ip->bw_fd < 0) { diff --git a/src/nvim/iconv.h b/src/nvim/iconv.h index 509f83c415..f5f3f25786 100644 --- a/src/nvim/iconv.h +++ b/src/nvim/iconv.h @@ -1,20 +1,18 @@ #ifndef NVIM_ICONV_H #define NVIM_ICONV_H -#include "auto/config.h" +#include <errno.h> +#include <iconv.h> -#ifdef HAVE_ICONV -# include <errno.h> -# include <iconv.h> +#include "auto/config.h" // define some missing constants if necessary -# ifndef EILSEQ -# define EILSEQ 123 -# endif -# define ICONV_ERRNO errno -# define ICONV_E2BIG E2BIG -# define ICONV_EINVAL EINVAL -# define ICONV_EILSEQ EILSEQ +#ifndef EILSEQ +# define EILSEQ 123 #endif +#define ICONV_ERRNO errno +#define ICONV_E2BIG E2BIG +#define ICONV_EINVAL EINVAL +#define ICONV_EILSEQ EILSEQ #endif // NVIM_ICONV_H diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 8b74418753..6ebca6d97e 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -482,8 +482,6 @@ static int nlua_stricmp(lua_State *const lstate) FUNC_ATTR_NONNULL_ALL return 1; } -#if defined(HAVE_ICONV) - /// Convert string from one encoding to another static int nlua_iconv(lua_State *lstate) { @@ -526,8 +524,6 @@ static int nlua_iconv(lua_State *lstate) return 1; } -#endif - void nlua_state_add_stdlib(lua_State *const lstate, bool is_thread) { if (!is_thread) { @@ -574,12 +570,10 @@ void nlua_state_add_stdlib(lua_State *const lstate, bool is_thread) luaopen_spell(lstate); lua_setfield(lstate, -2, "spell"); -#if defined(HAVE_ICONV) // vim.iconv // depends on p_ambw, p_emoji lua_pushcfunction(lstate, &nlua_iconv); lua_setfield(lstate, -2, "iconv"); -#endif } // vim.mpack diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 0a0a2080b4..8b50ba719a 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -2263,8 +2263,6 @@ enc_locale_copy_enc: return enc_canonize(buf); } -#if defined(HAVE_ICONV) - // Call iconv_open() with a check if iconv() works properly (there are broken // versions). // Returns (void *)-1 if failed. @@ -2272,7 +2270,7 @@ enc_locale_copy_enc: void *my_iconv_open(char *to, char *from) { iconv_t fd; -# define ICONV_TESTLEN 400 +#define ICONV_TESTLEN 400 char tobuf[ICONV_TESTLEN]; char *p; size_t tolen; @@ -2386,8 +2384,6 @@ static char *iconv_string(const vimconv_T *const vcp, const char *str, size_t sl return result; } -#endif // HAVE_ICONV - /// Setup "vcp" for conversion from "from" to "to". /// The names must have been made canonical with enc_canonize(). /// vcp->vc_type must have been initialized to CONV_NONE. @@ -2412,11 +2408,9 @@ int convert_setup_ext(vimconv_T *vcp, char *from, bool from_unicode_is_utf8, cha int to_is_utf8; // 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; // No conversion when one of the names is empty or they are equal. @@ -2452,9 +2446,7 @@ int convert_setup_ext(vimconv_T *vcp, char *from, bool from_unicode_is_utf8, cha } else if (from_is_utf8 && (to_prop & ENC_LATIN9)) { // Internal utf-8 -> latin9 conversion. vcp->vc_type = CONV_TO_LATIN9; - } -#ifdef HAVE_ICONV - else { // NOLINT(readability/braces) + } else { // Use iconv() for conversion. vcp->vc_fd = (iconv_t)my_iconv_open(to_is_utf8 ? "utf-8" : to, from_is_utf8 ? "utf-8" : from); @@ -2463,7 +2455,6 @@ int convert_setup_ext(vimconv_T *vcp, char *from, bool from_unicode_is_utf8, cha vcp->vc_factor = 4; // could be longer too... } } -#endif if (vcp->vc_type == CONV_NONE) { return FAIL; } @@ -2626,11 +2617,9 @@ char *string_convert_ext(const vimconv_T *const vcp, char *ptr, size_t *lenp, si } break; -#ifdef HAVE_ICONV case CONV_ICONV: // conversion with vcp->vc_fd retval = (char_u *)iconv_string(vcp, ptr, len, unconvlenp, lenp); break; -#endif } return (char *)retval; diff --git a/src/nvim/mbyte_defs.h b/src/nvim/mbyte_defs.h index 53b01a211f..e913e20f9f 100644 --- a/src/nvim/mbyte_defs.h +++ b/src/nvim/mbyte_defs.h @@ -46,9 +46,7 @@ typedef enum { typedef struct { int vc_type; ///< Zero or more ConvFlags. int vc_factor; ///< Maximal expansion factor. -#ifdef HAVE_ICONV iconv_t vc_fd; ///< Value for CONV_ICONV. -#endif bool vc_fail; ///< What to do with invalid characters: if true, fail, ///< otherwise use '?'. } vimconv_T; diff --git a/src/nvim/version.c b/src/nvim/version.c index 92122b2523..44f795cdf1 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -63,12 +63,6 @@ static char *features[] = { "-acl", #endif -#if defined(HAVE_ICONV) - "+iconv", -#else - "-iconv", -#endif - "+tui", NULL }; |