From b3d304df93347ef3f585ae91ae9ff6f5f28651af Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 31 Jan 2023 11:47:02 +0000 Subject: refactor(fileio.c): remove HAVE_ACL ifdefs --- src/nvim/os/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 302faa8140..8915b0de3e 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -788,6 +788,7 @@ int os_setperm(const char *const name, int perm) # ifdef HAVE_SYS_ACCESS_H # include # endif +#endif // Return a pointer to the ACL of file "fname" in allocated memory. // Return NULL if the ACL is not available for whatever reason. @@ -811,7 +812,6 @@ void os_free_acl(vim_acl_T aclent) return; } } -#endif #ifdef UNIX /// Checks if the current user owns a file. -- cgit From 6aee2336ca75301bd4db6b99c2392f63f8304335 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 31 Jan 2023 12:00:33 +0000 Subject: refactor(fileio.c): normalize ifdefs As well as improving readbability, this also avoids all Treesitter parsing errors which cannot handle elaborate use of the preprocessor. --- src/nvim/os/os_defs.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h index a30e16eeba..f86c0d3483 100644 --- a/src/nvim/os/os_defs.h +++ b/src/nvim/os/os_defs.h @@ -13,6 +13,12 @@ # include "nvim/os/unix_defs.h" #endif +#ifdef BACKSLASH_IN_FILENAME +# define BACKSLASH_IN_FILENAME_BOOL true +#else +# define BACKSLASH_IN_FILENAME_BOOL false +#endif + #if !defined(NAME_MAX) && defined(_XOPEN_NAME_MAX) # define NAME_MAX _XOPEN_NAME_MAX #endif -- cgit From 69bb145cea56067e6e82ed0a130a51c0d611e540 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 4 Feb 2023 20:14:31 +0800 Subject: refactor(exit): pass error message to preserve_exit() (#22097) Problem: 1. Some calls to preserve_exit() don't put a message in IObuff, so the IObuff printed by preserve_exit() contains unrelated information. 2. If a TUI client runs out of memory or receives a deadly signal, the error message is shown on alternate screen and cannot be easily seen because the TUI exits alternate screen soon afterwards. Solution: Pass error message to preserve_exit() and exit alternate screen before printing it. Note that this doesn't fix the problem that server error messages cannot be easily seen on exit. This is tracked in #21608 and #21843. --- src/nvim/os/input.c | 3 +-- src/nvim/os/signal.c | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 759b3cf83c..44ad0315a5 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -550,8 +550,7 @@ static void read_error_exit(void) if (silent_mode) { // Normal way to exit for "nvim -es". getout(0); } - STRCPY(IObuff, _("Vim: Error reading input, exiting...\n")); - preserve_exit(); + preserve_exit(_("Vim: Error reading input, exiting...\n")); } static bool pending_events(MultiQueue *events) diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index b8daaabba2..e7b745fb7e 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -172,11 +172,10 @@ static void deadly_signal(int signum) ILOG("got signal %d (%s)", signum, signal_name(signum)); - snprintf(IObuff, sizeof(IObuff), "Vim: Caught deadly signal '%s'\r\n", - signal_name(signum)); + snprintf(IObuff, IOSIZE, "Vim: Caught deadly signal '%s'\r\n", signal_name(signum)); // Preserve files and exit. - preserve_exit(); + preserve_exit(IObuff); } static void on_signal(SignalWatcher *handle, int signum, void *data) -- cgit From 7224c889e0d5d70b99ae377036baa6377c33a568 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:25:24 +0100 Subject: build: enable MSVC level 3 warnings (#21934) MSVC has 4 different warning levels: 1 (severe), 2 (significant), 3 (production quality) and 4 (informational). Enabling level 3 warnings mostly revealed conversion problems, similar to GCC/clang -Wconversion flag. --- src/nvim/os/env.c | 6 +++++- src/nvim/os/fileio.c | 4 ++++ src/nvim/os/fs.c | 21 ++++++++++----------- 3 files changed, 19 insertions(+), 12 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 0611de14aa..30092b9142 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -34,7 +34,11 @@ #include "nvim/vim.h" #ifdef MSWIN -# include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 +# include "nvim/mbyte.h" +#endif + +#ifdef BACKSLASH_IN_FILENAME +# include "nvim/fileio.h" #endif #ifdef HAVE__NSGETENVIRON diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index 5af39555c9..846219f720 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -27,6 +27,10 @@ #include "nvim/rbuffer.h" #include "nvim/types.h" +#ifdef MSWIN +# include "nvim/os/os_win_console.h" +#endif + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/fileio.c.generated.h" #endif diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 6157341ec9..85d95960a7 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -12,14 +12,20 @@ #include #include #include +#include #include "auto/config.h" +#include "nvim/ascii.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/log.h" #include "nvim/macros.h" +#include "nvim/memory.h" +#include "nvim/message.h" #include "nvim/option_defs.h" #include "nvim/os/fs_defs.h" +#include "nvim/os/os.h" +#include "nvim/path.h" #include "nvim/types.h" #include "nvim/vim.h" @@ -27,24 +33,17 @@ # include #endif -#include - -#include "nvim/ascii.h" -#include "nvim/memory.h" -#include "nvim/message.h" -#include "nvim/os/os.h" -#include "nvim/path.h" - -struct iovec; - #ifdef MSWIN -# include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 +# include "nvim/mbyte.h" +# include "nvim/option.h" #endif #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/fs.c.generated.h" #endif +struct iovec; + #define RUN_UV_FS_FUNC(ret, func, ...) \ do { \ bool did_try_to_free = false; \ -- cgit From 820430dc0bb84011edae801262e64a10be7ebb9d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 13 Feb 2023 16:33:20 +0800 Subject: fix(tui): exit on input eof --- src/nvim/os/input.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 44ad0315a5..d472836d0a 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -470,11 +470,6 @@ static InbufPollResult inbuf_poll(int ms, MultiQueue *events) return input_eof ? kInputEof : kInputNone; } -void input_done(void) -{ - input_eof = true; -} - bool input_available(void) { return rbuffer_size(input_buffer) != 0; @@ -483,7 +478,7 @@ bool input_available(void) static void input_read_cb(Stream *stream, RBuffer *buf, size_t c, void *data, bool at_eof) { if (at_eof) { - input_done(); + input_eof = true; } assert(rbuffer_space(input_buffer) >= rbuffer_size(buf)); -- cgit From d34c64e342dfba9248d1055e702d02620a1b31a8 Mon Sep 17 00:00:00 2001 From: Ghjuvan Lacambre Date: Thu, 16 Feb 2023 13:15:02 +0100 Subject: feat: $NVIM_APPNAME #22128 This commit implements the ability to control all of the XDG paths Neovim should use. This is done by setting an environment variable named NVIM_APPNAME. For example, setting $NVIM_APPNAME makes Neovim look for its configuration directory in $XDG_CONFIG_HOME/$NVIM_APPNAME instead of $XDG_CONFIG_HOME/nvim. If NVIM_APPNAME is not set or is an empty string, "nvim" will be used as default. The usecase for this feature is to enable an easy way to switch from configuration to configuration. One might argue that the various $XDG environment variables can already be used for this usecase. However, setting $XDG environment variables also affects tools spawned by Neovim. For example, while setting $XDG_CONFIG_HOME will enable Neovim to use a different configuration directory, it will also prevent Git from finding its "default" configuration. Closes https://github.com/neovim/neovim/issues/21691 --- src/nvim/os/stdpaths.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 6b07b6ef70..5235828f7a 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -57,6 +57,18 @@ static const char *const xdg_defaults[] = { #endif }; +/// Get the value of $NVIM_APPNAME or "nvim" if not set. +/// +/// @return $NVIM_APPNAME value +const char *get_appname(void) +{ + const char *env_val = os_getenv("NVIM_APPNAME"); + if (env_val == NULL || *env_val == '\0') { + env_val = "nvim"; + } + return env_val; +} + /// Return XDG variable value /// /// @param[in] idx XDG variable to use. @@ -100,25 +112,28 @@ char *stdpaths_get_xdg_var(const XDGVarType idx) /// Return Nvim-specific XDG directory subpath. /// -/// Windows: Uses "…/nvim-data" for kXDGDataHome to avoid storing +/// Windows: Uses "…/$NVIM_APPNAME-data" for kXDGDataHome to avoid storing /// configuration and data files in the same path. #4403 /// /// @param[in] idx XDG directory to use. /// -/// @return [allocated] "{xdg_directory}/nvim" +/// @return [allocated] "{xdg_directory}/$NVIM_APPNAME" char *get_xdg_home(const XDGVarType idx) FUNC_ATTR_WARN_UNUSED_RESULT { char *dir = stdpaths_get_xdg_var(idx); + const char *appname = get_appname(); + size_t appname_len = strlen(appname); + assert(appname_len < (IOSIZE - sizeof("-data"))); + if (dir) { + xstrlcpy(IObuff, appname, appname_len + 1); #if defined(MSWIN) - dir = concat_fnames_realloc(dir, - ((idx == kXDGDataHome - || idx == kXDGStateHome) ? "nvim-data" : "nvim"), - true); -#else - dir = concat_fnames_realloc(dir, "nvim", true); + if (idx == kXDGDataHome || idx == kXDGStateHome) { + STRCAT(IObuff, "-data"); + } #endif + dir = concat_fnames_realloc(dir, IObuff, true); #ifdef BACKSLASH_IN_FILENAME slash_adjust(dir); @@ -131,7 +146,7 @@ char *get_xdg_home(const XDGVarType idx) /// /// @param[in] fname New component of the path. /// -/// @return [allocated] `$XDG_CACHE_HOME/nvim/{fname}` +/// @return [allocated] `$XDG_CACHE_HOME/$NVIM_APPNAME/{fname}` char *stdpaths_user_cache_subpath(const char *fname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { @@ -142,7 +157,7 @@ char *stdpaths_user_cache_subpath(const char *fname) /// /// @param[in] fname New component of the path. /// -/// @return [allocated] `$XDG_CONFIG_HOME/nvim/{fname}` +/// @return [allocated] `$XDG_CONFIG_HOME/$NVIM_APPNAME/{fname}` char *stdpaths_user_conf_subpath(const char *fname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { @@ -153,7 +168,7 @@ char *stdpaths_user_conf_subpath(const char *fname) /// /// @param[in] fname New component of the path. /// -/// @return [allocated] `$XDG_DATA_HOME/nvim/{fname}` +/// @return [allocated] `$XDG_DATA_HOME/$NVIM_APPNAME/{fname}` char *stdpaths_user_data_subpath(const char *fname) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET { @@ -166,7 +181,7 @@ char *stdpaths_user_data_subpath(const char *fname) /// @param[in] trailing_pathseps Amount of trailing path separators to add. /// @param[in] escape_commas If true, all commas will be escaped. /// -/// @return [allocated] `$XDG_STATE_HOME/nvim/{fname}`. +/// @return [allocated] `$XDG_STATE_HOME/$NVIM_APPNAME/{fname}`. char *stdpaths_user_state_subpath(const char *fname, const size_t trailing_pathseps, const bool escape_commas) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET -- cgit From 1d8b77da6b0abe6dccd6ce64e283b7208f873d57 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 26 Feb 2023 01:12:41 +0100 Subject: fix(MSVC): set the active code page to utf-8 (#22384) Neovim expects character encoding to be UTF-8, and deviation from this causes bugs such as lua files not being recognized for non-ascii paths. This changes the behavior of fopen, which defaults to using the currently active codepage. Closes: https://github.com/neovim/neovim/issues/18122 --- src/nvim/os/nvim.manifest | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/nvim.manifest b/src/nvim/os/nvim.manifest index 8878822a5d..571b7f4580 100644 --- a/src/nvim/os/nvim.manifest +++ b/src/nvim/os/nvim.manifest @@ -17,4 +17,9 @@ + + + UTF-8 + + -- cgit From 166b149d5b473f277c63e64ced03c40df44ac3c9 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 27 Feb 2023 16:30:32 +0100 Subject: refactor(build): remove unused stdlib function and include checks In addition: merge some checks for the same feature into one test_compile. This reduces the total number of test compiles which speeds up the cmake configure stage. --- src/nvim/os/os_defs.h | 5 ++--- src/nvim/os/shell.c | 4 ++-- src/nvim/os/users.c | 10 +++++----- 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h index f86c0d3483..9e201f1dfa 100644 --- a/src/nvim/os/os_defs.h +++ b/src/nvim/os/os_defs.h @@ -36,10 +36,9 @@ // Command-processing buffer. Use large buffers for all platforms. #define CMDBUFFSIZE 1024 -// Note: Some systems need both string.h and strings.h (Savage). However, -// some systems can't handle both, only use string.h in that case. +// Note: Some systems need both string.h and strings.h (Savage). #include -#if defined(HAVE_STRINGS_H) && !defined(NO_STRINGS_WITH_STRING_H) +#ifdef HAVE_STRINGS_H # include #endif diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index f1e2c5440f..f7d1154169 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -399,8 +399,8 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in fclose(fd); return FAIL; } -#if SIZEOF_LONG_LONG > SIZEOF_SIZE_T - assert(templen <= (long long)SIZE_MAX); // NOLINT(runtime/int) +#if 8 > SIZEOF_SIZE_T + assert(templen <= SIZE_MAX); // NOLINT(runtime/int) #endif len = (size_t)templen; fseek(fd, 0L, SEEK_SET); diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index ef2986246b..411ba91fa7 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -15,7 +15,7 @@ #include "nvim/os/os.h" #include "nvim/types.h" #include "nvim/vim.h" -#ifdef HAVE_PWD_H +#ifdef HAVE_PWD_FUNCS # include #endif #ifdef MSWIN @@ -50,7 +50,7 @@ int os_get_usernames(garray_T *users) } ga_init(users, sizeof(char *), 20); -#if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H) +#ifdef HAVE_PWD_FUNCS { struct passwd *pw; @@ -81,7 +81,7 @@ int os_get_usernames(garray_T *users) } } #endif -#if defined(HAVE_GETPWNAM) +#ifdef HAVE_PWD_FUNCS { const char *user_env = os_getenv("USER"); @@ -141,7 +141,7 @@ int os_get_username(char *s, size_t len) /// @return OK if a username was found, else FAIL. int os_get_uname(uv_uid_t uid, char *s, size_t len) { -#if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID) +#ifdef HAVE_PWD_FUNCS struct passwd *pw; if ((pw = getpwuid(uid)) != NULL // NOLINT(runtime/threadsafe_fn) @@ -159,7 +159,7 @@ int os_get_uname(uv_uid_t uid, char *s, size_t len) /// Caller must free() the returned string. char *os_get_userdir(const char *name) { -#if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H) +#ifdef HAVE_PWD_FUNCS if (name == NULL || *name == NUL) { return NULL; } -- cgit From 1b3c1f6c06d73e881bfc2a46e5ee3e0b24ba96d8 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 27 Feb 2023 19:37:43 +0100 Subject: refactor(build): graduate HAVE_LOCALE_H feature Merge locale.h into os/lang.h Having a source file with the same name as a system header we use is considered an anti-pattern. --- src/nvim/os/lang.c | 343 ++++++++++++++++++++++++++++++++++++++++++++++++++++- src/nvim/os/lang.h | 3 + 2 files changed, 340 insertions(+), 6 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/lang.c b/src/nvim/os/lang.c index 57c82bba86..8ca2aa3a4b 100644 --- a/src/nvim/os/lang.c +++ b/src/nvim/os/lang.c @@ -7,16 +7,347 @@ # include # undef Boolean # undef FileInfo +#endif -# include "auto/config.h" -# ifdef HAVE_LOCALE_H -# include -# endif -# include "nvim/os/os.h" +#include +#include +#include + +#include "auto/config.h" +#include "nvim/ascii.h" +#include "nvim/buffer.h" +#include "nvim/charset.h" +#include "nvim/eval.h" +#include "nvim/ex_cmds_defs.h" +#include "nvim/garray.h" +#include "nvim/gettext.h" +#include "nvim/macros.h" +#include "nvim/memory.h" +#include "nvim/message.h" +#include "nvim/option.h" +#include "nvim/os/lang.h" +#include "nvim/os/os.h" +#include "nvim/os/shell.h" +#include "nvim/path.h" +#include "nvim/profile.h" +#include "nvim/types.h" +#include "nvim/vim.h" +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/lang.c.generated.h" #endif -#include "nvim/os/lang.h" +static char *get_locale_val(int what) +{ + // Obtain the locale value from the libraries. + char *loc = setlocale(what, NULL); + + return loc; +} + +/// @return true when "lang" starts with a valid language name. +/// Rejects NULL, empty string, "C", "C.UTF-8" and others. +static bool is_valid_mess_lang(const char *lang) +{ + return lang != NULL && ASCII_ISALPHA(lang[0]) && ASCII_ISALPHA(lang[1]); +} + +/// Obtain the current messages language. Used to set the default for +/// 'helplang'. May return NULL or an empty string. +char *get_mess_lang(void) +{ + char *p; + +#if defined(LC_MESSAGES) + p = get_locale_val(LC_MESSAGES); +#else + // This is necessary for Win32, where LC_MESSAGES is not defined and $LANG + // may be set to the LCID number. LC_COLLATE is the best guess, LC_TIME + // and LC_MONETARY may be set differently for a Japanese working in the + // US. + p = get_locale_val(LC_COLLATE); +#endif + return is_valid_mess_lang(p) ? p : NULL; +} + +// Complicated #if; matches with where get_mess_env() is used below. +#ifdef HAVE_WORKING_LIBINTL +/// Get the language used for messages from the environment. +static char *get_mess_env(void) +{ + char *p; + + p = (char *)os_getenv("LC_ALL"); + if (p == NULL) { + p = (char *)os_getenv("LC_MESSAGES"); + if (p == NULL) { + p = (char *)os_getenv("LANG"); + if (p != NULL && ascii_isdigit(*p)) { + p = NULL; // ignore something like "1043" + } + if (p == NULL) { + p = get_locale_val(LC_CTYPE); + } + } + } + return p; +} +#endif + +/// Set the "v:lang" variable according to the current locale setting. +/// Also do "v:lc_time"and "v:ctype". +void set_lang_var(void) +{ + const char *loc; + + loc = get_locale_val(LC_CTYPE); + set_vim_var_string(VV_CTYPE, loc, -1); + + // When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall + // back to LC_CTYPE if it's empty. +#ifdef HAVE_WORKING_LIBINTL + loc = get_mess_env(); +#elif defined(LC_MESSAGES) + loc = get_locale_val(LC_MESSAGES); +#else + // In Windows LC_MESSAGES is not defined fallback to LC_CTYPE + loc = get_locale_val(LC_CTYPE); +#endif + set_vim_var_string(VV_LANG, loc, -1); + + loc = get_locale_val(LC_TIME); + set_vim_var_string(VV_LC_TIME, loc, -1); + + loc = get_locale_val(LC_COLLATE); + set_vim_var_string(VV_COLLATE, loc, -1); +} + +/// Setup to use the current locale (for ctype() and many other things). +void init_locale(void) +{ + setlocale(LC_ALL, ""); + +#ifdef LC_NUMERIC + // Make sure strtod() uses a decimal point, not a comma. + setlocale(LC_NUMERIC, "C"); +#endif + + char localepath[MAXPATHL] = { 0 }; + snprintf(localepath, sizeof(localepath), "%s", get_vim_var_str(VV_PROGPATH)); + char *tail = path_tail_with_sep(localepath); + *tail = NUL; + tail = path_tail(localepath); + xstrlcpy(tail, "share/locale", + sizeof(localepath) - (size_t)(tail - localepath)); + bindtextdomain(PROJECT_NAME, localepath); + textdomain(PROJECT_NAME); + TIME_MSG("locale set"); +} + +#ifdef HAVE_WORKING_LIBINTL + +/// ":language": Set the language (locale). +/// +/// @param eap +void ex_language(exarg_T *eap) +{ + char *loc; + char *p; + char *name; + int what = LC_ALL; + char *whatstr = ""; +# ifdef LC_MESSAGES +# define VIM_LC_MESSAGES LC_MESSAGES +# else +# define VIM_LC_MESSAGES 6789 +# endif + + name = eap->arg; + + // Check for "messages {name}", "ctype {name}" or "time {name}" argument. + // Allow abbreviation, but require at least 3 characters to avoid + // confusion with a two letter language name "me" or "ct". + p = skiptowhite(eap->arg); + if ((*p == NUL || ascii_iswhite(*p)) && p - eap->arg >= 3) { + if (STRNICMP(eap->arg, "messages", p - eap->arg) == 0) { + what = VIM_LC_MESSAGES; + name = skipwhite(p); + whatstr = "messages "; + } else if (STRNICMP(eap->arg, "ctype", p - eap->arg) == 0) { + what = LC_CTYPE; + name = skipwhite(p); + whatstr = "ctype "; + } else if (STRNICMP(eap->arg, "time", p - eap->arg) == 0) { + what = LC_TIME; + name = skipwhite(p); + whatstr = "time "; + } else if (STRNICMP(eap->arg, "collate", p - eap->arg) == 0) { + what = LC_COLLATE; + name = skipwhite(p); + whatstr = "collate "; + } + } + + if (*name == NUL) { + if (what == VIM_LC_MESSAGES) { + p = get_mess_env(); + } else { + p = setlocale(what, NULL); + } + if (p == NULL || *p == NUL) { + p = "Unknown"; + } + smsg(_("Current %slanguage: \"%s\""), whatstr, p); + } else { +# ifndef LC_MESSAGES + if (what == VIM_LC_MESSAGES) { + loc = ""; + } else { +# endif + loc = setlocale(what, name); +# ifdef LC_NUMERIC + // Make sure strtod() uses a decimal point, not a comma. + setlocale(LC_NUMERIC, "C"); +# endif +# ifndef LC_MESSAGES + } +# endif + if (loc == NULL) { + semsg(_("E197: Cannot set language to \"%s\""), name); + } else { +# ifdef HAVE_NL_MSG_CAT_CNTR + // Need to do this for GNU gettext, otherwise cached translations + // will be used again. + extern int _nl_msg_cat_cntr; + + _nl_msg_cat_cntr++; +# endif + // Reset $LC_ALL, otherwise it would overrule everything. + os_setenv("LC_ALL", "", 1); + + if (what != LC_TIME && what != LC_COLLATE) { + // Tell gettext() what to translate to. It apparently doesn't + // use the currently effective locale. + if (what == LC_ALL) { + os_setenv("LANG", name, 1); + + // Clear $LANGUAGE because GNU gettext uses it. + os_setenv("LANGUAGE", "", 1); + } + if (what != LC_CTYPE) { + os_setenv("LC_MESSAGES", name, 1); + set_helplang_default(name); + } + } + + // Set v:lang, v:lc_time, v:collate and v:ctype to the final result. + set_lang_var(); + maketitle(); + } + } +} + +static char **locales = NULL; // Array of all available locales + +# ifndef MSWIN +static bool did_init_locales = false; + +/// @return an array of strings for all available locales + NULL for the +/// last element or, +/// NULL in case of error. +static char **find_locales(void) +{ + garray_T locales_ga; + char *loc; + char *saveptr = NULL; + + // Find all available locales by running command "locale -a". If this + // doesn't work we won't have completion. + char *locale_a = get_cmd_output("locale -a", NULL, kShellOptSilent, NULL); + if (locale_a == NULL) { + return NULL; + } + ga_init(&locales_ga, sizeof(char *), 20); + + // Transform locale_a string where each locale is separated by "\n" + // into an array of locale strings. + loc = os_strtok(locale_a, "\n", &saveptr); + + while (loc != NULL) { + loc = xstrdup(loc); + GA_APPEND(char *, &locales_ga, loc); + loc = os_strtok(NULL, "\n", &saveptr); + } + xfree(locale_a); + // Guarantee that .ga_data is NULL terminated + ga_grow(&locales_ga, 1); + ((char **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; + return locales_ga.ga_data; +} +# endif + +/// Lazy initialization of all available locales. +static void init_locales(void) +{ +# ifndef MSWIN + if (did_init_locales) { + return; + } + + did_init_locales = true; + locales = find_locales(); +# endif +} + +# if defined(EXITFREE) +void free_locales(void) +{ + if (locales == NULL) { + return; + } + + for (int i = 0; locales[i] != NULL; i++) { + xfree(locales[i]); + } + XFREE_CLEAR(locales); +} +# endif + +/// Function given to ExpandGeneric() to obtain the possible arguments of the +/// ":language" command. +char *get_lang_arg(expand_T *xp, int idx) +{ + if (idx == 0) { + return "messages"; + } + if (idx == 1) { + return "ctype"; + } + if (idx == 2) { + return "time"; + } + if (idx == 3) { + return "collate"; + } + + init_locales(); + if (locales == NULL) { + return NULL; + } + return locales[idx - 4]; +} + +/// Function given to ExpandGeneric() to obtain the available locales. +char *get_locales(expand_T *xp, int idx) +{ + init_locales(); + if (locales == NULL) { + return NULL; + } + return locales[idx]; +} + +#endif void lang_init(void) { diff --git a/src/nvim/os/lang.h b/src/nvim/os/lang.h index f60e064f57..bb1ebfb721 100644 --- a/src/nvim/os/lang.h +++ b/src/nvim/os/lang.h @@ -1,6 +1,9 @@ #ifndef NVIM_OS_LANG_H #define NVIM_OS_LANG_H +#include "nvim/ex_cmds_defs.h" +#include "nvim/types.h" + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/lang.h.generated.h" #endif -- cgit From d5f6176e6dc4b4e12fc5061ca6e87f4af533e46a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Sat, 1 Apr 2023 02:49:51 +0200 Subject: refactor: add const and remove unnecessary casts (#22841) --- src/nvim/os/env.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 30092b9142..5b8c060e7a 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -494,7 +494,7 @@ void init_homedir(void) // links. Don't do it when we can't return. if (os_dirname(os_buf, MAXPATHL) == OK && os_chdir(os_buf) == 0) { if (!os_chdir(var) && os_dirname(IObuff, IOSIZE) == OK) { - var = (char *)IObuff; + var = IObuff; } if (os_chdir(os_buf) != 0) { emsg(_(e_prev_dir)); -- cgit From 7190dba017e3aac0409c73ff1c954d18858cb3c9 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Thu, 6 Apr 2023 22:39:50 +0200 Subject: refactor: remove use of reserved c++ keywords libnvim couldn't be easily used in C++ due to the use of reserved keywords. Additionally, add explicit casts to *alloc function calls used in inline functions, as C++ doesn't allow implicit casts from void pointers. --- src/nvim/os/fs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 7eba5ca54c..cb51e81005 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -1014,17 +1014,17 @@ int os_file_mkdir(char *fname, int32_t mode) /// Create a unique temporary directory. /// -/// @param[in] template Template of the path to the directory with XXXXXX -/// which would be replaced by random chars. +/// @param[in] templ Template of the path to the directory with XXXXXX +/// which would be replaced by random chars. /// @param[out] path Path to created directory for success, undefined for /// failure. /// @return `0` for success, non-zero for failure. -int os_mkdtemp(const char *template, char *path) +int os_mkdtemp(const char *templ, char *path) FUNC_ATTR_NONNULL_ALL { uv_fs_t request; fs_loop_lock(); - int result = uv_fs_mkdtemp(&fs_loop, &request, template, NULL); + int result = uv_fs_mkdtemp(&fs_loop, &request, templ, NULL); fs_loop_unlock(); if (result == kLibuvSuccess) { xstrlcpy(path, request.path, TEMP_FILE_PATH_MAXLEN); -- cgit From 1d2a29f75ba7d094c8e7444c9b249a4a7211c93c Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:39:04 +0200 Subject: refactor: make char * parameters const in message.c Add const to char * parameters in message.c functions and remove some redundant casts. --- src/nvim/os/env.c | 4 ++-- src/nvim/os/shell.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 5b8c060e7a..b167bf02fd 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -1060,7 +1060,7 @@ size_t home_replace(const buf_T *const buf, const char *src, char *const dst, si } if (buf != NULL && buf->b_help) { - const size_t dlen = xstrlcpy(dst, path_tail((char *)src), dstlen); + const size_t dlen = xstrlcpy(dst, path_tail(src), dstlen); return MIN(dlen, dstlen - 1); } @@ -1098,7 +1098,7 @@ size_t home_replace(const buf_T *const buf, const char *src, char *const dst, si } if (!one) { - src = skipwhite((char *)src); + src = skipwhite(src); } char *dst_p = dst; while (*src && dstlen > 0) { diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index f7d1154169..e990db3296 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -876,7 +876,7 @@ static int do_os_system(char **argv, const char *input, size_t len, char **outpu // Failed, probably 'shell' is not executable. if (!silent) { msg_puts(_("\nshell failed to start: ")); - msg_outtrans((char *)os_strerror(status)); + msg_outtrans(os_strerror(status)); msg_puts(": "); msg_outtrans(prog); msg_putchar('\n'); -- cgit From 9408f2dcf7cade2631688300e9b58eed6bc5219a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:40:57 +0200 Subject: refactor: remove redundant const char * casts --- src/nvim/os/env.c | 4 ++-- src/nvim/os/shell.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index b167bf02fd..0b06877f3c 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -845,7 +845,7 @@ const void *vim_env_iter(const char delim, const char *const val, const void *co const char **const dir, size_t *const len) FUNC_ATTR_NONNULL_ARG(2, 4, 5) FUNC_ATTR_WARN_UNUSED_RESULT { - const char *varval = (const char *)iter; + const char *varval = iter; if (varval == NULL) { varval = val; } @@ -876,7 +876,7 @@ const void *vim_env_iter_rev(const char delim, const char *const val, const void const char **const dir, size_t *const len) FUNC_ATTR_NONNULL_ARG(2, 4, 5) FUNC_ATTR_WARN_UNUSED_RESULT { - const char *varend = (const char *)iter; + const char *varend = iter; if (varend == NULL) { varend = val + strlen(val) - 1; } diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index e990db3296..41b176eb41 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -1180,7 +1180,7 @@ static size_t tokenize(const char *const str, char **const argv) } argc++; - p = (const char *)skipwhite((p + len)); + p = skipwhite((p + len)); } return argc; -- cgit From 2d78e656b715119ca11d131a1a932f22f1b4ad36 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:43:00 +0200 Subject: refactor: remove redundant casts --- src/nvim/os/shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 41b176eb41..52cab63989 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -144,7 +144,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in bool is_fish_shell = #if defined(UNIX) - strncmp((char *)invocation_path_tail(p_sh, NULL), "fish", 4) == 0; + strncmp(invocation_path_tail(p_sh, NULL), "fish", 4) == 0; #else false; #endif -- cgit From d927128fccad1c234e4b87321ff0d6392b9d69d5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Apr 2023 13:03:04 +0800 Subject: vim-patch:8.2.1071: Vim9: no line break allowed inside a lambda Problem: Vim9: no line break allowed inside a lambda. Solution: Handle line break inside a lambda in Vim9 script. https://github.com/vim/vim/commit/e40fbc2ca9fda07332a4da5af1fcaba91bed865b Omit skip_expr_concatenate(). Apply the change to skip_expr() instead. Omit eval_ga: Vim9 script only. Co-authored-by: Bram Moolenaar --- src/nvim/os/env.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 0b06877f3c..26707fd6ca 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -603,7 +603,7 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es if (src[0] == '`' && src[1] == '=') { var = src; src += 2; - (void)skip_expr(&src); + (void)skip_expr(&src, NULL); if (*src == '`') { src++; } -- cgit From f39b33ee491a4a8d4b08425e582dd0dd53617edf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Apr 2023 11:46:17 +0800 Subject: vim-patch:9.0.0411: only created files can be cleaned up with one call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Only created files can be cleaned up with one call. Solution: Add flags to mkdir() to delete with a deferred function. Expand the writefile() name to a full path to handle changing directory. https://github.com/vim/vim/commit/6f14da15ac900589f2f413d77898b9bff3b31ece vim-patch:8.2.3742: dec mouse test fails without gnome terminfo entry Problem: Dec mouse test fails without gnome terminfo entry. Solution: Check if there is a gnome entry. Also fix 'acd' test on MS-Windows. (Dominique Pellé, closes vim/vim#9282) https://github.com/vim/vim/commit/f589fd3e1047cdf90566b68aaf9a13389e54d26a Cherry-pick test_autochdir.vim changes from patch 9.0.0313. Cherry-pick test_autocmd.vim changes from patch 9.0.0323. Co-authored-by: Bram Moolenaar --- src/nvim/os/fs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index cb51e81005..872d9c9314 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -937,10 +937,13 @@ int os_mkdir(const char *path, int32_t mode) /// the name of the directory which os_mkdir_recurse /// failed to create. I.e. it will contain dir or any /// of the higher level directories. +/// @param[out] created Set to the full name of the first created directory. +/// It will be NULL until that happens. /// /// @return `0` for success, libuv error code for failure. -int os_mkdir_recurse(const char *const dir, int32_t mode, char **const failed_dir) - FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT +int os_mkdir_recurse(const char *const dir, int32_t mode, char **const failed_dir, + char **const created) + FUNC_ATTR_NONNULL_ARG(1, 3) FUNC_ATTR_WARN_UNUSED_RESULT { // Get end of directory name in "dir". // We're done when it's "/" or "c:/". @@ -975,6 +978,8 @@ int os_mkdir_recurse(const char *const dir, int32_t mode, char **const failed_di if ((ret = os_mkdir(curdir, mode)) != 0) { *failed_dir = curdir; return ret; + } else if (created != NULL && *created == NULL) { + *created = FullName_save(curdir, false); } } xfree(curdir); @@ -1002,7 +1007,7 @@ int os_file_mkdir(char *fname, int32_t mode) *tail = NUL; int r; char *failed_dir; - if (((r = os_mkdir_recurse(fname, mode, &failed_dir)) < 0)) { + if (((r = os_mkdir_recurse(fname, mode, &failed_dir, NULL)) < 0)) { semsg(_(e_mkdir), failed_dir, os_strerror(r)); xfree(failed_dir); } -- cgit From 706f871014b46300180156590ff269ee38473989 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 19 Apr 2023 17:04:00 +0100 Subject: build: update uncrustify to 0.76 --- src/nvim/os/os_defs.h | 14 +++++++------- src/nvim/os/pty_process_win.c | 6 ++++-- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h index 9e201f1dfa..c595013a21 100644 --- a/src/nvim/os/os_defs.h +++ b/src/nvim/os/os_defs.h @@ -57,49 +57,49 @@ // stat macros #ifndef S_ISDIR # ifdef S_IFDIR -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +# define S_ISDIR(m) (((m)& S_IFMT) == S_IFDIR) # else # define S_ISDIR(m) 0 # endif #endif #ifndef S_ISREG # ifdef S_IFREG -# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +# define S_ISREG(m) (((m)& S_IFMT) == S_IFREG) # else # define S_ISREG(m) 0 # endif #endif #ifndef S_ISBLK # ifdef S_IFBLK -# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) +# define S_ISBLK(m) (((m)& S_IFMT) == S_IFBLK) # else # define S_ISBLK(m) 0 # endif #endif #ifndef S_ISSOCK # ifdef S_IFSOCK -# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) +# define S_ISSOCK(m) (((m)& S_IFMT) == S_IFSOCK) # else # define S_ISSOCK(m) 0 # endif #endif #ifndef S_ISFIFO # ifdef S_IFIFO -# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) +# define S_ISFIFO(m) (((m)& S_IFMT) == S_IFIFO) # else # define S_ISFIFO(m) 0 # endif #endif #ifndef S_ISCHR # ifdef S_IFCHR -# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +# define S_ISCHR(m) (((m)& S_IFMT) == S_IFCHR) # else # define S_ISCHR(m) 0 # endif #endif #ifndef S_ISLNK # ifdef S_IFLNK -# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) +# define S_ISLNK(m) (((m)& S_IFMT) == S_IFLNK) # else # define S_ISLNK(m) 0 # endif diff --git a/src/nvim/os/pty_process_win.c b/src/nvim/os/pty_process_win.c index 6233a90638..2e850f8c22 100644 --- a/src/nvim/os/pty_process_win.c +++ b/src/nvim/os/pty_process_win.c @@ -172,11 +172,13 @@ void pty_process_close(PtyProcess *ptyproc) void pty_process_close_master(PtyProcess *ptyproc) FUNC_ATTR_NONNULL_ALL -{} +{ +} void pty_process_teardown(Loop *loop) FUNC_ATTR_NONNULL_ALL -{} +{ +} static void pty_process_connect_cb(uv_connect_t *req, int status) FUNC_ATTR_NONNULL_ALL -- cgit From b773a525157393fca26967bd400edf137839e545 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 20 Apr 2023 18:54:00 +0200 Subject: refactor(env): remove unused mutex This was needed when TUI was a thread. lua code uses os_getenv only on the main thread. --- src/nvim/os/env.c | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 26707fd6ca..ad98a5b97e 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -52,22 +52,6 @@ // Because `uv_os_getenv` requires allocating, we must manage a map to maintain // the behavior of `os_getenv`. static PMap(cstr_t) envmap = MAP_INIT; -static uv_mutex_t mutex; - -void env_init(void) -{ - uv_mutex_init(&mutex); -} - -void os_env_var_lock(void) -{ - uv_mutex_lock(&mutex); -} - -void os_env_var_unlock(void) -{ - uv_mutex_unlock(&mutex); -} /// Like getenv(), but returns NULL if the variable is empty. /// @see os_env_exists @@ -79,7 +63,6 @@ const char *os_getenv(const char *name) if (name[0] == '\0') { return NULL; } - uv_mutex_lock(&mutex); int r = 0; if (pmap_has(cstr_t)(&envmap, name) && !!(e = (char *)pmap_get(cstr_t)(&envmap, name))) { @@ -105,8 +88,6 @@ const char *os_getenv(const char *name) } pmap_put(cstr_t)(&envmap, xstrdup(name), e); end: - // Must do this before ELOG, log.c may call os_setenv. - uv_mutex_unlock(&mutex); if (r != 0 && r != UV_ENOENT && r != UV_UNKNOWN) { ELOG("uv_os_getenv(%s) failed: %d %s", name, r, uv_err_name(r)); } @@ -158,7 +139,6 @@ int os_setenv(const char *name, const char *value, int overwrite) return 0; } #endif - uv_mutex_lock(&mutex); int r; #ifdef MSWIN // libintl uses getenv() for LC_ALL/LANG/etc., so we must use _putenv_s(). @@ -173,8 +153,6 @@ int os_setenv(const char *name, const char *value, int overwrite) // Destroy the old map item. Do this AFTER uv_os_setenv(), because `value` // could be a previous os_getenv() result. pmap_del2(&envmap, name); - // Must do this before ELOG, log.c may call os_setenv. - uv_mutex_unlock(&mutex); if (r != 0) { ELOG("uv_os_setenv(%s) failed: %d %s", name, r, uv_err_name(r)); } @@ -188,11 +166,8 @@ int os_unsetenv(const char *name) if (name[0] == '\0') { return -1; } - uv_mutex_lock(&mutex); pmap_del2(&envmap, name); int r = uv_os_unsetenv(name); - // Must do this before ELOG, log.c may call os_setenv. - uv_mutex_unlock(&mutex); if (r != 0) { ELOG("uv_os_unsetenv(%s) failed: %d %s", name, r, uv_err_name(r)); } @@ -519,10 +494,8 @@ static char *os_homedir(void) { homedir_buf[0] = NUL; size_t homedir_size = MAXPATHL; - uv_mutex_lock(&mutex); // http://docs.libuv.org/en/v1.x/misc.html#c.uv_os_homedir int ret_value = uv_os_homedir(homedir_buf, &homedir_size); - uv_mutex_unlock(&mutex); if (ret_value == 0 && homedir_size < MAXPATHL) { return homedir_buf; } -- cgit From 0d2fe7786537ef63d0d3ed1e94546eb3ee35a368 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 23 Apr 2023 19:02:23 +0200 Subject: refactor(time): refactor delay with input checking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, there were three low-level delay entry points - os_delay(ms, ignoreinput=true): sleep for ms, only break on got_int - os_delay(ms, ignoreinput=false): sleep for ms, break on any key input os_microdelay(us, false): equivalent, but in μs (not directly called) - os_microdelay(us, true): sleep for μs, never break. The implementation of the latter two both used uv_cond_timedwait() This could have been for two reasons: 1. allow another thread to "interrupt" the wait 2. uv_cond_timedwait() has higher resolution than uv_sleep() However we (1) never used the first, even when TUI was a thread, and (2) nowhere in the codebase are we using μs resolution, it is always a ms multiplied with 1000. In addition, os_delay(ms, false) would completely block the thread for 100ms intervals and in between check for input. This is not how event handling is done alound here. Therefore: Replace the implementation of os_delay(ms, false) to use LOOP_PROCESS_EVENTS_UNTIL which does a proper epoll wait with a timeout, instead of the 100ms timer panic. Replace os_microdelay(us, false) with a direct wrapper of uv_sleep. --- src/nvim/os/input.c | 10 ++++----- src/nvim/os/time.c | 63 +++++++++++------------------------------------------ 2 files changed, 18 insertions(+), 55 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index d472836d0a..e9f23eba40 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -441,7 +441,7 @@ bool input_blocking(void) // This is a replacement for the old `WaitForChar` function in os_unix.c static InbufPollResult inbuf_poll(int ms, MultiQueue *events) { - if (input_ready(events)) { + if (os_input_ready(events)) { return kInputAvail; } @@ -457,14 +457,14 @@ static InbufPollResult inbuf_poll(int ms, MultiQueue *events) DLOG("blocking... events_enabled=%d events_pending=%d", events != NULL, events && !multiqueue_empty(events)); LOOP_PROCESS_EVENTS_UNTIL(&main_loop, NULL, ms, - input_ready(events) || input_eof); + os_input_ready(events) || input_eof); blocking = false; if (do_profiling == PROF_YES && ms) { prof_inchar_exit(); } - if (input_ready(events)) { + if (os_input_ready(events)) { return kInputAvail; } return input_eof ? kInputEof : kInputNone; @@ -530,8 +530,8 @@ static int push_event_key(uint8_t *buf, int maxlen) return buf_idx; } -// Check if there's pending input -static bool input_ready(MultiQueue *events) +/// Check if there's pending input already in typebuf or `events` +bool os_input_ready(MultiQueue *events) { return (typebuf_was_filled // API call filled typeahead || rbuffer_size(input_buffer) // Input buffer filled diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index 873302a27d..8d77e58177 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -24,20 +24,10 @@ struct tm; -static uv_mutex_t delay_mutex; -static uv_cond_t delay_cond; - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/time.c.generated.h" // IWYU pragma: export #endif -/// Initializes the time module -void time_init(void) -{ - uv_mutex_init(&delay_mutex); - uv_cond_init(&delay_cond); -} - /// Gets a high-resolution (nanosecond), monotonically-increasing time relative /// to an arbitrary time in the past. /// @@ -73,55 +63,28 @@ uint64_t os_now(void) void os_delay(uint64_t ms, bool ignoreinput) { DLOG("%" PRIu64 " ms", ms); - if (ignoreinput) { - if (ms > INT_MAX) { - ms = INT_MAX; - } - LOOP_PROCESS_EVENTS_UNTIL(&main_loop, NULL, (int)ms, got_int); - } else { - os_microdelay(ms * 1000U, ignoreinput); + if (ms > INT_MAX) { + ms = INT_MAX; } + LOOP_PROCESS_EVENTS_UNTIL(&main_loop, NULL, (int)ms, + ignoreinput ? got_int : os_input_ready(NULL)); } -/// Sleeps for `us` microseconds. +/// Sleeps for `ms` milliseconds without checking for events or interrupts. +/// +/// This blocks even "fast" events which is quite disruptive. This should only +/// be used in debug code. Prefer os_delay() and decide if the delay should be +/// interupted by input or only a CTRL-C. /// /// @see uv_sleep() (libuv v1.34.0) /// /// @param us Number of microseconds to sleep. -/// @param ignoreinput If true, ignore all input (including SIGINT/CTRL-C). -/// If false, waiting is aborted on any input. -void os_microdelay(uint64_t us, bool ignoreinput) +void os_sleep(uint64_t ms) { - uint64_t elapsed = 0U; - uint64_t base = uv_hrtime(); - // Convert microseconds to nanoseconds, or UINT64_MAX on overflow. - const uint64_t ns = (us < UINT64_MAX / 1000U) ? us * 1000U : UINT64_MAX; - - uv_mutex_lock(&delay_mutex); - - while (elapsed < ns) { - // If ignoring input, we simply wait the full delay. - // Else we check for input in ~100ms intervals. - const uint64_t ns_delta = ignoreinput - ? ns - elapsed - : MIN(ns - elapsed, 100000000U); // 100ms - - const int rv = uv_cond_timedwait(&delay_cond, &delay_mutex, ns_delta); - if (0 != rv && UV_ETIMEDOUT != rv) { - abort(); - break; - } // Else: Timeout proceeded normally. - - if (!ignoreinput && os_char_avail()) { - break; - } - - const uint64_t now = uv_hrtime(); - elapsed += now - base; - base = now; + if (ms > UINT_MAX) { + ms = UINT_MAX; } - - uv_mutex_unlock(&delay_mutex); + uv_sleep((unsigned)ms); } // Cache of the current timezone name as retrieved from TZ, or an empty string -- cgit From 5e569a47031d2a5b94cfadd67d5e76ba4651ac4d Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 25 Apr 2023 13:39:28 +0200 Subject: refactor(fs): now it is time to get rid of fs_loop and fs_loop_mutex Here's the headline: when run in sync mode (last argument cb=NULL), these functions don't actually use the uv_loop_t. An earlier version of this patch instead replaced fs_loop with using main_loop.uv on the main thread and luv_loop() on luv worker threads. However this made the code more complicated for no reason. Also arbitrarily, half of these functions would attempt to handle UV_ENOMEM by try_to_free_memory(). This would mostly happen on windows because it needs to allocate a converted WCHAR buffer. This should be a quite rare situation. Your system is pretty much hosed already if you cannot allocate like 50 WCHAR:s. Therefore, take the liberty of simply removing this fallback. In addition, we tried to "recover" from ENOMEM in read()/readv() this way which doesn't make any sense. The read buffer(s) are already allocated at this point. This would also be an issue when using these functions on a worker thread, as try_to_free_memory() is not thread-safe. Currently os_file_is_readable() and os_is_dir() is used by worker threads (as part of nvim__get_runtime(), to implement require from 'rtp' in threads). In the end, these changes makes _all_ os/fs.c functions thread-safe, and we thus don't need to document and maintain a thread-safe subset. --- src/nvim/os/fs.c | 73 +++++++------------------------------------------------- 1 file changed, 9 insertions(+), 64 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 872d9c9314..b13afba727 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -20,6 +20,7 @@ #include "nvim/globals.h" #include "nvim/log.h" #include "nvim/macros.h" +#include "nvim/main.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_defs.h" @@ -46,44 +47,13 @@ struct iovec; #define RUN_UV_FS_FUNC(ret, func, ...) \ do { \ - bool did_try_to_free = false; \ -uv_call_start: {} \ uv_fs_t req; \ - fs_loop_lock(); \ - ret = func(&fs_loop, &req, __VA_ARGS__); \ + ret = func(NULL, &req, __VA_ARGS__); \ uv_fs_req_cleanup(&req); \ - fs_loop_unlock(); \ - if (ret == UV_ENOMEM && !did_try_to_free) { \ - try_to_free_memory(); \ - did_try_to_free = true; \ - goto uv_call_start; \ - } \ } while (0) // Many fs functions from libuv return that value on success. static const int kLibuvSuccess = 0; -static uv_loop_t fs_loop; -static uv_mutex_t fs_loop_mutex; - -// Initialize the fs module -void fs_init(void) -{ - uv_loop_init(&fs_loop); - uv_mutex_init_recursive(&fs_loop_mutex); -} - -/// TODO(bfredl): some of these operations should -/// be possible to do the private libuv loop of the -/// thread, instead of contending the global fs loop -void fs_loop_lock(void) -{ - uv_mutex_lock(&fs_loop_mutex); -} - -void fs_loop_unlock(void) -{ - uv_mutex_unlock(&fs_loop_mutex); -} /// Changes the current directory to `path`. /// @@ -122,12 +92,9 @@ bool os_isrealdir(const char *name) FUNC_ATTR_NONNULL_ALL { uv_fs_t request; - fs_loop_lock(); - if (uv_fs_lstat(&fs_loop, &request, name, NULL) != kLibuvSuccess) { - fs_loop_unlock(); + if (uv_fs_lstat(NULL, &request, name, NULL) != kLibuvSuccess) { return false; } - fs_loop_unlock(); if (S_ISLNK(request.statbuf.st_mode)) { return false; } @@ -566,7 +533,6 @@ ptrdiff_t os_read(const int fd, bool *const ret_eof, char *const ret_buf, const return 0; } size_t read_bytes = 0; - bool did_try_to_free = false; while (read_bytes != size) { assert(size >= read_bytes); const ptrdiff_t cur_read_bytes = read(fd, ret_buf + read_bytes, @@ -581,10 +547,6 @@ ptrdiff_t os_read(const int fd, bool *const ret_eof, char *const ret_buf, const break; } else if (error == UV_EINTR || error == UV_EAGAIN) { continue; - } else if (error == UV_ENOMEM && !did_try_to_free) { - try_to_free_memory(); - did_try_to_free = true; - continue; } else { return (ptrdiff_t)error; } @@ -618,7 +580,6 @@ ptrdiff_t os_readv(const int fd, bool *const ret_eof, struct iovec *iov, size_t { *ret_eof = false; size_t read_bytes = 0; - bool did_try_to_free = false; size_t toread = 0; for (size_t i = 0; i < iov_size; i++) { // Overflow, trying to read too much data @@ -650,10 +611,6 @@ ptrdiff_t os_readv(const int fd, bool *const ret_eof, struct iovec *iov, size_t break; } else if (error == UV_EINTR || error == UV_EAGAIN) { continue; - } else if (error == UV_ENOMEM && !did_try_to_free) { - try_to_free_memory(); - did_try_to_free = true; - continue; } else { return (ptrdiff_t)error; } @@ -742,9 +699,7 @@ static int os_stat(const char *name, uv_stat_t *statbuf) return UV_EINVAL; } uv_fs_t request; - fs_loop_lock(); - int result = uv_fs_stat(&fs_loop, &request, name, NULL); - fs_loop_unlock(); + int result = uv_fs_stat(NULL, &request, name, NULL); if (result == kLibuvSuccess) { *statbuf = request.statbuf; } @@ -1028,9 +983,7 @@ int os_mkdtemp(const char *templ, char *path) FUNC_ATTR_NONNULL_ALL { uv_fs_t request; - fs_loop_lock(); - int result = uv_fs_mkdtemp(&fs_loop, &request, templ, NULL); - fs_loop_unlock(); + int result = uv_fs_mkdtemp(NULL, &request, templ, NULL); if (result == kLibuvSuccess) { xstrlcpy(path, request.path, TEMP_FILE_PATH_MAXLEN); } @@ -1057,9 +1010,7 @@ int os_rmdir(const char *path) bool os_scandir(Directory *dir, const char *path) FUNC_ATTR_NONNULL_ALL { - fs_loop_lock(); - int r = uv_fs_scandir(&fs_loop, &dir->request, path, 0, NULL); - fs_loop_unlock(); + int r = uv_fs_scandir(NULL, &dir->request, path, 0, NULL); if (r < 0) { os_closedir(dir); } @@ -1120,9 +1071,7 @@ bool os_fileinfo_link(const char *path, FileInfo *file_info) return false; } uv_fs_t request; - fs_loop_lock(); - bool ok = uv_fs_lstat(&fs_loop, &request, path, NULL) == kLibuvSuccess; - fs_loop_unlock(); + bool ok = uv_fs_lstat(NULL, &request, path, NULL) == kLibuvSuccess; if (ok) { file_info->stat = request.statbuf; } @@ -1140,8 +1089,7 @@ bool os_fileinfo_fd(int file_descriptor, FileInfo *file_info) { uv_fs_t request; CLEAR_POINTER(file_info); - fs_loop_lock(); - bool ok = uv_fs_fstat(&fs_loop, + bool ok = uv_fs_fstat(NULL, &request, file_descriptor, NULL) == kLibuvSuccess; @@ -1149,7 +1097,6 @@ bool os_fileinfo_fd(int file_descriptor, FileInfo *file_info) file_info->stat = request.statbuf; } uv_fs_req_cleanup(&request); - fs_loop_unlock(); return ok; } @@ -1266,8 +1213,7 @@ char *os_realpath(const char *name, char *buf) FUNC_ATTR_NONNULL_ARG(1) { uv_fs_t request; - fs_loop_lock(); - int result = uv_fs_realpath(&fs_loop, &request, name, NULL); + int result = uv_fs_realpath(NULL, &request, name, NULL); if (result == kLibuvSuccess) { if (buf == NULL) { buf = xmallocz(MAXPATHL); @@ -1275,7 +1221,6 @@ char *os_realpath(const char *name, char *buf) xstrlcpy(buf, request.ptr, MAXPATHL + 1); } uv_fs_req_cleanup(&request); - fs_loop_unlock(); return result == kLibuvSuccess ? buf : NULL; } -- cgit From 3b0df1780e2c8526bda5dead18ee7cc45925caba Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:23:44 +0200 Subject: refactor: uncrustify Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`. --- src/nvim/os/env.c | 2 +- src/nvim/os/fs.c | 2 +- src/nvim/os/input.c | 4 ++-- src/nvim/os/process.c | 2 +- src/nvim/os/shell.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index ad98a5b97e..f931e00916 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -1084,7 +1084,7 @@ size_t home_replace(const buf_T *const buf, const char *src, char *const dst, si // er's home directory)). char *p = homedir; size_t len = dirlen; - for (;;) { + while (true) { if (len && path_fnamencmp(src, p, len) == 0 && (vim_ispathsep(src[len]) diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index b13afba727..d270f8767e 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -339,7 +339,7 @@ static bool is_executable_in_path(const char *name, char **abspath) // is an executable file. char *p = path; bool rv = false; - for (;;) { + while (true) { char *e = xstrchrnul(p, ENV_SEPCHAR); // Combine the $PATH segment with `name`. diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index e9f23eba40..fa9ff6e9b1 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -253,7 +253,7 @@ size_t input_enqueue(String keys) // K_SPECIAL(0x80). uint8_t buf[19] = { 0 }; // Do not simplify the keys here. Simplification will be done later. - unsigned int new_size + unsigned new_size = trans_special((const char **)&ptr, (size_t)(end - ptr), (char *)buf, FSK_KEYCODE, true, NULL); @@ -346,7 +346,7 @@ static uint8_t check_multiclick(int code, int grid, int row, int col) // Mouse event handling code(Extract row/col if available and detect multiple // clicks) -static unsigned int handle_mouse_event(char **ptr, uint8_t *buf, unsigned int bufsize) +static unsigned handle_mouse_event(char **ptr, uint8_t *buf, unsigned bufsize) { int mouse_code = 0; int type = 0; diff --git a/src/nvim/os/process.c b/src/nvim/os/process.c index f4d95e141b..2a248a1e32 100644 --- a/src/nvim/os/process.c +++ b/src/nvim/os/process.c @@ -72,7 +72,7 @@ static bool os_proc_tree_kill_rec(HANDLE process, int sig) } theend: - return (bool)TerminateProcess(process, (unsigned int)sig); + return (bool)TerminateProcess(process, (unsigned)sig); } /// Kills process `pid` and its descendants recursively. bool os_proc_tree_kill(int pid, int sig) diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 52cab63989..979c6153aa 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -1225,7 +1225,7 @@ static void read_input(DynamicBuffer *buf) linenr_T lnum = curbuf->b_op_start.lnum; char *lp = ml_get(lnum); - for (;;) { + while (true) { l = strlen(lp + written); if (l == 0) { len = 0; -- cgit From 6a273af10517d1f7e4ea85635f1d25a9158adeb5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 13 May 2023 10:40:53 +0800 Subject: refactor: remove typval.h from most header files (#23601) Because typval_defs.h is enough for most of them. --- src/nvim/os/pty_process_win.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/pty_process_win.c b/src/nvim/os/pty_process_win.c index 2e850f8c22..a8330acd54 100644 --- a/src/nvim/os/pty_process_win.c +++ b/src/nvim/os/pty_process_win.c @@ -6,6 +6,7 @@ #include #include "nvim/ascii.h" +#include "nvim/eval/typval.h" #include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 #include "nvim/memory.h" #include "nvim/os/os.h" -- cgit From 08991b078267e5de0a19a136d00d4f71ad651a32 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 13 May 2023 21:33:22 +0200 Subject: docs: small fixes Co-authored-by: Christian Clason Co-authored-by: Gregory Anders Co-authored-by: HiPhish Co-authored-by: Julio B Co-authored-by: T727 <74924917+T-727@users.noreply.github.com> Co-authored-by: camoz Co-authored-by: champignoom <66909116+champignoom@users.noreply.github.com> --- src/nvim/os/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index 8d77e58177..0c3b254b9a 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -74,7 +74,7 @@ void os_delay(uint64_t ms, bool ignoreinput) /// /// This blocks even "fast" events which is quite disruptive. This should only /// be used in debug code. Prefer os_delay() and decide if the delay should be -/// interupted by input or only a CTRL-C. +/// interrupted by input or only a CTRL-C. /// /// @see uv_sleep() (libuv v1.34.0) /// -- cgit From d36dd2bae8e899b40cc21603e600a5046213bc36 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Tue, 16 May 2023 05:33:03 +0200 Subject: refactor: use xstrl{cpy,cat} on IObuff (#23648) Replace usage of STR{CPY,CAT} with xstrl{cpy,cat} when using on IObuff Co-authored-by: ii14 --- src/nvim/os/stdpaths.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 5235828f7a..8b62b9e895 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -130,7 +130,7 @@ char *get_xdg_home(const XDGVarType idx) xstrlcpy(IObuff, appname, appname_len + 1); #if defined(MSWIN) if (idx == kXDGDataHome || idx == kXDGStateHome) { - STRCAT(IObuff, "-data"); + xstrlcat(IObuff, "-data", IOSIZE); } #endif dir = concat_fnames_realloc(dir, IObuff, true); -- cgit From cfd4fdfea4d0e68ea50ad412b88b5289ded6fd6f Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Tue, 23 May 2023 14:25:10 +0600 Subject: refactor(api): new helper macros Adds new API helper macros `CSTR_AS_OBJ()`, `STATIC_CSTR_AS_OBJ()`, and `STATIC_CSTR_TO_OBJ()`, which cleans up a lot of the current code. These macros will also be used extensively in the upcoming option refactor PRs because then API Objects will be used to get/set options. This PR also modifies pre-existing code to use old API helper macros like `CSTR_TO_OBJ()` to make them cleaner. --- src/nvim/os/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/process.c b/src/nvim/os/process.c index 2a248a1e32..98ae251e2b 100644 --- a/src/nvim/os/process.c +++ b/src/nvim/os/process.c @@ -254,7 +254,7 @@ Dictionary os_proc_info(int pid) if (pe.th32ProcessID == (DWORD)pid) { PUT(pinfo, "pid", INTEGER_OBJ(pid)); PUT(pinfo, "ppid", INTEGER_OBJ((int)pe.th32ParentProcessID)); - PUT(pinfo, "name", STRING_OBJ(cstr_to_string(pe.szExeFile))); + PUT(pinfo, "name", CSTR_TO_OBJ(pe.szExeFile)); } return pinfo; -- cgit From 5a3752889c5b7e18d1041eb873ca2fa9ceb814bd Mon Sep 17 00:00:00 2001 From: Ghjuvan Lacambre Date: Sun, 28 May 2023 16:04:54 +0200 Subject: fix(NVIM_APPNAME): show error message if $NVIM_APPNAME is invalid Closes https://github.com/neovim/neovim/issues/23056. --- src/nvim/os/stdpaths.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 8b62b9e895..53ddda22fa 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -69,6 +69,19 @@ const char *get_appname(void) return env_val; } +/// Ensure that APPNAME is valid. In particular, it cannot contain directory separators. +bool appname_is_valid(void) +{ + const char *appname = get_appname(); + const size_t appname_len = strlen(appname); + for (size_t i = 0; i < appname_len; i++) { + if (appname[i] == PATHSEP) { + return false; + } + } + return true; +} + /// Return XDG variable value /// /// @param[in] idx XDG variable to use. -- cgit From f5d12889e80d3369359b8248806694cf6d21f820 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 6 Jun 2023 14:00:32 +0200 Subject: refactor: adjust headers according to the style guide (#23934) System headers should be included first to prevent naming conflicts. --- src/nvim/os/fs.c | 24 +++++++++++++----------- src/nvim/os/os_defs.h | 12 ++++++------ src/nvim/os/process.c | 14 ++++++++------ src/nvim/os/pty_process_unix.c | 3 +-- src/nvim/os/pty_process_win.c | 2 +- src/nvim/os/signal.c | 2 +- 6 files changed, 30 insertions(+), 27 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index d270f8767e..6c3eca8961 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -14,6 +14,19 @@ #include #include +#ifdef MSWIN +# include +#endif + +#if defined(HAVE_ACL) +# ifdef HAVE_SYS_ACL_H +# include +# endif +# ifdef HAVE_SYS_ACCESS_H +# include +# endif +#endif + #include "auto/config.h" #include "nvim/ascii.h" #include "nvim/gettext.h" @@ -731,15 +744,6 @@ int os_setperm(const char *const name, int perm) return (r == kLibuvSuccess ? OK : FAIL); } -#if defined(HAVE_ACL) -# ifdef HAVE_SYS_ACL_H -# include -# endif -# ifdef HAVE_SYS_ACCESS_H -# include -# endif -#endif - // Return a pointer to the ACL of file "fname" in allocated memory. // Return NULL if the ACL is not available for whatever reason. vim_acl_T os_get_acl(const char *fname) @@ -1225,8 +1229,6 @@ char *os_realpath(const char *name, char *buf) } #ifdef MSWIN -# include - /// When "fname" is the name of a shortcut (*.lnk) resolve the file it points /// to and return that name in allocated memory. /// Otherwise NULL is returned. diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h index c595013a21..1e0f5b77f8 100644 --- a/src/nvim/os/os_defs.h +++ b/src/nvim/os/os_defs.h @@ -7,6 +7,12 @@ #include #include +// Note: Some systems need both string.h and strings.h (Savage). +#include +#ifdef HAVE_STRINGS_H +# include +#endif + #ifdef MSWIN # include "nvim/os/win_defs.h" #else @@ -36,12 +42,6 @@ // Command-processing buffer. Use large buffers for all platforms. #define CMDBUFFSIZE 1024 -// Note: Some systems need both string.h and strings.h (Savage). -#include -#ifdef HAVE_STRINGS_H -# include -#endif - /// Converts libuv error (negative int) to error description string. #define os_strerror uv_strerror diff --git a/src/nvim/os/process.c b/src/nvim/os/process.c index 98ae251e2b..a636689f97 100644 --- a/src/nvim/os/process.c +++ b/src/nvim/os/process.c @@ -13,14 +13,8 @@ #include #include -#include "nvim/log.h" -#include "nvim/memory.h" -#include "nvim/os/process.h" - #ifdef MSWIN # include - -# include "nvim/api/private/helpers.h" #endif #if defined(__FreeBSD__) // XXX: OpenBSD ? @@ -38,6 +32,14 @@ # include #endif +#include "nvim/log.h" +#include "nvim/memory.h" +#include "nvim/os/process.h" + +#ifdef MSWIN +# include "nvim/api/private/helpers.h" +#endif + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/process.c.generated.h" // IWYU pragma: export #endif diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c index 2413f0339b..b5423c59d7 100644 --- a/src/nvim/os/pty_process_unix.c +++ b/src/nvim/os/pty_process_unix.c @@ -11,6 +11,7 @@ #include #include #include +#include // forkpty is not in POSIX, so headers are platform-specific #if defined(__FreeBSD__) || defined(__DragonFly__) @@ -31,8 +32,6 @@ # include #endif -#include - #include "auto/config.h" #include "klib/klist.h" #include "nvim/eval/typval.h" diff --git a/src/nvim/os/pty_process_win.c b/src/nvim/os/pty_process_win.c index a8330acd54..abeb020645 100644 --- a/src/nvim/os/pty_process_win.c +++ b/src/nvim/os/pty_process_win.c @@ -7,7 +7,7 @@ #include "nvim/ascii.h" #include "nvim/eval/typval.h" -#include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 +#include "nvim/mbyte.h" #include "nvim/memory.h" #include "nvim/os/os.h" #include "nvim/os/pty_conpty_win.h" diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index e7b745fb7e..56fd2125c2 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -5,7 +5,7 @@ #include #include #ifndef MSWIN -# include // for sigset_t +# include #endif #include "nvim/autocmd.h" -- cgit From 559c4cfd52e385c1b9bd5fa66a0eeb7e8d9e018a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 8 Jul 2023 08:27:39 +0800 Subject: fix(startup): run embedded Nvim with real path (#24282) fix(startup): run embedded process with real path --- src/nvim/os/pty_process_unix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c index b5423c59d7..15a4ef6230 100644 --- a/src/nvim/os/pty_process_unix.c +++ b/src/nvim/os/pty_process_unix.c @@ -285,7 +285,7 @@ static void init_child(PtyProcess *ptyproc) return; } - char *prog = ptyproc->process.argv[0]; + const char *prog = process_get_exepath(proc); assert(proc->env); environ = tv_dict_to_env(proc->env); -- cgit From d2efcbf2dca6c2899ba0a1be7fc10dbf3f112d26 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 22 Jul 2023 18:00:55 +0800 Subject: refactor: remove some (const char **) casts (#24423) --- src/nvim/os/input.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index fa9ff6e9b1..6310b90f04 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -242,8 +242,8 @@ bool os_isatty(int fd) size_t input_enqueue(String keys) { - char *ptr = keys.data; - char *end = ptr + keys.size; + const char *ptr = keys.data; + const char *end = ptr + keys.size; while (rbuffer_space(input_buffer) >= 19 && ptr < end) { // A "" form occupies at least 1 characters, and produces up @@ -254,8 +254,7 @@ size_t input_enqueue(String keys) uint8_t buf[19] = { 0 }; // Do not simplify the keys here. Simplification will be done later. unsigned new_size - = trans_special((const char **)&ptr, (size_t)(end - ptr), (char *)buf, FSK_KEYCODE, true, - NULL); + = trans_special(&ptr, (size_t)(end - ptr), (char *)buf, FSK_KEYCODE, true, NULL); if (new_size) { new_size = handle_mouse_event(&ptr, buf, new_size); @@ -264,7 +263,7 @@ size_t input_enqueue(String keys) } if (*ptr == '<') { - char *old_ptr = ptr; + const char *old_ptr = ptr; // Invalid or incomplete key sequence, skip until the next '>' or *end. do { ptr++; @@ -346,7 +345,7 @@ static uint8_t check_multiclick(int code, int grid, int row, int col) // Mouse event handling code(Extract row/col if available and detect multiple // clicks) -static unsigned handle_mouse_event(char **ptr, uint8_t *buf, unsigned bufsize) +static unsigned handle_mouse_event(const char **ptr, uint8_t *buf, unsigned bufsize) { int mouse_code = 0; int type = 0; -- cgit From 5970157e1d22fd5e05ae5d3bd949f807fb7a744c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 17 May 2023 16:08:06 +0200 Subject: refactor(map): enhanced implementation, Clean Code™, etc etc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This involves two redesigns of the map.c implementations: 1. Change of macro style and code organization The old khash.h and map.c implementation used huge #define blocks with a lot of backslash line continuations. This instead uses the "implementation file" .c.h pattern. Such a file is meant to be included multiple times, with different macros set prior to inclusion as parameters. we already use this pattern e.g. for eval/typval_encode.c.h to implement different typval encoders reusing a similar structure. We can structure this code into two parts. one that only depends on key type and is enough to implement sets, and one which depends on both key and value to implement maps (as a wrapper around sets, with an added value[] array) 2. Separate the main hash buckets from the key / value arrays Change the hack buckets to only contain an index into separate key / value arrays This is a common pattern in modern, state of the art hashmap implementations. Even though this leads to one more allocated array, it is this often is a net reduction of memory consumption. Consider key+value consuming at least 12 bytes per pair. On average, we will have twice as many buckets per item. Thus old implementation: 2*12 = 24 bytes per item New implementation 1*12 + 2*4 = 20 bytes per item And the difference gets bigger with larger items. One might think we have pulled a fast one here, as wouldn't the average size of the new key/value arrays be 1.5 slots per items due to amortized grows? But remember, these arrays are fully dense, and thus the accessed memory, measured in _cache lines_, the unit which actually matters, will be the fully used memory but just rounded up to the nearest cache line boundary. This has some other interesting properties, such as an insert-only set/map will be fully ordered by insert only. Preserving this ordering in face of deletions is more tricky tho. As we currently don't use ordered maps, the "delete" operation maintains compactness of the item arrays in the simplest way by breaking the ordering. It would be possible to implement an order-preserving delete although at some cost, like allowing the items array to become non-dense until the next rehash. Finally, in face of these two major changes, all code used in khash.h has been integrated into map.c and friends. Given the heavy edits it makes no sense to "layer" the code into a vendored and a wrapper part. Rather, the layered cake follows the specialization depth: code shared for all maps, code specialized to a key type (and its equivalence relation), and finally code specialized to value+key type. --- src/nvim/os/env.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index f931e00916..10fe3cb114 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -64,7 +64,7 @@ const char *os_getenv(const char *name) return NULL; } int r = 0; - if (pmap_has(cstr_t)(&envmap, name) + if (map_has(cstr_t, &envmap, name) && !!(e = (char *)pmap_get(cstr_t)(&envmap, name))) { if (e[0] != '\0') { // Found non-empty cached env var. -- cgit From bb38c066a96512cf8cb2ef2e733494b5bbdfa3fd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 9 Sep 2023 15:13:45 +0200 Subject: fix: fix compiler warning from clang --- src/nvim/os/shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 979c6153aa..81e15bf841 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -1026,7 +1026,7 @@ static bool out_data_decide_throttle(size_t size) started = os_hrtime(); } else { uint64_t since = os_hrtime() - started; - if (since < (visit * 0.1L * NS_1_SECOND)) { + if (since < (visit * (NS_1_SECOND / 10))) { return true; } if (since > (3 * NS_1_SECOND)) { -- cgit From 57ccd8241735d4867692ed179a14f484909f3621 Mon Sep 17 00:00:00 2001 From: sid-6581 Date: Sun, 17 Sep 2023 18:07:08 -0500 Subject: fix(job-control): fix use after free (#25223) --- src/nvim/os/pty_process_win.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/pty_process_win.c b/src/nvim/os/pty_process_win.c index abeb020645..763d30d4a2 100644 --- a/src/nvim/os/pty_process_win.c +++ b/src/nvim/os/pty_process_win.c @@ -256,9 +256,9 @@ static int build_cmd_line(char **argv, wchar_t **cmd_line, bool is_cmdexe) QUEUE_FOREACH(q, &args_q, { ArgNode *arg_node = QUEUE_DATA(q, ArgNode, node); xstrlcat(utf8_cmd_line, arg_node->arg, utf8_cmd_line_len); + QUEUE_REMOVE(q); xfree(arg_node->arg); xfree(arg_node); - QUEUE_REMOVE(q); if (!QUEUE_EMPTY(&args_q)) { xstrlcat(utf8_cmd_line, " ", utf8_cmd_line_len); } -- cgit From a66b0fdfaa35715c832b98b8941cc5673505e0c2 Mon Sep 17 00:00:00 2001 From: Rory Nesbitt Date: Wed, 27 Sep 2023 18:09:55 +0100 Subject: feat: NVIM_APPNAME supports relative paths #25233 Problem: NVIM_APPNAME does not allow path separators in the name, so relative paths can't be used: NVIM_APPNAME="neovim-configs/first-config" nvim NVIM_APPNAME="neovim-configs/second-config" nvim Solution: Let NVIM_APPNAME be a relative path. Absolute paths are not supported. fix #23056 fix #24966 --- src/nvim/os/stdpaths.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 53ddda22fa..b129eb445a 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -69,15 +69,23 @@ const char *get_appname(void) return env_val; } -/// Ensure that APPNAME is valid. In particular, it cannot contain directory separators. +/// Ensure that APPNAME is valid. Must be a name or relative path. bool appname_is_valid(void) { const char *appname = get_appname(); - const size_t appname_len = strlen(appname); - for (size_t i = 0; i < appname_len; i++) { - if (appname[i] == PATHSEP) { - return false; - } + if (path_is_absolute(appname) + // TODO(justinmk): on Windows, path_is_absolute says "/" is NOT absolute. Should it? + || strequal(appname, "/") + || strequal(appname, "\\") + || strequal(appname, ".") + || strequal(appname, "..") +#ifdef BACKSLASH_IN_FILENAME + || strstr(appname, "\\..") != NULL + || strstr(appname, "..\\") != NULL +#endif + || strstr(appname, "/..") != NULL + || strstr(appname, "../") != NULL) { + return false; } return true; } -- cgit From f91cd31d7d9d70006e0000592637d5d997eab52c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 21:46:39 +0200 Subject: refactor(messages): fold msg_outtrans_attr into msg_outtrans problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/os/shell.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 81e15bf841..48219f6231 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -876,9 +876,9 @@ static int do_os_system(char **argv, const char *input, size_t len, char **outpu // Failed, probably 'shell' is not executable. if (!silent) { msg_puts(_("\nshell failed to start: ")); - msg_outtrans(os_strerror(status)); + msg_outtrans(os_strerror(status), 0); msg_puts(": "); - msg_outtrans(prog); + msg_outtrans(prog, 0); msg_putchar('\n'); } multiqueue_free(events); @@ -1127,7 +1127,7 @@ static void out_data_append_to_screen(char *output, size_t *count, bool eof) goto end; } - (void)msg_outtrans_len_attr(p, i, 0); + (void)msg_outtrans_len(p, i, 0); p += i; } } -- cgit From b85f1dafc7c0a19704135617454f1c66f41202c1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 22:21:17 +0200 Subject: refactor(messages): fold msg_attr into msg problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/os/shell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 48219f6231..1cd560c5ef 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -364,7 +364,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in if (!(flags & EW_SILENT)) { msg_putchar('\n'); // clear bottom line quickly cmdline_row = Rows - 1; // continue on last line - msg(_(e_wildexpand)); + msg(_(e_wildexpand), 0); msg_start(); // don't overwrite this message } @@ -381,7 +381,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in if (fd == NULL) { // Something went wrong, perhaps a file name with a special char. if (!(flags & EW_SILENT)) { - msg(_(e_wildexpand)); + msg(_(e_wildexpand), 0); msg_start(); // don't overwrite this message } xfree(tempname); -- cgit From 92e40f8d185e3da8fc97b7a48041afc3fd568d29 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 28 Sep 2023 05:09:21 +0800 Subject: vim-patch:9.0.1946: filename expansion using ** in bash may fail Problem: filename expansion using ** in bash may fail Solution: Try to enable the globstar setting Starting with bash 4.0 it supports extended globbing using the globstar shell option. This makes matching recursively below a certain directory using the ** pattern work as expected nowadays. However, we need to explicitly enable this using the 'shopt -s globstar' bash command. So let's check the bash environment variable $BASH_VERSINFO (which is supported since bash 3.0 and conditionally enable the globstar option, if the major version is at least 4. For older bashs, this at least shouldn't cause errors (unless one is using really ancient bash 2.X or something). closes: vim/vim#13002 closes: vim/vim#13144 https://github.com/vim/vim/commit/9eb1ce531527a7177d16373b0f8689bbcd3d5f73 Co-authored-by: Christian Brabandt --- src/nvim/os/shell.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 1cd560c5ef..582135349f 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -134,6 +134,8 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in #define STYLE_VIMGLOB 2 // use "vimglob", for Posix sh #define STYLE_PRINT 3 // use "print -N", for zsh #define STYLE_BT 4 // `cmd` expansion, execute the pattern directly +#define STYLE_GLOBSTAR 5 // use extended shell glob for bash (this uses extended + // globbing functionality with globstar, needs bash > 4) int shell_style = STYLE_ECHO; int check_spaces; static bool did_find_nul = false; @@ -141,6 +143,9 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in // vimglob() function to define for Posix shell static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo \"$1\"; shift; done }; vimglob >"; + // vimglob() function with globstar setting enabled, only for bash >= 4.X + static char *sh_globstar_opt = + "[[ ${BASH_VERSINFO[0]} -ge 4 ]] && shopt -s globstar; "; bool is_fish_shell = #if defined(UNIX) @@ -190,6 +195,8 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in // If we use *zsh, "print -N" will work better than "glob". // STYLE_VIMGLOB: NL separated // If we use *sh*, we define "vimglob()". + // STYLE_GLOBSTAR: NL separated + // If we use *bash*, we define "vimglob() and enable globstar option". // STYLE_ECHO: space separated. // A shell we don't know, stay safe and use "echo". if (num_pat == 1 && *pat[0] == '`' @@ -203,9 +210,12 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in shell_style = STYLE_PRINT; } } - if (shell_style == STYLE_ECHO - && strstr(path_tail(p_sh), "sh") != NULL) { - shell_style = STYLE_VIMGLOB; + if (shell_style == STYLE_ECHO) { + if (strstr(path_tail(p_sh), "bash") != NULL) { + shell_style = STYLE_GLOBSTAR; + } else if (strstr(path_tail(p_sh), "sh") != NULL) { + shell_style = STYLE_VIMGLOB; + } } // Compute the length of the command. We need 2 extra bytes: for the @@ -214,6 +224,8 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in len = strlen(tempname) + 29; if (shell_style == STYLE_VIMGLOB) { len += strlen(sh_vimglob_func); + } else if (shell_style == STYLE_GLOBSTAR) { + len += strlen(sh_vimglob_func) + strlen(sh_globstar_opt); } for (i = 0; i < num_pat; i++) { @@ -281,6 +293,9 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in STRCAT(command, "print -N >"); } else if (shell_style == STYLE_VIMGLOB) { STRCAT(command, sh_vimglob_func); + } else if (shell_style == STYLE_GLOBSTAR) { + STRCAT(command, sh_globstar_opt); + STRCAT(command, sh_vimglob_func); } else { STRCAT(command, "echo >"); } @@ -430,7 +445,9 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in p = skipwhite(p); // skip to next entry } // file names are separated with NL - } else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) { + } else if (shell_style == STYLE_BT + || shell_style == STYLE_VIMGLOB + || shell_style == STYLE_GLOBSTAR) { buffer[len] = NUL; // make sure the buffer ends in NUL p = buffer; for (i = 0; *p != NUL; i++) { // count number of entries @@ -496,7 +513,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in (*file)[i] = p; // Space or NL separates if (shell_style == STYLE_ECHO || shell_style == STYLE_BT - || shell_style == STYLE_VIMGLOB) { + || shell_style == STYLE_VIMGLOB || shell_style == STYLE_GLOBSTAR) { while (!(shell_style == STYLE_ECHO && *p == ' ') && *p != '\n' && *p != NUL) { p++; -- cgit From bc13bc154aa574e0bb58a50f2e0ca4570efa57c3 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 29 Sep 2023 16:10:54 +0200 Subject: refactor(message): smsg_attr -> smsg --- src/nvim/os/fs.c | 2 +- src/nvim/os/lang.c | 2 +- src/nvim/os/shell.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 6c3eca8961..c95b5defaa 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -76,7 +76,7 @@ int os_chdir(const char *path) { if (p_verbose >= 5) { verbose_enter(); - smsg("chdir(%s)", path); + smsg(0, "chdir(%s)", path); verbose_leave(); } return uv_chdir(path); diff --git a/src/nvim/os/lang.c b/src/nvim/os/lang.c index 8ca2aa3a4b..652b851903 100644 --- a/src/nvim/os/lang.c +++ b/src/nvim/os/lang.c @@ -197,7 +197,7 @@ void ex_language(exarg_T *eap) if (p == NULL || *p == NUL) { p = "Unknown"; } - smsg(_("Current %slanguage: \"%s\""), whatstr, p); + smsg(0, _("Current %slanguage: \"%s\""), whatstr, p); } else { # ifndef LC_MESSAGES if (what == VIM_LC_MESSAGES) { diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 582135349f..9b7b013edf 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -732,7 +732,7 @@ int call_shell(char *cmd, ShellOpts opts, char *extra_shell_arg) if (p_verbose > 3) { verbose_enter(); - smsg(_("Executing command: \"%s\""), cmd == NULL ? p_sh : cmd); + smsg(0, _("Executing command: \"%s\""), cmd == NULL ? p_sh : cmd); msg_putchar('\n'); verbose_leave(); } -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/os/fs.c | 1 - src/nvim/os/input.c | 2 +- src/nvim/os/input.h | 1 + src/nvim/os/shell.c | 1 - src/nvim/os/signal.c | 1 - src/nvim/os/stdpaths.c | 2 ++ src/nvim/os/time.c | 2 -- 7 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index c95b5defaa..400284606f 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -33,7 +33,6 @@ #include "nvim/globals.h" #include "nvim/log.h" #include "nvim/macros.h" -#include "nvim/main.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_defs.h" diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 6310b90f04..d4ca31aa54 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -11,7 +11,6 @@ #include "nvim/api/private/defs.h" #include "nvim/ascii.h" #include "nvim/autocmd.h" -#include "nvim/buffer_defs.h" #include "nvim/event/loop.h" #include "nvim/event/multiqueue.h" #include "nvim/event/rstream.h" @@ -26,6 +25,7 @@ #include "nvim/msgpack_rpc/channel.h" #include "nvim/option_defs.h" #include "nvim/os/input.h" +#include "nvim/os/os_defs.h" #include "nvim/os/time.h" #include "nvim/profile.h" #include "nvim/rbuffer.h" diff --git a/src/nvim/os/input.h b/src/nvim/os/input.h index 6f25efdc7b..af17aabd90 100644 --- a/src/nvim/os/input.h +++ b/src/nvim/os/input.h @@ -6,6 +6,7 @@ #include "nvim/api/private/defs.h" #include "nvim/event/multiqueue.h" +#include "nvim/macros.h" EXTERN bool used_stdin INIT(= false); diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 9b7b013edf..be5c6be222 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -11,7 +11,6 @@ #include "auto/config.h" #include "klib/kvec.h" #include "nvim/ascii.h" -#include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/eval.h" #include "nvim/eval/typval_defs.h" diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index 56fd2125c2..4c4ac9df1e 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -9,7 +9,6 @@ #endif #include "nvim/autocmd.h" -#include "nvim/buffer_defs.h" #include "nvim/eval.h" #include "nvim/event/signal.h" #include "nvim/globals.h" diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index b129eb445a..fa474b67dd 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -1,11 +1,13 @@ // This is an open source non-commercial project. Dear PVS-Studio, please check // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com +#include #include #include #include "nvim/ascii.h" #include "nvim/fileio.h" +#include "nvim/globals.h" #include "nvim/memory.h" #include "nvim/os/os.h" #include "nvim/os/stdpaths_defs.h" diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index 0c3b254b9a..ac98f0cf9a 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include @@ -15,7 +14,6 @@ #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/log.h" -#include "nvim/macros.h" #include "nvim/main.h" #include "nvim/memory.h" #include "nvim/os/input.h" -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/os/env.c | 2 +- src/nvim/os/fs.c | 2 +- src/nvim/os/input.c | 2 +- src/nvim/os/shell.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 10fe3cb114..b03509a313 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -25,7 +25,7 @@ #include "nvim/map.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/option_defs.h" +#include "nvim/option_vars.h" #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/strings.h" diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 400284606f..77c4766419 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -35,7 +35,7 @@ #include "nvim/macros.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/option_defs.h" +#include "nvim/option_vars.h" #include "nvim/os/fs_defs.h" #include "nvim/os/os.h" #include "nvim/path.h" diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index d4ca31aa54..03418f4548 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -23,7 +23,7 @@ #include "nvim/macros.h" #include "nvim/main.h" #include "nvim/msgpack_rpc/channel.h" -#include "nvim/option_defs.h" +#include "nvim/option_vars.h" #include "nvim/os/input.h" #include "nvim/os/os_defs.h" #include "nvim/os/time.h" diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index be5c6be222..d885c8476f 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -31,7 +31,7 @@ #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/option_defs.h" +#include "nvim/option_vars.h" #include "nvim/os/fs.h" #include "nvim/os/os_defs.h" #include "nvim/os/shell.h" -- cgit From f6e72c3dfed83b02483976eaedb27819df9a878d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 19:14:24 +0800 Subject: vim-patch:9.0.1962: No support for writing extended attributes Problem: No support for writing extended attributes Solution: Add extended attribute support for linux It's been a long standing issue, that if you write a file with extended attributes and backupcopy is set to no, the file will loose the extended attributes. So this patch adds support for retrieving the extended attributes and copying it to the new file. It currently only works on linux, mainly because I don't know the different APIs for other systems (BSD, MacOSX and Solaris). On linux, this should be supported since Kernel 2.4 or something, so this should be pretty safe to use now. Enable the extended attribute support with normal builds. I also added it explicitly to the :version output as well as make it able to check using `:echo has("xattr")`, to have users easily check that this is available. In contrast to the similar support for SELINUX and SMACK support (which also internally uses extended attributes), I have made this a FEAT_XATTR define, instead of the similar HAVE_XATTR. Add a test and change CI to include relevant packages so that CI can test that extended attributes are correctly written. closes: vim/vim#306 closes: vim/vim#13203 https://github.com/vim/vim/commit/e085dfda5d8dde064b0332464040959479696d1c Co-authored-by: Christian Brabandt --- src/nvim/os/fs.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 77c4766419..3efb575039 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -18,6 +18,8 @@ # include #endif +#include "auto/config.h" + #if defined(HAVE_ACL) # ifdef HAVE_SYS_ACL_H # include @@ -27,7 +29,11 @@ # endif #endif -#include "auto/config.h" +#ifdef HAVE_XATTR +# include +# define XATTR_VAL_LEN 1024 +#endif + #include "nvim/ascii.h" #include "nvim/gettext.h" #include "nvim/globals.h" @@ -55,6 +61,17 @@ # include "os/fs.c.generated.h" #endif +#ifdef HAVE_XATTR +static const char e_xattr_erange[] + = N_("E1506: Buffer too small to copy xattr value or key"); +static const char e_xattr_enotsup[] + = N_("E1507: Extended attributes are not supported by the filesystem"); +static const char e_xattr_e2big[] + = N_("E1508: size of the extended attribute value is larger than the maximum size allowed"); +static const char e_xattr_other[] + = N_("E1509: error occured when reading or writing extended attribute"); +#endif + struct iovec; #define RUN_UV_FS_FUNC(ret, func, ...) \ @@ -743,6 +760,84 @@ int os_setperm(const char *const name, int perm) return (r == kLibuvSuccess ? OK : FAIL); } +#ifdef HAVE_XATTR +/// Copy extended attributes from_file to to_file +void os_copy_xattr(const char *from_file, const char *to_file) +{ + if (from_file == NULL) { + return; + } + + // get the length of the extended attributes + ssize_t size = listxattr((char *)from_file, NULL, 0); + // not supported or no attributes to copy + if (errno == ENOTSUP || size <= 0) { + return; + } + char *xattr_buf = xmalloc((size_t)size); + size = listxattr(from_file, xattr_buf, (size_t)size); + ssize_t tsize = size; + + errno = 0; + + ssize_t max_vallen = 0; + char *val = NULL; + const char *errmsg = NULL; + + for (int round = 0; round < 2; round++) { + char *key = xattr_buf; + if (round == 1) { + size = tsize; + } + + while (size > 0) { + ssize_t vallen = getxattr(from_file, key, val, round ? (size_t)max_vallen : 0); + // only set the attribute in the second round + if (vallen >= 0 && round + && setxattr(to_file, key, val, (size_t)vallen, 0) == 0) { + // + } else if (errno) { + switch (errno) { + case E2BIG: + errmsg = e_xattr_e2big; + goto error_exit; + case ENOTSUP: + errmsg = e_xattr_enotsup; + goto error_exit; + case ERANGE: + errmsg = e_xattr_erange; + goto error_exit; + default: + errmsg = e_xattr_other; + goto error_exit; + } + } + + if (round == 0 && vallen > max_vallen) { + max_vallen = vallen; + } + + // add one for terminating null + ssize_t keylen = (ssize_t)strlen(key) + 1; + size -= keylen; + key += keylen; + } + if (round) { + break; + } + + val = xmalloc((size_t)max_vallen + 1); + } +error_exit: + xfree(xattr_buf); + xfree(val); + + if (errmsg != NULL) { + emsg(errmsg); + } +} +#endif + // Return a pointer to the ACL of file "fname" in allocated memory. // Return NULL if the ACL is not available for whatever reason. vim_acl_T os_get_acl(const char *fname) -- cgit From 5c60fbe9db0005d10d87ba60a981fd41f85f8df5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 21:19:12 +0800 Subject: vim-patch:9.0.1963: Configure script may not detect xattr Problem: Configure script may not detect xattr correctly Solution: include sys/xattr instead of attr/xattr, make Test_write_with_xattr_support() test xattr feature correctly This also applies to the Smack security feature, so change the include and configure script for it as well. closes: vim/vim#13229 https://github.com/vim/vim/commit/6de4e58cf27a3bb6e81653ca63b77e29d1bb46f2 --- src/nvim/os/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 3efb575039..93cc7de040 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -30,7 +30,7 @@ #endif #ifdef HAVE_XATTR -# include +# include # define XATTR_VAL_LEN 1024 #endif -- cgit From 248305cf377de6710daa89a92eb8605fa5dcbb1f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 1 Oct 2023 06:08:47 +0800 Subject: vim-patch:9.0.1964: xattr support fails to build on MacOS X (#25448) Problem: xattr support fails to build on MacOS X Solution: Disable xattr support for MacOS X MacOS X uses the same headers and functions sys/xattr.h but the function signatures for xattr support are much different, so building fails. So let's for now disable xattr support there. closes: vim/vim#13230 closes: vim/vim#13232 https://github.com/vim/vim/commit/a4dfbfed89e26a766e30cca62c18e710eec81c3f Co-authored-by: Christian Brabandt --- src/nvim/os/fs.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 93cc7de040..de7996e51b 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -31,7 +31,6 @@ #ifdef HAVE_XATTR # include -# define XATTR_VAL_LEN 1024 #endif #include "nvim/ascii.h" -- cgit From 2da66f1f710523548ca0746d5f7ef945de6d8f6a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 1 Oct 2023 16:29:55 +0800 Subject: vim-patch:9.0.1967: xattr errors not translated (#25454) Problem: xattr errors not translated Solution: mark for translation, consistently capitalize first letter. closes: vim/vim#13236 https://github.com/vim/vim/commit/7ece036d72cf639b05d3936183220bec7179bf63 --- src/nvim/os/fs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index de7996e51b..476ede2046 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -66,9 +66,9 @@ static const char e_xattr_erange[] static const char e_xattr_enotsup[] = N_("E1507: Extended attributes are not supported by the filesystem"); static const char e_xattr_e2big[] - = N_("E1508: size of the extended attribute value is larger than the maximum size allowed"); + = N_("E1508: Size of the extended attribute value is larger than the maximum size allowed"); static const char e_xattr_other[] - = N_("E1509: error occured when reading or writing extended attribute"); + = N_("E1509: Error occured when reading or writing extended attribute"); #endif struct iovec; @@ -832,7 +832,7 @@ error_exit: xfree(val); if (errmsg != NULL) { - emsg(errmsg); + emsg(_(errmsg)); } } #endif -- cgit From 09a17f91d0d362c6e58bfdbe3ccdeacffb0b44b9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 2 Oct 2023 10:45:33 +0800 Subject: refactor: move cmdline completion types to cmdexpand_defs.h (#25465) --- src/nvim/os/env.c | 2 -- src/nvim/os/lang.c | 3 ++- src/nvim/os/lang.h | 1 + src/nvim/os/os.h | 5 ++++- src/nvim/os/users.c | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index b03509a313..7de7168d62 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -17,7 +17,6 @@ #include "nvim/charset.h" #include "nvim/cmdexpand.h" #include "nvim/eval.h" -#include "nvim/ex_cmds_defs.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/log.h" @@ -29,7 +28,6 @@ #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/strings.h" -#include "nvim/types.h" #include "nvim/version.h" #include "nvim/vim.h" diff --git a/src/nvim/os/lang.c b/src/nvim/os/lang.c index 652b851903..c3958cb3f2 100644 --- a/src/nvim/os/lang.c +++ b/src/nvim/os/lang.c @@ -5,6 +5,7 @@ # define Boolean CFBoolean // Avoid conflict with API's Boolean # define FileInfo CSFileInfo // Avoid conflict with API's Fileinfo # include + # undef Boolean # undef FileInfo #endif @@ -17,6 +18,7 @@ #include "nvim/ascii.h" #include "nvim/buffer.h" #include "nvim/charset.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/eval.h" #include "nvim/ex_cmds_defs.h" #include "nvim/garray.h" @@ -30,7 +32,6 @@ #include "nvim/os/shell.h" #include "nvim/path.h" #include "nvim/profile.h" -#include "nvim/types.h" #include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS diff --git a/src/nvim/os/lang.h b/src/nvim/os/lang.h index bb1ebfb721..ad64b38916 100644 --- a/src/nvim/os/lang.h +++ b/src/nvim/os/lang.h @@ -1,6 +1,7 @@ #ifndef NVIM_OS_LANG_H #define NVIM_OS_LANG_H +#include "nvim/cmdexpand_defs.h" #include "nvim/ex_cmds_defs.h" #include "nvim/types.h" diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h index a7496130cc..006dfbfc04 100644 --- a/src/nvim/os/os.h +++ b/src/nvim/os/os.h @@ -4,9 +4,12 @@ #include #include +#include "nvim/buffer_defs.h" +#include "nvim/cmdexpand_defs.h" +#include "nvim/garray.h" #include "nvim/os/fs_defs.h" #include "nvim/os/stdpaths_defs.h" -#include "nvim/vim.h" +#include "nvim/types.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/env.h.generated.h" diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index 411ba91fa7..b23d2b7b13 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -10,10 +10,10 @@ #include "auto/config.h" #include "nvim/ascii.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/garray.h" #include "nvim/memory.h" #include "nvim/os/os.h" -#include "nvim/types.h" #include "nvim/vim.h" #ifdef HAVE_PWD_FUNCS # include -- cgit From fd791db0ecebf5d5bf8922ba519f8dd4eef3c5e6 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 3 Oct 2023 00:19:30 +0200 Subject: fix: fix ASAN errors on clang 17 (#25469) --- src/nvim/os/fileio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index 846219f720..119a42f074 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -282,9 +282,10 @@ static char writebuf[kRWBufferSize]; /// /// @param[in,out] rv RBuffer instance used. /// @param[in,out] fp File to work with. -static void file_rb_write_full_cb(RBuffer *const rv, FileDescriptor *const fp) +static void file_rb_write_full_cb(RBuffer *const rv, void *const fp_in) FUNC_ATTR_NONNULL_ALL { + FileDescriptor *const fp = fp_in; assert(fp->wr); assert(rv->data == (void *)fp); if (rbuffer_size(rv) == 0) { -- cgit From 3c76038755b5c0c63604f2baa481491bb0efe2e1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 3 Oct 2023 07:45:51 +0800 Subject: vim-patch:9.0.1975: xattr: permission-denied errors on write (#25478) Problem: xattr: permission-denied errors on write Solution: ignore those errors closes: vim/vim#13246 https://github.com/vim/vim/commit/993b17569b5acffe2d8941d1709a55da4e439755 N/A patches: vim-patch:9.0.1965: wrong auto/configure script vim-patch:9.0.1966: configure prints stray 6 when checking libruby Co-authored-by: Gene C --- src/nvim/os/fs.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 476ede2046..2712b874bb 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -63,8 +63,6 @@ #ifdef HAVE_XATTR static const char e_xattr_erange[] = N_("E1506: Buffer too small to copy xattr value or key"); -static const char e_xattr_enotsup[] - = N_("E1507: Extended attributes are not supported by the filesystem"); static const char e_xattr_e2big[] = N_("E1508: Size of the extended attribute value is larger than the maximum size allowed"); static const char e_xattr_other[] @@ -800,9 +798,9 @@ void os_copy_xattr(const char *from_file, const char *to_file) case E2BIG: errmsg = e_xattr_e2big; goto error_exit; - case ENOTSUP: - errmsg = e_xattr_enotsup; - goto error_exit; + case EACCES: + case EPERM: + break; case ERANGE: errmsg = e_xattr_erange; goto error_exit; -- cgit From 3a44db510b1661eb92689e328d5191acfcb95433 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 11 Oct 2023 22:16:25 +0200 Subject: refactor(lang): reduce scope of HAVE_WORKING_LIBINTL #ifdefs A lot of code inside HAVE_WORKING_LIBINTL doesn't really depend on a "working libintl". For instance ex_language is also used for ":lang collate" and ":lang time". Also ":lang C" should not fail just because translations aren't available (it just means use the default text). References: https://github.com/neovim/neovim/pull/1 2d00ead2e57653b771354a564f9a760c2ce0d18e separate ifdefs for locale and gettext got merged together. https://github.com/neovim/neovim/commit/8253e29971c54310434ee93d987a99994769d717 Unmotivated switcharoo of get_mess_env() logic. If available, get_locale_val(LC_MESSAGES) is the correct implementation. --- src/nvim/os/lang.c | 68 +++++++++++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 39 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/lang.c b/src/nvim/os/lang.c index c3958cb3f2..93c200f6e8 100644 --- a/src/nvim/os/lang.c +++ b/src/nvim/os/lang.c @@ -71,20 +71,23 @@ char *get_mess_lang(void) return is_valid_mess_lang(p) ? p : NULL; } -// Complicated #if; matches with where get_mess_env() is used below. -#ifdef HAVE_WORKING_LIBINTL /// Get the language used for messages from the environment. +/// +/// This uses LC_MESSAGES when available, which it is for most systems we build for +/// except for windows. Then fallback to get the value from the envirionment +/// ourselves, and use LC_CTYPE as a last resort. static char *get_mess_env(void) { - char *p; - - p = (char *)os_getenv("LC_ALL"); +#ifdef LC_MESSAGES + return get_locale_val(LC_MESSAGES); +#else + char *p = (char *)os_getenv("LC_ALL"); if (p == NULL) { p = (char *)os_getenv("LC_MESSAGES"); if (p == NULL) { p = (char *)os_getenv("LANG"); if (p != NULL && ascii_isdigit(*p)) { - p = NULL; // ignore something like "1043" + p = NULL; // ignore something like "1043" } if (p == NULL) { p = get_locale_val(LC_CTYPE); @@ -92,8 +95,8 @@ static char *get_mess_env(void) } } return p; -} #endif +} /// Set the "v:lang" variable according to the current locale setting. /// Also do "v:lc_time"and "v:ctype". @@ -104,16 +107,7 @@ void set_lang_var(void) loc = get_locale_val(LC_CTYPE); set_vim_var_string(VV_CTYPE, loc, -1); - // When LC_MESSAGES isn't defined use the value from $LC_MESSAGES, fall - // back to LC_CTYPE if it's empty. -#ifdef HAVE_WORKING_LIBINTL loc = get_mess_env(); -#elif defined(LC_MESSAGES) - loc = get_locale_val(LC_MESSAGES); -#else - // In Windows LC_MESSAGES is not defined fallback to LC_CTYPE - loc = get_locale_val(LC_CTYPE); -#endif set_vim_var_string(VV_LANG, loc, -1); loc = get_locale_val(LC_TIME); @@ -145,8 +139,6 @@ void init_locale(void) TIME_MSG("locale set"); } -#ifdef HAVE_WORKING_LIBINTL - /// ":language": Set the language (locale). /// /// @param eap @@ -157,11 +149,11 @@ void ex_language(exarg_T *eap) char *name; int what = LC_ALL; char *whatstr = ""; -# ifdef LC_MESSAGES -# define VIM_LC_MESSAGES LC_MESSAGES -# else -# define VIM_LC_MESSAGES 6789 -# endif +#ifdef LC_MESSAGES +# define VIM_LC_MESSAGES LC_MESSAGES +#else +# define VIM_LC_MESSAGES 6789 +#endif name = eap->arg; @@ -200,29 +192,29 @@ void ex_language(exarg_T *eap) } smsg(0, _("Current %slanguage: \"%s\""), whatstr, p); } else { -# ifndef LC_MESSAGES +#ifndef LC_MESSAGES if (what == VIM_LC_MESSAGES) { loc = ""; } else { -# endif +#endif loc = setlocale(what, name); -# ifdef LC_NUMERIC +#ifdef LC_NUMERIC // Make sure strtod() uses a decimal point, not a comma. setlocale(LC_NUMERIC, "C"); -# endif -# ifndef LC_MESSAGES +#endif +#ifndef LC_MESSAGES } -# endif +#endif if (loc == NULL) { semsg(_("E197: Cannot set language to \"%s\""), name); } else { -# ifdef HAVE_NL_MSG_CAT_CNTR +#ifdef HAVE_NL_MSG_CAT_CNTR // Need to do this for GNU gettext, otherwise cached translations // will be used again. extern int _nl_msg_cat_cntr; _nl_msg_cat_cntr++; -# endif +#endif // Reset $LC_ALL, otherwise it would overrule everything. os_setenv("LC_ALL", "", 1); @@ -250,7 +242,7 @@ void ex_language(exarg_T *eap) static char **locales = NULL; // Array of all available locales -# ifndef MSWIN +#ifndef MSWIN static bool did_init_locales = false; /// @return an array of strings for all available locales + NULL for the @@ -285,22 +277,22 @@ static char **find_locales(void) ((char **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; return locales_ga.ga_data; } -# endif +#endif /// Lazy initialization of all available locales. static void init_locales(void) { -# ifndef MSWIN +#ifndef MSWIN if (did_init_locales) { return; } did_init_locales = true; locales = find_locales(); -# endif +#endif } -# if defined(EXITFREE) +#if defined(EXITFREE) void free_locales(void) { if (locales == NULL) { @@ -312,7 +304,7 @@ void free_locales(void) } XFREE_CLEAR(locales); } -# endif +#endif /// Function given to ExpandGeneric() to obtain the possible arguments of the /// ":language" command. @@ -348,8 +340,6 @@ char *get_locales(expand_T *xp, int idx) return locales[idx]; } -#endif - void lang_init(void) { #ifdef __APPLE__ -- cgit From 3222f0ad0079ce4bd4e45886a00e4fe4685fb5dd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 16 Oct 2023 16:36:25 +0800 Subject: vim-patch:dbf749bd5aae (#25665) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit runtime: Fix more typos (vim/vim#13354) * Fix more typos * Fix typos in ignored runtime/ directory https://github.com/vim/vim/commit/dbf749bd5aaef6ea2d28bce081349785d174d96a Co-authored-by: Viktor Szépe --- src/nvim/os/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 2712b874bb..9a448d69ae 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -66,7 +66,7 @@ static const char e_xattr_erange[] static const char e_xattr_e2big[] = N_("E1508: Size of the extended attribute value is larger than the maximum size allowed"); static const char e_xattr_other[] - = N_("E1509: Error occured when reading or writing extended attribute"); + = N_("E1509: Error occurred when reading or writing extended attribute"); #endif struct iovec; -- cgit From 5f03a1eaabfc8de2b3a9c666fcd604763f41e152 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 20 Oct 2023 15:10:33 +0200 Subject: build(lint): remove unnecessary clint.py rules Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py. --- src/nvim/os/input.h | 2 +- src/nvim/os/pty_conpty_win.c | 6 +++--- src/nvim/os/pty_conpty_win.h | 6 +++--- src/nvim/os/pty_process_unix.c | 28 ++++++++++++++-------------- src/nvim/os/shell.c | 8 ++++---- 5 files changed, 25 insertions(+), 25 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/input.h b/src/nvim/os/input.h index af17aabd90..d42da010f0 100644 --- a/src/nvim/os/input.h +++ b/src/nvim/os/input.h @@ -8,7 +8,7 @@ #include "nvim/event/multiqueue.h" #include "nvim/macros.h" -EXTERN bool used_stdin INIT(= false); +EXTERN bool used_stdin INIT( = false); #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/input.h.generated.h" diff --git a/src/nvim/os/pty_conpty_win.c b/src/nvim/os/pty_conpty_win.c index 43c89f8865..32067ad49f 100644 --- a/src/nvim/os/pty_conpty_win.c +++ b/src/nvim/os/pty_conpty_win.c @@ -14,9 +14,9 @@ # define PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE 0x00020016 #endif -HRESULT (WINAPI *pCreatePseudoConsole)(COORD, HANDLE, HANDLE, DWORD, HPCON *); -HRESULT (WINAPI *pResizePseudoConsole)(HPCON, COORD); -void (WINAPI *pClosePseudoConsole)(HPCON); +HRESULT(WINAPI *pCreatePseudoConsole)(COORD, HANDLE, HANDLE, DWORD, HPCON *); +HRESULT(WINAPI *pResizePseudoConsole)(HPCON, COORD); +void(WINAPI *pClosePseudoConsole)(HPCON); bool os_has_conpty_working(void) { diff --git a/src/nvim/os/pty_conpty_win.h b/src/nvim/os/pty_conpty_win.h index 0c25a5970e..c47857bdd9 100644 --- a/src/nvim/os/pty_conpty_win.h +++ b/src/nvim/os/pty_conpty_win.h @@ -8,10 +8,10 @@ # define HPCON VOID * #endif -extern HRESULT (WINAPI *pCreatePseudoConsole) // NOLINT(whitespace/parens) +extern HRESULT(WINAPI *pCreatePseudoConsole) // NOLINT(whitespace/parens) (COORD, HANDLE, HANDLE, DWORD, HPCON *); -extern HRESULT (WINAPI *pResizePseudoConsole)(HPCON, COORD); -extern void (WINAPI *pClosePseudoConsole)(HPCON); +extern HRESULT(WINAPI *pResizePseudoConsole)(HPCON, COORD); +extern void(WINAPI *pClosePseudoConsole)(HPCON); typedef struct conpty { HPCON pty; diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c index 15a4ef6230..efd476ae7b 100644 --- a/src/nvim/os/pty_process_unix.c +++ b/src/nvim/os/pty_process_unix.c @@ -335,21 +335,21 @@ static void init_termios(struct termios *termios) FUNC_ATTR_NONNULL_ALL termios->c_lflag |= ECHOKE; #endif - termios->c_cc[VINTR] = 0x1f & 'C'; - termios->c_cc[VQUIT] = 0x1f & '\\'; - termios->c_cc[VERASE] = 0x7f; - termios->c_cc[VKILL] = 0x1f & 'U'; - termios->c_cc[VEOF] = 0x1f & 'D'; - termios->c_cc[VEOL] = _POSIX_VDISABLE; - termios->c_cc[VEOL2] = _POSIX_VDISABLE; - termios->c_cc[VSTART] = 0x1f & 'Q'; - termios->c_cc[VSTOP] = 0x1f & 'S'; - termios->c_cc[VSUSP] = 0x1f & 'Z'; + termios->c_cc[VINTR] = 0x1f & 'C'; + termios->c_cc[VQUIT] = 0x1f & '\\'; + termios->c_cc[VERASE] = 0x7f; + termios->c_cc[VKILL] = 0x1f & 'U'; + termios->c_cc[VEOF] = 0x1f & 'D'; + termios->c_cc[VEOL] = _POSIX_VDISABLE; + termios->c_cc[VEOL2] = _POSIX_VDISABLE; + termios->c_cc[VSTART] = 0x1f & 'Q'; + termios->c_cc[VSTOP] = 0x1f & 'S'; + termios->c_cc[VSUSP] = 0x1f & 'Z'; termios->c_cc[VREPRINT] = 0x1f & 'R'; - termios->c_cc[VWERASE] = 0x1f & 'W'; - termios->c_cc[VLNEXT] = 0x1f & 'V'; - termios->c_cc[VMIN] = 1; - termios->c_cc[VTIME] = 0; + termios->c_cc[VWERASE] = 0x1f & 'W'; + termios->c_cc[VLNEXT] = 0x1f & 'V'; + termios->c_cc[VMIN] = 1; + termios->c_cc[VTIME] = 0; } static int set_duplicating_descriptor(int fd, uv_pipe_t *pipe) diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index d885c8476f..a206eefd53 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -1022,9 +1022,9 @@ static void system_data_cb(Stream *stream, RBuffer *buf, size_t count, void *dat /// Returns the previous decision if size=0. static bool out_data_decide_throttle(size_t size) { - static uint64_t started = 0; // Start time of the current throttle. - static size_t received = 0; // Bytes observed since last throttle. - static size_t visit = 0; // "Pulse" count of the current throttle. + static uint64_t started = 0; // Start time of the current throttle. + static size_t received = 0; // Bytes observed since last throttle. + static size_t visit = 0; // "Pulse" count of the current throttle. static char pulse_msg[] = { ' ', ' ', ' ', '\0' }; if (!size) { @@ -1104,7 +1104,7 @@ static void out_data_ring(char *output, size_t size) last_skipped_len = MAX_CHUNK_SIZE; } else if (size > 0) { // Length of the old data that can be kept. - size_t keep_len = MIN(last_skipped_len, MAX_CHUNK_SIZE - size); + size_t keep_len = MIN(last_skipped_len, MAX_CHUNK_SIZE - size); size_t keep_start = last_skipped_len - keep_len; // Shift the kept part of the old data to the start. if (keep_start) { -- cgit From 2dc9ceb99c018b15dcf0c443cad46efecccaf94e Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 29 Oct 2023 09:02:32 +0100 Subject: docs: small fixes (#25585) Co-authored-by: tmummert Co-authored-by: parikshit adhikari --- src/nvim/os/lang.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/lang.c b/src/nvim/os/lang.c index 93c200f6e8..602dcc9bd3 100644 --- a/src/nvim/os/lang.c +++ b/src/nvim/os/lang.c @@ -74,7 +74,7 @@ char *get_mess_lang(void) /// Get the language used for messages from the environment. /// /// This uses LC_MESSAGES when available, which it is for most systems we build for -/// except for windows. Then fallback to get the value from the envirionment +/// except for windows. Then fallback to get the value from the environment /// ourselves, and use LC_CTYPE as a last resort. static char *get_mess_env(void) { -- cgit From acc646ad8fc3ef11fcc63b69f3d8484e4a91accd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/os/shell.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index a206eefd53..2f52895357 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -366,7 +366,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in // When running in the background, give it some time to create the temp // file, but don't wait for it to finish. if (ampersand) { - os_delay(10L, true); + os_delay(10, true); } xfree(command); @@ -401,7 +401,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in xfree(tempname); goto notfound; } - int fseek_res = fseek(fd, 0L, SEEK_END); + int fseek_res = fseek(fd, 0, SEEK_END); if (fseek_res < 0) { xfree(tempname); fclose(fd); @@ -417,7 +417,7 @@ int os_expand_wildcards(int num_pat, char **pat, int *num_file, char ***file, in assert(templen <= SIZE_MAX); // NOLINT(runtime/int) #endif len = (size_t)templen; - fseek(fd, 0L, SEEK_SET); + fseek(fd, 0, SEEK_SET); buffer = xmalloc(len + 1); // fread() doesn't terminate buffer with NUL; // appropriate termination (not always NUL) is done below. @@ -802,9 +802,9 @@ char *get_cmd_output(char *cmd, char *infile, ShellOpts flags, size_t *ret_len) goto done; } - fseek(fd, 0L, SEEK_END); + fseek(fd, 0, SEEK_END); size_t len = (size_t)ftell(fd); // get size of temp file - fseek(fd, 0L, SEEK_SET); + fseek(fd, 0, SEEK_SET); buffer = xmalloc(len + 1); size_t i = fread(buffer, 1, len, fd); -- cgit From cd63a9addd6e1114c3524fa041ece560550cfe7b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 10 Nov 2023 08:39:21 +0800 Subject: refactor: change some xstrndup() and xstrnsave() to xmemdupz() (#25959) When the given length is exactly the number of bytes to copy, xmemdupz() makes the intention clearer. --- src/nvim/os/env.c | 9 ++++----- src/nvim/os/stdpaths.c | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 7de7168d62..dbea6f01df 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -292,12 +292,11 @@ char *os_getenvname_at_index(size_t index) // Some Windows env vars start with =, so skip over that to find the // separator between name/value - const char * const end = strchr(utf8_str + (utf8_str[0] == '=' ? 1 : 0), - '='); + const char *const end = strchr(utf8_str + (utf8_str[0] == '=' ? 1 : 0), '='); assert(end != NULL); ptrdiff_t len = end - utf8_str; assert(len > 0); - name = xstrndup(utf8_str, (size_t)len); + name = xmemdupz(utf8_str, (size_t)len); xfree(utf8_str); break; } @@ -328,7 +327,7 @@ char *os_getenvname_at_index(size_t index) assert(end != NULL); ptrdiff_t len = end - str; assert(len > 0); - return xstrndup(str, (size_t)len); + return xmemdupz(str, (size_t)len); #endif } @@ -960,7 +959,7 @@ char *vim_getenv(const char *name) // check that the result is a directory name assert(vim_path_end >= vim_path); - vim_path = xstrndup(vim_path, (size_t)(vim_path_end - vim_path)); + vim_path = xmemdupz(vim_path, (size_t)(vim_path_end - vim_path)); if (!os_isdir(vim_path)) { xfree(vim_path); diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index fa474b67dd..8ea30ff21e 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -127,7 +127,7 @@ char *stdpaths_get_xdg_var(const XDGVarType idx) ret = "/tmp/"; } size_t len = strlen(ret); - ret = xstrndup(ret, len >= 2 ? len - 1 : 0); // Trim trailing slash. + ret = xmemdupz(ret, len >= 2 ? len - 1 : 0); // Trim trailing slash. } return ret; -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/os/dl.c | 3 --- src/nvim/os/env.c | 5 +---- src/nvim/os/fileio.c | 4 ---- src/nvim/os/fs.c | 3 --- src/nvim/os/input.c | 3 --- src/nvim/os/lang.c | 3 --- src/nvim/os/mem.c | 3 --- src/nvim/os/os_win_console.c | 3 --- src/nvim/os/process.c | 3 --- src/nvim/os/pty_conpty_win.c | 3 --- src/nvim/os/pty_process_unix.c | 3 --- src/nvim/os/pty_process_win.c | 3 --- src/nvim/os/shell.c | 3 --- src/nvim/os/signal.c | 3 --- src/nvim/os/stdpaths.c | 3 --- src/nvim/os/time.c | 3 --- src/nvim/os/tty.c | 3 --- src/nvim/os/users.c | 3 --- 18 files changed, 1 insertion(+), 56 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/dl.c b/src/nvim/os/dl.c index 519cef7876..67164f56b4 100644 --- a/src/nvim/os/dl.c +++ b/src/nvim/os/dl.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - /// Functions for using external native libraries #include diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index dbea6f01df..20dc6a159c 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // Environment inspection #include @@ -933,7 +930,7 @@ char *vim_getenv(const char *name) if (append_path(exe_name, "share" _PATHSEPSTR "nvim" _PATHSEPSTR "runtime" _PATHSEPSTR, MAXPATHL) == OK) { - vim_path = exe_name; // -V507 + vim_path = exe_name; } } diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index 119a42f074..ed0a97aac9 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - /// @file fileio.c /// /// Buffered reading/writing to a file. Unlike fileio.c this is not dealing with @@ -53,7 +50,6 @@ int file_open(FileDescriptor *const ret_fp, const char *const fname, const int f { int os_open_flags = 0; TriState wr = kNone; - // -V:FLAG:501 #define FLAG(flags, flag, fcntl_flags, wrval, cond) \ do { \ if (flags & flag) { \ diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 9a448d69ae..6b3f79abb2 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // fs.c -- filesystem access #include #include diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 03418f4548..5c26a94196 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include #include diff --git a/src/nvim/os/lang.c b/src/nvim/os/lang.c index 602dcc9bd3..d14c086a4f 100644 --- a/src/nvim/os/lang.c +++ b/src/nvim/os/lang.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #ifdef __APPLE__ # define Boolean CFBoolean // Avoid conflict with API's Boolean # define FileInfo CSFileInfo // Avoid conflict with API's Fileinfo diff --git a/src/nvim/os/mem.c b/src/nvim/os/mem.c index 0b7e8065ef..3e6264c691 100644 --- a/src/nvim/os/mem.c +++ b/src/nvim/os/mem.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - /// Functions for accessing system memory information. #include diff --git a/src/nvim/os/os_win_console.c b/src/nvim/os/os_win_console.c index 006e27d28f..af0c28a308 100644 --- a/src/nvim/os/os_win_console.c +++ b/src/nvim/os/os_win_console.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/os/os_win_console.h" diff --git a/src/nvim/os/process.c b/src/nvim/os/process.c index a636689f97..889d1f453f 100644 --- a/src/nvim/os/process.c +++ b/src/nvim/os/process.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - /// OS process functions /// /// psutil is a good reference for cross-platform syscall voodoo: diff --git a/src/nvim/os/pty_conpty_win.c b/src/nvim/os/pty_conpty_win.c index 32067ad49f..819b6fcf77 100644 --- a/src/nvim/os/pty_conpty_win.c +++ b/src/nvim/os/pty_conpty_win.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include "nvim/os/os.h" diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c index efd476ae7b..f3a841f7d0 100644 --- a/src/nvim/os/pty_process_unix.c +++ b/src/nvim/os/pty_process_unix.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // Some of the code came from pangoterm and libuv #include diff --git a/src/nvim/os/pty_process_win.c b/src/nvim/os/pty_process_win.c index 763d30d4a2..19eedd14cd 100644 --- a/src/nvim/os/pty_process_win.c +++ b/src/nvim/os/pty_process_win.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include #include diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 2f52895357..b3ce4a3c91 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include #include diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index 4c4ac9df1e..e73a579a27 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include #include diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 8ea30ff21e..5aeecb8cda 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include #include diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index ac98f0cf9a..8aa3170963 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include #include diff --git a/src/nvim/os/tty.c b/src/nvim/os/tty.c index b5124bd83a..e683b9383f 100644 --- a/src/nvim/os/tty.c +++ b/src/nvim/os/tty.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // // Terminal/console utils // diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index b23d2b7b13..b61dcd1e4b 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // users.c -- operating system user information #include -- cgit From 4f8941c1a5f1ef6caa410feeb52e343db22763ce Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 10 Nov 2023 12:23:42 +0100 Subject: refactor: replace manual header guards with #pragma once It is less error-prone than manually defining header guards. Pretty much all compilers support it even if it's not part of the C standard. --- src/nvim/os/dl.h | 4 +--- src/nvim/os/fileio.h | 4 +--- src/nvim/os/fs.h | 4 +--- src/nvim/os/fs_defs.h | 5 +---- src/nvim/os/input.h | 4 +--- src/nvim/os/lang.h | 4 +--- src/nvim/os/os.h | 5 +---- src/nvim/os/os_defs.h | 5 +---- src/nvim/os/os_win_console.h | 5 +---- src/nvim/os/process.h | 5 +---- src/nvim/os/pty_conpty_win.h | 5 +---- src/nvim/os/pty_process.h | 4 +--- src/nvim/os/pty_process_unix.h | 5 +---- src/nvim/os/pty_process_win.h | 5 +---- src/nvim/os/shell.h | 4 +--- src/nvim/os/signal.h | 4 +--- src/nvim/os/stdpaths_defs.h | 5 +---- src/nvim/os/time.h | 4 +--- src/nvim/os/tty.h | 4 +--- src/nvim/os/unix_defs.h | 5 +---- src/nvim/os/win_defs.h | 5 +---- 21 files changed, 21 insertions(+), 74 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/dl.h b/src/nvim/os/dl.h index 302e4e6678..9c41a28f69 100644 --- a/src/nvim/os/dl.h +++ b/src/nvim/os/dl.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_DL_H -#define NVIM_OS_DL_H +#pragma once #include #include @@ -7,4 +6,3 @@ #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/dl.h.generated.h" #endif -#endif // NVIM_OS_DL_H diff --git a/src/nvim/os/fileio.h b/src/nvim/os/fileio.h index 5e47bbf921..72e7984c8a 100644 --- a/src/nvim/os/fileio.h +++ b/src/nvim/os/fileio.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_FILEIO_H -#define NVIM_OS_FILEIO_H +#pragma once #include #include @@ -75,4 +74,3 @@ enum { #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/fileio.h.generated.h" #endif -#endif // NVIM_OS_FILEIO_H diff --git a/src/nvim/os/fs.h b/src/nvim/os/fs.h index 75c24b8db2..4fe54215ba 100644 --- a/src/nvim/os/fs.h +++ b/src/nvim/os/fs.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_FS_H -#define NVIM_OS_FS_H +#pragma once #include "nvim/os/fs_defs.h" #include "nvim/types.h" @@ -7,4 +6,3 @@ #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/fs.h.generated.h" #endif -#endif // NVIM_OS_FS_H diff --git a/src/nvim/os/fs_defs.h b/src/nvim/os/fs_defs.h index f4929b12b1..e5355ddefd 100644 --- a/src/nvim/os/fs_defs.h +++ b/src/nvim/os/fs_defs.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_FS_DEFS_H -#define NVIM_OS_FS_DEFS_H +#pragma once #include @@ -26,5 +25,3 @@ typedef struct { #define NODE_WRITABLE 1 // something we can write to (character // device, fifo, socket, ..) #define NODE_OTHER 2 // non-writable thing (e.g., block device) - -#endif // NVIM_OS_FS_DEFS_H diff --git a/src/nvim/os/input.h b/src/nvim/os/input.h index d42da010f0..113dbbb8d5 100644 --- a/src/nvim/os/input.h +++ b/src/nvim/os/input.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_INPUT_H -#define NVIM_OS_INPUT_H +#pragma once #include #include @@ -13,4 +12,3 @@ EXTERN bool used_stdin INIT( = false); #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/input.h.generated.h" #endif -#endif // NVIM_OS_INPUT_H diff --git a/src/nvim/os/lang.h b/src/nvim/os/lang.h index ad64b38916..dd32378c69 100644 --- a/src/nvim/os/lang.h +++ b/src/nvim/os/lang.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_LANG_H -#define NVIM_OS_LANG_H +#pragma once #include "nvim/cmdexpand_defs.h" #include "nvim/ex_cmds_defs.h" @@ -8,4 +7,3 @@ #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/lang.h.generated.h" #endif -#endif // NVIM_OS_LANG_H diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h index 006dfbfc04..54fff5c8e3 100644 --- a/src/nvim/os/os.h +++ b/src/nvim/os/os.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_OS_H -#define NVIM_OS_OS_H +#pragma once #include #include @@ -21,5 +20,3 @@ #define ENV_LOGFILE "NVIM_LOG_FILE" #define ENV_NVIM "NVIM" - -#endif // NVIM_OS_OS_H diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h index 1e0f5b77f8..e5060a5e6a 100644 --- a/src/nvim/os/os_defs.h +++ b/src/nvim/os/os_defs.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_OS_DEFS_H -#define NVIM_OS_OS_DEFS_H +#pragma once #include #include @@ -104,5 +103,3 @@ # define S_ISLNK(m) 0 # endif #endif - -#endif // NVIM_OS_OS_DEFS_H diff --git a/src/nvim/os/os_win_console.h b/src/nvim/os/os_win_console.h index 7b5800afa8..098267312a 100644 --- a/src/nvim/os/os_win_console.h +++ b/src/nvim/os/os_win_console.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_OS_WIN_CONSOLE_H -#define NVIM_OS_OS_WIN_CONSOLE_H +#pragma once #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/os_win_console.h.generated.h" @@ -8,5 +7,3 @@ #ifndef ENABLE_VIRTUAL_TERMINAL_INPUT # define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200 #endif - -#endif // NVIM_OS_OS_WIN_CONSOLE_H diff --git a/src/nvim/os/process.h b/src/nvim/os/process.h index faa4762cf1..61a5009fd8 100644 --- a/src/nvim/os/process.h +++ b/src/nvim/os/process.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_PROCESS_H -#define NVIM_OS_PROCESS_H +#pragma once #include @@ -8,5 +7,3 @@ #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/process.h.generated.h" #endif - -#endif // NVIM_OS_PROCESS_H diff --git a/src/nvim/os/pty_conpty_win.h b/src/nvim/os/pty_conpty_win.h index c47857bdd9..aa04cd1e84 100644 --- a/src/nvim/os/pty_conpty_win.h +++ b/src/nvim/os/pty_conpty_win.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_PTY_CONPTY_WIN_H -#define NVIM_OS_PTY_CONPTY_WIN_H +#pragma once #include "klib/kvec.h" #include "nvim/os/input.h" @@ -21,5 +20,3 @@ typedef struct conpty { #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/pty_conpty_win.h.generated.h" #endif - -#endif // NVIM_OS_PTY_CONPTY_WIN_H diff --git a/src/nvim/os/pty_process.h b/src/nvim/os/pty_process.h index 07d346be22..2c7a5f66bd 100644 --- a/src/nvim/os/pty_process.h +++ b/src/nvim/os/pty_process.h @@ -1,9 +1,7 @@ -#ifndef NVIM_OS_PTY_PROCESS_H -#define NVIM_OS_PTY_PROCESS_H +#pragma once #ifdef MSWIN # include "nvim/os/pty_process_win.h" #else # include "nvim/os/pty_process_unix.h" #endif -#endif // NVIM_OS_PTY_PROCESS_H diff --git a/src/nvim/os/pty_process_unix.h b/src/nvim/os/pty_process_unix.h index 0cc68cf3e9..344e0a3423 100644 --- a/src/nvim/os/pty_process_unix.h +++ b/src/nvim/os/pty_process_unix.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_PTY_PROCESS_UNIX_H -#define NVIM_OS_PTY_PROCESS_UNIX_H +#pragma once #include #include @@ -27,5 +26,3 @@ static inline PtyProcess pty_process_init(Loop *loop, void *data) #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/pty_process_unix.h.generated.h" #endif - -#endif // NVIM_OS_PTY_PROCESS_UNIX_H diff --git a/src/nvim/os/pty_process_win.h b/src/nvim/os/pty_process_win.h index ed7d765ac7..71190380fd 100644 --- a/src/nvim/os/pty_process_win.h +++ b/src/nvim/os/pty_process_win.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_PTY_PROCESS_WIN_H -#define NVIM_OS_PTY_PROCESS_WIN_H +#pragma once #include @@ -37,5 +36,3 @@ static inline PtyProcess pty_process_init(Loop *loop, void *data) #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/pty_process_win.h.generated.h" #endif - -#endif // NVIM_OS_PTY_PROCESS_WIN_H diff --git a/src/nvim/os/shell.h b/src/nvim/os/shell.h index 48503f2601..498c72e63d 100644 --- a/src/nvim/os/shell.h +++ b/src/nvim/os/shell.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_SHELL_H -#define NVIM_OS_SHELL_H +#pragma once #include @@ -19,4 +18,3 @@ typedef enum { #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/shell.h.generated.h" #endif -#endif // NVIM_OS_SHELL_H diff --git a/src/nvim/os/signal.h b/src/nvim/os/signal.h index 5d8cc6f661..83a0a9c91b 100644 --- a/src/nvim/os/signal.h +++ b/src/nvim/os/signal.h @@ -1,7 +1,5 @@ -#ifndef NVIM_OS_SIGNAL_H -#define NVIM_OS_SIGNAL_H +#pragma once #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/signal.h.generated.h" #endif -#endif // NVIM_OS_SIGNAL_H diff --git a/src/nvim/os/stdpaths_defs.h b/src/nvim/os/stdpaths_defs.h index f94c511fe7..985688390d 100644 --- a/src/nvim/os/stdpaths_defs.h +++ b/src/nvim/os/stdpaths_defs.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_STDPATHS_DEFS_H -#define NVIM_OS_STDPATHS_DEFS_H +#pragma once /// List of possible XDG variables typedef enum { @@ -12,5 +11,3 @@ typedef enum { kXDGConfigDirs, ///< XDG_CONFIG_DIRS kXDGDataDirs, ///< XDG_DATA_DIRS } XDGVarType; - -#endif // NVIM_OS_STDPATHS_DEFS_H diff --git a/src/nvim/os/time.h b/src/nvim/os/time.h index 1b6c667dbb..8f8b5511bd 100644 --- a/src/nvim/os/time.h +++ b/src/nvim/os/time.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_TIME_H -#define NVIM_OS_TIME_H +#pragma once #include #include @@ -10,4 +9,3 @@ typedef uint64_t Timestamp; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/time.h.generated.h" #endif -#endif // NVIM_OS_TIME_H diff --git a/src/nvim/os/tty.h b/src/nvim/os/tty.h index d771e63768..3a78573189 100644 --- a/src/nvim/os/tty.h +++ b/src/nvim/os/tty.h @@ -1,7 +1,5 @@ -#ifndef NVIM_OS_TTY_H -#define NVIM_OS_TTY_H +#pragma once #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/tty.h.generated.h" #endif -#endif // NVIM_OS_TTY_H diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h index 8d002fc5e9..42d649d773 100644 --- a/src/nvim/os/unix_defs.h +++ b/src/nvim/os/unix_defs.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_UNIX_DEFS_H -#define NVIM_OS_UNIX_DEFS_H +#pragma once #include #include @@ -21,5 +20,3 @@ // Character that separates entries in $PATH. #define ENV_SEPCHAR ':' #define ENV_SEPSTR ":" - -#endif // NVIM_OS_UNIX_DEFS_H diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h index 4f8a242a51..e1bc1a727b 100644 --- a/src/nvim/os/win_defs.h +++ b/src/nvim/os/win_defs.h @@ -1,5 +1,4 @@ -#ifndef NVIM_OS_WIN_DEFS_H -#define NVIM_OS_WIN_DEFS_H +#pragma once #ifndef MSWIN # error Header must be included only when compiling for Windows. @@ -86,5 +85,3 @@ typedef int mode_t; #ifndef STDERR_FILENO # define STDERR_FILENO 2 #endif - -#endif // NVIM_OS_WIN_DEFS_H -- cgit From 28f4f3c48498086307ed825d1761edb5789ca0e8 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 15:54:54 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment - use bool to represent boolean values --- src/nvim/os/shell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index b3ce4a3c91..2fd4c732fc 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -1234,12 +1234,12 @@ static size_t word_length(const char *str) /// before we finish writing. static void read_input(DynamicBuffer *buf) { - size_t written = 0, l = 0, len = 0; + size_t written = 0, len = 0; linenr_T lnum = curbuf->b_op_start.lnum; char *lp = ml_get(lnum); while (true) { - l = strlen(lp + written); + size_t l = strlen(lp + written); if (l == 0) { len = 0; } else if (lp[written] == NL) { -- cgit From a6e3d93421ba13c407a96fac9cc01fa41ec7ad98 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 16 Nov 2023 10:59:11 +0100 Subject: refactor: enable formatting for ternaries This requires removing the "Inner expression should be aligned" rule from clint as it prevents essentially any formatting regarding ternary operators. --- src/nvim/os/dl.c | 2 +- src/nvim/os/users.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/dl.c b/src/nvim/os/dl.c index 67164f56b4..1a8d847f79 100644 --- a/src/nvim/os/dl.c +++ b/src/nvim/os/dl.c @@ -72,7 +72,7 @@ bool os_libcall(const char *libname, const char *funcname, const char *argv, int // assume that ptr values of NULL, 1 or -1 are illegal *str_out = (res && (intptr_t)res != 1 && (intptr_t)res != -1) - ? xstrdup(res) : NULL; + ? xstrdup(res) : NULL; } else { str_int_fn sfn = (str_int_fn)fn; int_int_fn ifn = (int_int_fn)fn; diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index b61dcd1e4b..f0666435cc 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -27,7 +27,7 @@ static garray_T ga_users = GA_EMPTY_INIT_VALUE; static void add_user(garray_T *users, char *user, bool need_copy) { char *user_copy = (user != NULL && need_copy) - ? xstrdup(user) : user; + ? xstrdup(user) : user; if (user_copy == NULL || *user_copy == NUL) { if (need_copy) { -- cgit From 488038580934f301c1528a14548ec0cabd16c2cd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 10 Nov 2023 14:06:04 +0100 Subject: build: adjust clang-tidy warning exclusion logic Enable all clang-tidy warnings by default instead of disabling them. This ensures that we don't miss useful warnings on each clang-tidy version upgrade. A drawback of this is that it will force us to either fix or adjust the warnings as soon as possible. --- src/nvim/os/env.c | 4 +--- src/nvim/os/lang.c | 2 +- src/nvim/os/os_win_console.c | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 20dc6a159c..ba874422ff 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -927,9 +927,7 @@ char *vim_getenv(const char *name) // Find runtime path relative to the nvim binary: ../share/nvim/runtime if (vim_path == NULL) { vim_get_prefix_from_exepath(exe_name); - if (append_path(exe_name, - "share" _PATHSEPSTR "nvim" _PATHSEPSTR "runtime" _PATHSEPSTR, - MAXPATHL) == OK) { + if (append_path(exe_name, "share/nvim/runtime/", MAXPATHL) == OK) { vim_path = exe_name; } } diff --git a/src/nvim/os/lang.c b/src/nvim/os/lang.c index d14c086a4f..e6db41a8ac 100644 --- a/src/nvim/os/lang.c +++ b/src/nvim/os/lang.c @@ -208,7 +208,7 @@ void ex_language(exarg_T *eap) #ifdef HAVE_NL_MSG_CAT_CNTR // Need to do this for GNU gettext, otherwise cached translations // will be used again. - extern int _nl_msg_cat_cntr; + extern int _nl_msg_cat_cntr; // NOLINT(bugprone-reserved-identifier) _nl_msg_cat_cntr++; #endif diff --git a/src/nvim/os/os_win_console.c b/src/nvim/os/os_win_console.c index af0c28a308..44a2b6f769 100644 --- a/src/nvim/os/os_win_console.c +++ b/src/nvim/os/os_win_console.c @@ -80,7 +80,7 @@ void os_icon_init(void) const char *vimruntime = os_getenv("VIMRUNTIME"); if (vimruntime != NULL) { - snprintf(NameBuff, MAXPATHL, "%s" _PATHSEPSTR "neovim.ico", vimruntime); + snprintf(NameBuff, MAXPATHL, "%s/neovim.ico", vimruntime); if (!os_path_exists(NameBuff)) { WLOG("neovim.ico not found: %s", NameBuff); } else { -- cgit From 4ce3159e24e18ccd53400f7066a54e01561cf586 Mon Sep 17 00:00:00 2001 From: Nik Klassen Date: Thu, 23 Nov 2023 16:28:52 -0500 Subject: fix: missing case in setxattr error handling (#26176) ENOTSUP case is present in vim, but doesn't appear to have included here. --- src/nvim/os/fs.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 6b3f79abb2..e2a6136ab4 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -795,6 +795,7 @@ void os_copy_xattr(const char *from_file, const char *to_file) case E2BIG: errmsg = e_xattr_e2big; goto error_exit; + case ENOTSUP: case EACCES: case EPERM: break; -- cgit From a827003e3052c6d9ee7bdb71518182e9bd76317d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 25 Nov 2023 11:32:32 +0100 Subject: build: rework IWYU mapping files Create mapping to most of the C spec and some POSIX specific functions. This is more robust than relying files shipped with IWYU. --- src/nvim/os/fs.c | 1 + src/nvim/os/unix_defs.h | 1 + 2 files changed, 2 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index e2a6136ab4..82916eca7b 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #ifdef MSWIN diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h index 42d649d773..b90e306932 100644 --- a/src/nvim/os/unix_defs.h +++ b/src/nvim/os/unix_defs.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #if defined(HAVE_TERMIOS_H) # include -- cgit From 6361806aa28edca55ad3316a58bc3e936df9c0eb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 26 Nov 2023 22:58:52 +0800 Subject: refactor: move garray_T to garray_defs.h (#26227) --- src/nvim/os/os.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h index 54fff5c8e3..ede9234865 100644 --- a/src/nvim/os/os.h +++ b/src/nvim/os/os.h @@ -5,7 +5,7 @@ #include "nvim/buffer_defs.h" #include "nvim/cmdexpand_defs.h" -#include "nvim/garray.h" +#include "nvim/garray_defs.h" #include "nvim/os/fs_defs.h" #include "nvim/os/stdpaths_defs.h" #include "nvim/types.h" -- cgit From 7e2387f41be7cd8304fe48bfa089f2bea155dd5a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 08:34:06 +0800 Subject: build(clint): more precise check for "defs" headers (#26236) --- src/nvim/os/process.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/process.h b/src/nvim/os/process.h index 61a5009fd8..3b116b4bad 100644 --- a/src/nvim/os/process.h +++ b/src/nvim/os/process.h @@ -1,8 +1,10 @@ #pragma once -#include +#include // IWYU pragma: keep -#include "nvim/api/private/defs.h" +#ifdef MSWIN +# include "nvim/api/private/defs.h" // IWYU pragma: keep +#endif #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/process.h.generated.h" -- cgit From 09541d514dd18bf86f673d3784d406236fcbdad8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 09:51:26 +0800 Subject: build(IWYU): replace public-to-public mappings with pragmas (#26237) --- src/nvim/os/fs.h | 2 +- src/nvim/os/os.h | 1 + src/nvim/os/pty_process_unix.h | 1 + src/nvim/os/pty_process_win.h | 1 + src/nvim/os/unix_defs.h | 9 +++++---- src/nvim/os/win_defs.h | 1 + 6 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.h b/src/nvim/os/fs.h index 4fe54215ba..aacb1c2f48 100644 --- a/src/nvim/os/fs.h +++ b/src/nvim/os/fs.h @@ -1,6 +1,6 @@ #pragma once -#include "nvim/os/fs_defs.h" +#include "nvim/os/fs_defs.h" // IWYU pragma: export #include "nvim/types.h" #ifdef INCLUDE_GENERATED_DECLARATIONS diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h index ede9234865..84c4e6668e 100644 --- a/src/nvim/os/os.h +++ b/src/nvim/os/os.h @@ -7,6 +7,7 @@ #include "nvim/cmdexpand_defs.h" #include "nvim/garray_defs.h" #include "nvim/os/fs_defs.h" +#include "nvim/os/os_defs.h" // IWYU pragma: export #include "nvim/os/stdpaths_defs.h" #include "nvim/types.h" diff --git a/src/nvim/os/pty_process_unix.h b/src/nvim/os/pty_process_unix.h index 344e0a3423..92cc582832 100644 --- a/src/nvim/os/pty_process_unix.h +++ b/src/nvim/os/pty_process_unix.h @@ -1,4 +1,5 @@ #pragma once +// IWYU pragma: private, include "nvim/os/pty_process.h" #include #include diff --git a/src/nvim/os/pty_process_win.h b/src/nvim/os/pty_process_win.h index 71190380fd..26cf387e54 100644 --- a/src/nvim/os/pty_process_win.h +++ b/src/nvim/os/pty_process_win.h @@ -1,4 +1,5 @@ #pragma once +// IWYU pragma: private, include "nvim/os/pty_process.h" #include diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h index b90e306932..fe5dce5655 100644 --- a/src/nvim/os/unix_defs.h +++ b/src/nvim/os/unix_defs.h @@ -1,10 +1,11 @@ #pragma once +// IWYU pragma: private, include "nvim/os/os_defs.h" -#include -#include -#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include // IWYU pragma: export #if defined(HAVE_TERMIOS_H) -# include +# include // IWYU pragma: export #endif // POSIX.1-2008 says that NAME_MAX should be in here diff --git a/src/nvim/os/win_defs.h b/src/nvim/os/win_defs.h index e1bc1a727b..852059f78b 100644 --- a/src/nvim/os/win_defs.h +++ b/src/nvim/os/win_defs.h @@ -1,4 +1,5 @@ #pragma once +// IWYU pragma: private, include "nvim/os/os_defs.h" #ifndef MSWIN # error Header must be included only when compiling for Windows. -- cgit From 574d25642fc9ca65b396633aeab6e2d32778b642 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 17:21:58 +0800 Subject: refactor: move Arena and ArenaMem to memory_defs.h (#26240) --- src/nvim/os/dl.h | 3 --- src/nvim/os/fs.h | 5 +++++ src/nvim/os/input.h | 4 ++-- src/nvim/os/shell.h | 4 +--- src/nvim/os/time.h | 4 ++-- src/nvim/os/tty.h | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/dl.h b/src/nvim/os/dl.h index 9c41a28f69..0787c7fe46 100644 --- a/src/nvim/os/dl.h +++ b/src/nvim/os/dl.h @@ -1,8 +1,5 @@ #pragma once -#include -#include - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/dl.h.generated.h" #endif diff --git a/src/nvim/os/fs.h b/src/nvim/os/fs.h index aacb1c2f48..3e910be801 100644 --- a/src/nvim/os/fs.h +++ b/src/nvim/os/fs.h @@ -1,5 +1,10 @@ #pragma once +#include // IWYU pragma: keep +#include // IWYU pragma: keep +#include // IWYU pragma: keep +#include // IWYU pragma: keep + #include "nvim/os/fs_defs.h" // IWYU pragma: export #include "nvim/types.h" diff --git a/src/nvim/os/input.h b/src/nvim/os/input.h index 113dbbb8d5..b077f80860 100644 --- a/src/nvim/os/input.h +++ b/src/nvim/os/input.h @@ -1,9 +1,9 @@ #pragma once #include -#include +#include // IWYU pragma: keep -#include "nvim/api/private/defs.h" +#include "nvim/api/private/defs.h" // IWYU pragma: keep #include "nvim/event/multiqueue.h" #include "nvim/macros.h" diff --git a/src/nvim/os/shell.h b/src/nvim/os/shell.h index 498c72e63d..82c83543af 100644 --- a/src/nvim/os/shell.h +++ b/src/nvim/os/shell.h @@ -1,8 +1,6 @@ #pragma once -#include - -#include "nvim/types.h" +#include // IWYU pragma: keep // Flags for os_call_shell() second argument typedef enum { diff --git a/src/nvim/os/time.h b/src/nvim/os/time.h index 8f8b5511bd..fa9989c757 100644 --- a/src/nvim/os/time.h +++ b/src/nvim/os/time.h @@ -1,8 +1,8 @@ #pragma once -#include +#include // IWYU pragma: keep #include -#include +#include // IWYU pragma: keep typedef uint64_t Timestamp; diff --git a/src/nvim/os/tty.h b/src/nvim/os/tty.h index 3a78573189..a24d875c05 100644 --- a/src/nvim/os/tty.h +++ b/src/nvim/os/tty.h @@ -1,5 +1,5 @@ #pragma once #ifdef INCLUDE_GENERATED_DECLARATIONS -# include "os/tty.h.generated.h" +# include "os/tty.h.generated.h" // IWYU pragma: export #endif -- cgit From 38a20dd89f91c45ec8589bf1c50d50732882d38a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 20:58:37 +0800 Subject: build(IWYU): replace most private mappings with pragmas (#26247) --- src/nvim/os/env.c | 1 + src/nvim/os/fileio.c | 2 +- src/nvim/os/fs.c | 2 +- src/nvim/os/os.h | 16 +++++++--------- src/nvim/os/os_win_console.c | 1 + src/nvim/os/pty_process_unix.c | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index ba874422ff..deb3117f3c 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -22,6 +22,7 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_vars.h" +#include "nvim/os/fs.h" #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/strings.h" diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index ed0a97aac9..b205481e98 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -19,7 +19,7 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/os/fileio.h" -#include "nvim/os/os.h" +#include "nvim/os/fs.h" #include "nvim/os/os_defs.h" #include "nvim/rbuffer.h" #include "nvim/types.h" diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 82916eca7b..b9448ddf4b 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -17,6 +17,7 @@ #endif #include "auto/config.h" +#include "nvim/os/fs.h" #if defined(HAVE_ACL) # ifdef HAVE_SYS_ACL_H @@ -39,7 +40,6 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_vars.h" -#include "nvim/os/fs_defs.h" #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/types.h" diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h index 84c4e6668e..e0c970f20c 100644 --- a/src/nvim/os/os.h +++ b/src/nvim/os/os.h @@ -1,19 +1,17 @@ #pragma once -#include -#include +#include // IWYU pragma: keep +#include // IWYU pragma: keep +#include // IWYU pragma: keep -#include "nvim/buffer_defs.h" -#include "nvim/cmdexpand_defs.h" -#include "nvim/garray_defs.h" -#include "nvim/os/fs_defs.h" +#include "nvim/buffer_defs.h" // IWYU pragma: keep +#include "nvim/cmdexpand_defs.h" // IWYU pragma: keep +#include "nvim/garray_defs.h" // IWYU pragma: keep #include "nvim/os/os_defs.h" // IWYU pragma: export -#include "nvim/os/stdpaths_defs.h" -#include "nvim/types.h" +#include "nvim/os/stdpaths_defs.h" // IWYU pragma: keep #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/env.h.generated.h" -# include "os/fs.h.generated.h" # include "os/mem.h.generated.h" # include "os/stdpaths.h.generated.h" # include "os/users.h.generated.h" diff --git a/src/nvim/os/os_win_console.c b/src/nvim/os/os_win_console.c index 44a2b6f769..784f97e58b 100644 --- a/src/nvim/os/os_win_console.c +++ b/src/nvim/os/os_win_console.c @@ -1,3 +1,4 @@ +#include "nvim/os/fs.h" #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/os/os_win_console.h" diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c index f3a841f7d0..d4be3086ea 100644 --- a/src/nvim/os/pty_process_unix.c +++ b/src/nvim/os/pty_process_unix.c @@ -36,7 +36,7 @@ #include "nvim/event/process.h" #include "nvim/event/stream.h" #include "nvim/log.h" -#include "nvim/os/os.h" +#include "nvim/os/fs.h" #include "nvim/os/os_defs.h" #include "nvim/os/pty_process.h" #include "nvim/os/pty_process_unix.h" -- cgit From 40139738eb479d0913ec6ce751ca5adfa50ad8c3 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 26 Nov 2023 21:36:02 +0100 Subject: build: enable IWYU on mac --- src/nvim/os/fileio.c | 4 ++++ src/nvim/os/fs.c | 2 -- src/nvim/os/process.c | 12 +++++++++--- src/nvim/os/signal.c | 6 +++++- src/nvim/os/time.c | 2 -- src/nvim/os/unix_defs.h | 17 ++++++++++------- 6 files changed, 28 insertions(+), 15 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index b205481e98..55c12f2986 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -28,6 +28,10 @@ # include "nvim/os/os_win_console.h" #endif +#ifdef HAVE_SYS_UIO_H +# include +#endif + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/fileio.c.generated.h" #endif diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index b9448ddf4b..4721bc3f1c 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -67,8 +67,6 @@ static const char e_xattr_other[] = N_("E1509: Error occurred when reading or writing extended attribute"); #endif -struct iovec; - #define RUN_UV_FS_FUNC(ret, func, ...) \ do { \ uv_fs_t req; \ diff --git a/src/nvim/os/process.c b/src/nvim/os/process.c index 889d1f453f..7b47ba7020 100644 --- a/src/nvim/os/process.c +++ b/src/nvim/os/process.c @@ -3,18 +3,19 @@ /// psutil is a good reference for cross-platform syscall voodoo: /// https://github.com/giampaolo/psutil/tree/master/psutil/arch +// IWYU pragma: no_include + #include #include #include #include -#include #include #ifdef MSWIN # include #endif -#if defined(__FreeBSD__) // XXX: OpenBSD ? +#if defined(__FreeBSD__) # include # include # include @@ -25,8 +26,13 @@ #endif #if defined(__APPLE__) || defined(BSD) -# include # include + +# include "nvim/macros.h" +#endif + +#if defined(__linux__) +# include #endif #include "nvim/log.h" diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index e73a579a27..3a861b87b4 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -1,6 +1,7 @@ #include #include #include + #ifndef MSWIN # include #endif @@ -11,9 +12,12 @@ #include "nvim/globals.h" #include "nvim/log.h" #include "nvim/main.h" -#include "nvim/memline.h" #include "nvim/os/signal.h" +#ifdef SIGPWR +# include "nvim/memline.h" +#endif + static SignalWatcher spipe, shup, squit, sterm, susr1, swinch; #ifdef SIGPWR static SignalWatcher spwr; diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index 8aa3170963..be95412c01 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -17,8 +17,6 @@ #include "nvim/os/os.h" #include "nvim/os/time.h" -struct tm; - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/time.c.generated.h" // IWYU pragma: export #endif diff --git a/src/nvim/os/unix_defs.h b/src/nvim/os/unix_defs.h index fe5dce5655..d2bec7b361 100644 --- a/src/nvim/os/unix_defs.h +++ b/src/nvim/os/unix_defs.h @@ -1,15 +1,18 @@ #pragma once // IWYU pragma: private, include "nvim/os/os_defs.h" -#include // IWYU pragma: export -#include // IWYU pragma: export -#include // IWYU pragma: export +// IWYU pragma: begin_exports +#include +#include +#include +#include +#include +#include +#include #if defined(HAVE_TERMIOS_H) -# include // IWYU pragma: export +# include #endif - -// POSIX.1-2008 says that NAME_MAX should be in here -#include +// IWYU pragma: end_exports #define TEMP_DIR_NAMES { "$TMPDIR", "/tmp", ".", "~" } #define TEMP_FILE_PATH_MAXLEN 256 -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/os/env.c | 1 + src/nvim/os/fs.c | 1 + src/nvim/os/input.c | 1 + src/nvim/os/pty_process_unix.c | 1 + src/nvim/os/shell.c | 1 + src/nvim/os/signal.c | 1 + src/nvim/os/stdpaths.c | 1 + src/nvim/os/time.c | 1 + 8 files changed, 8 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index deb3117f3c..2b1907b025 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -14,6 +14,7 @@ #include "nvim/charset.h" #include "nvim/cmdexpand.h" #include "nvim/eval.h" +#include "nvim/func_attr.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/log.h" diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 4721bc3f1c..4e320a79c4 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -17,6 +17,7 @@ #endif #include "auto/config.h" +#include "nvim/func_attr.h" #include "nvim/os/fs.h" #if defined(HAVE_ACL) diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 5c26a94196..296433d782 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -12,6 +12,7 @@ #include "nvim/event/multiqueue.h" #include "nvim/event/rstream.h" #include "nvim/event/stream.h" +#include "nvim/func_attr.h" #include "nvim/getchar.h" #include "nvim/gettext.h" #include "nvim/globals.h" diff --git a/src/nvim/os/pty_process_unix.c b/src/nvim/os/pty_process_unix.c index d4be3086ea..f801646967 100644 --- a/src/nvim/os/pty_process_unix.c +++ b/src/nvim/os/pty_process_unix.c @@ -35,6 +35,7 @@ #include "nvim/event/loop.h" #include "nvim/event/process.h" #include "nvim/event/stream.h" +#include "nvim/func_attr.h" #include "nvim/log.h" #include "nvim/os/fs.h" #include "nvim/os/os_defs.h" diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 2fd4c732fc..2d4f58e45e 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -20,6 +20,7 @@ #include "nvim/event/wstream.h" #include "nvim/ex_cmds.h" #include "nvim/fileio.h" +#include "nvim/func_attr.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/macros.h" diff --git a/src/nvim/os/signal.c b/src/nvim/os/signal.c index 3a861b87b4..c920cb655e 100644 --- a/src/nvim/os/signal.c +++ b/src/nvim/os/signal.c @@ -9,6 +9,7 @@ #include "nvim/autocmd.h" #include "nvim/eval.h" #include "nvim/event/signal.h" +#include "nvim/func_attr.h" #include "nvim/globals.h" #include "nvim/log.h" #include "nvim/main.h" diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 5aeecb8cda..3bb23dcfdc 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -4,6 +4,7 @@ #include "nvim/ascii.h" #include "nvim/fileio.h" +#include "nvim/func_attr.h" #include "nvim/globals.h" #include "nvim/memory.h" #include "nvim/os/os.h" diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index be95412c01..49b43af6c0 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -8,6 +8,7 @@ #include "auto/config.h" #include "nvim/event/loop.h" +#include "nvim/func_attr.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/log.h" -- cgit From f4aedbae4cb1f206f5b7c6142697b71dd473059b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:39:38 +0100 Subject: build(IWYU): fix includes for undo_defs.h --- src/nvim/os/shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 2d4f58e45e..ead5de32b5 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -36,7 +36,7 @@ #include "nvim/os/signal.h" #include "nvim/os/time.h" #include "nvim/path.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/profile.h" #include "nvim/rbuffer.h" #include "nvim/strings.h" -- cgit From e38a05369293293b5b510b1b0014fcc2e7cb87f4 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:46:03 +0100 Subject: build(IWYU): export generated headers --- src/nvim/os/os.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/os') diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h index e0c970f20c..cbc2be47e0 100644 --- a/src/nvim/os/os.h +++ b/src/nvim/os/os.h @@ -11,10 +11,12 @@ #include "nvim/os/stdpaths_defs.h" // IWYU pragma: keep #ifdef INCLUDE_GENERATED_DECLARATIONS +// IWYU pragma: begin_exports # include "os/env.h.generated.h" # include "os/mem.h.generated.h" # include "os/stdpaths.h.generated.h" # include "os/users.h.generated.h" +// IWYU pragma: end_exports #endif #define ENV_LOGFILE "NVIM_LOG_FILE" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/os/fileio.c | 2 +- src/nvim/os/fs.c | 2 +- src/nvim/os/fs.h | 2 +- src/nvim/os/lang.h | 2 +- src/nvim/os/shell.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index 55c12f2986..4aad4c39c6 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -22,7 +22,7 @@ #include "nvim/os/fs.h" #include "nvim/os/os_defs.h" #include "nvim/rbuffer.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #ifdef MSWIN # include "nvim/os/os_win_console.h" diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 4e320a79c4..16151086c7 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -43,7 +43,7 @@ #include "nvim/option_vars.h" #include "nvim/os/os.h" #include "nvim/path.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/vim.h" #ifdef HAVE_SYS_UIO_H diff --git a/src/nvim/os/fs.h b/src/nvim/os/fs.h index 3e910be801..8ba0177909 100644 --- a/src/nvim/os/fs.h +++ b/src/nvim/os/fs.h @@ -6,7 +6,7 @@ #include // IWYU pragma: keep #include "nvim/os/fs_defs.h" // IWYU pragma: export -#include "nvim/types.h" +#include "nvim/types_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/fs.h.generated.h" diff --git a/src/nvim/os/lang.h b/src/nvim/os/lang.h index dd32378c69..87013ccec9 100644 --- a/src/nvim/os/lang.h +++ b/src/nvim/os/lang.h @@ -2,7 +2,7 @@ #include "nvim/cmdexpand_defs.h" #include "nvim/ex_cmds_defs.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/lang.h.generated.h" diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index ead5de32b5..817448d0d2 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -41,7 +41,7 @@ #include "nvim/rbuffer.h" #include "nvim/strings.h" #include "nvim/tag.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/vim.h" -- cgit From 718053b7a97c4e2fbaa6077d3c9f4dc7012c8aad Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 28 Nov 2023 07:47:36 +0800 Subject: refactor: fix runtime_defs.h (#26259) --- src/nvim/os/fs.h | 2 +- src/nvim/os/lang.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.h b/src/nvim/os/fs.h index 8ba0177909..56dd657f70 100644 --- a/src/nvim/os/fs.h +++ b/src/nvim/os/fs.h @@ -6,7 +6,7 @@ #include // IWYU pragma: keep #include "nvim/os/fs_defs.h" // IWYU pragma: export -#include "nvim/types_defs.h" +#include "nvim/types_defs.h" // IWYU pragma: keep #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/fs.h.generated.h" diff --git a/src/nvim/os/lang.h b/src/nvim/os/lang.h index 87013ccec9..4e7bf82195 100644 --- a/src/nvim/os/lang.h +++ b/src/nvim/os/lang.h @@ -1,8 +1,8 @@ #pragma once -#include "nvim/cmdexpand_defs.h" -#include "nvim/ex_cmds_defs.h" -#include "nvim/types_defs.h" +#include "nvim/cmdexpand_defs.h" // IWYU pragma: keep +#include "nvim/ex_cmds_defs.h" // IWYU pragma: keep +#include "nvim/types_defs.h" // IWYU pragma: keep #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/lang.h.generated.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/os/env.c | 8 ++++---- src/nvim/os/fileio.c | 2 +- src/nvim/os/fs.c | 6 +++--- src/nvim/os/input.c | 6 +++--- src/nvim/os/input.h | 2 +- src/nvim/os/lang.c | 6 +++--- src/nvim/os/os_win_console.c | 2 +- src/nvim/os/process.c | 2 +- src/nvim/os/pty_conpty_win.c | 2 +- src/nvim/os/pty_process_win.c | 2 +- src/nvim/os/shell.c | 6 +++--- src/nvim/os/stdpaths.c | 2 +- src/nvim/os/time.h | 3 +-- src/nvim/os/time_defs.h | 4 ++++ src/nvim/os/users.c | 4 ++-- 15 files changed, 30 insertions(+), 27 deletions(-) create mode 100644 src/nvim/os/time_defs.h (limited to 'src/nvim/os') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index 2b1907b025..8620c79069 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -9,7 +9,7 @@ #include #include "auto/config.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/cmdexpand.h" @@ -18,8 +18,8 @@ #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/log.h" -#include "nvim/macros.h" -#include "nvim/map.h" +#include "nvim/macros_defs.h" +#include "nvim/map_defs.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_vars.h" @@ -28,7 +28,7 @@ #include "nvim/path.h" #include "nvim/strings.h" #include "nvim/version.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifdef MSWIN # include "nvim/mbyte.h" diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index 4aad4c39c6..79d6ac08e7 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -15,7 +15,7 @@ #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/log.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/os/fileio.h" diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 16151086c7..3fc9e0ab69 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -33,18 +33,18 @@ # include #endif -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/log.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_vars.h" #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/types_defs.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifdef HAVE_SYS_UIO_H # include diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 296433d782..5ae24c89ab 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -6,7 +6,7 @@ #include #include "nvim/api/private/defs.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/autocmd.h" #include "nvim/event/loop.h" #include "nvim/event/multiqueue.h" @@ -18,7 +18,7 @@ #include "nvim/globals.h" #include "nvim/keycodes.h" #include "nvim/log.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/main.h" #include "nvim/msgpack_rpc/channel.h" #include "nvim/option_vars.h" @@ -28,7 +28,7 @@ #include "nvim/profile.h" #include "nvim/rbuffer.h" #include "nvim/state.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #define READ_BUFFER_SIZE 0xfff #define INPUT_BUFFER_SIZE (READ_BUFFER_SIZE * 4) diff --git a/src/nvim/os/input.h b/src/nvim/os/input.h index b077f80860..4b104b0b50 100644 --- a/src/nvim/os/input.h +++ b/src/nvim/os/input.h @@ -5,7 +5,7 @@ #include "nvim/api/private/defs.h" // IWYU pragma: keep #include "nvim/event/multiqueue.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" EXTERN bool used_stdin INIT( = false); diff --git a/src/nvim/os/lang.c b/src/nvim/os/lang.c index e6db41a8ac..17d179a56a 100644 --- a/src/nvim/os/lang.c +++ b/src/nvim/os/lang.c @@ -12,7 +12,7 @@ #include #include "auto/config.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/cmdexpand_defs.h" @@ -20,7 +20,7 @@ #include "nvim/ex_cmds_defs.h" #include "nvim/garray.h" #include "nvim/gettext.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option.h" @@ -29,7 +29,7 @@ #include "nvim/os/shell.h" #include "nvim/path.h" #include "nvim/profile.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/lang.c.generated.h" diff --git a/src/nvim/os/os_win_console.c b/src/nvim/os/os_win_console.c index 784f97e58b..1a5ecefaa9 100644 --- a/src/nvim/os/os_win_console.c +++ b/src/nvim/os/os_win_console.c @@ -2,7 +2,7 @@ #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/os/os_win_console.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/os_win_console.c.generated.h" diff --git a/src/nvim/os/process.c b/src/nvim/os/process.c index 7b47ba7020..d9ec3a7a8a 100644 --- a/src/nvim/os/process.c +++ b/src/nvim/os/process.c @@ -28,7 +28,7 @@ #if defined(__APPLE__) || defined(BSD) # include -# include "nvim/macros.h" +# include "nvim/macros_defs.h" #endif #if defined(__linux__) diff --git a/src/nvim/os/pty_conpty_win.c b/src/nvim/os/pty_conpty_win.c index 819b6fcf77..53169c0ef8 100644 --- a/src/nvim/os/pty_conpty_win.c +++ b/src/nvim/os/pty_conpty_win.c @@ -2,7 +2,7 @@ #include "nvim/os/os.h" #include "nvim/os/pty_conpty_win.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifndef EXTENDED_STARTUPINFO_PRESENT # define EXTENDED_STARTUPINFO_PRESENT 0x00080000 diff --git a/src/nvim/os/pty_process_win.c b/src/nvim/os/pty_process_win.c index 19eedd14cd..ca2dce36ea 100644 --- a/src/nvim/os/pty_process_win.c +++ b/src/nvim/os/pty_process_win.c @@ -2,7 +2,7 @@ #include #include -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/eval/typval.h" #include "nvim/mbyte.h" #include "nvim/memory.h" diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 817448d0d2..0aaa7be2b8 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -7,7 +7,7 @@ #include "auto/config.h" #include "klib/kvec.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/charset.h" #include "nvim/eval.h" #include "nvim/eval/typval_defs.h" @@ -23,7 +23,7 @@ #include "nvim/func_attr.h" #include "nvim/gettext.h" #include "nvim/globals.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/main.h" #include "nvim/mbyte.h" #include "nvim/memline.h" @@ -43,7 +43,7 @@ #include "nvim/tag.h" #include "nvim/types_defs.h" #include "nvim/ui.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #define DYNAMIC_BUFFER_INIT { NULL, 0, 0 } #define NS_1_SECOND 1000000000U // 1 second, in nanoseconds diff --git a/src/nvim/os/stdpaths.c b/src/nvim/os/stdpaths.c index 3bb23dcfdc..7691aa5122 100644 --- a/src/nvim/os/stdpaths.c +++ b/src/nvim/os/stdpaths.c @@ -2,7 +2,7 @@ #include #include -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/fileio.h" #include "nvim/func_attr.h" #include "nvim/globals.h" diff --git a/src/nvim/os/time.h b/src/nvim/os/time.h index fa9989c757..2748ba6953 100644 --- a/src/nvim/os/time.h +++ b/src/nvim/os/time.h @@ -1,10 +1,9 @@ #pragma once #include // IWYU pragma: keep -#include #include // IWYU pragma: keep -typedef uint64_t Timestamp; +#include "nvim/os/time_defs.h" // IWYU pragma: export #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/time.h.generated.h" diff --git a/src/nvim/os/time_defs.h b/src/nvim/os/time_defs.h new file mode 100644 index 0000000000..9b71a6764d --- /dev/null +++ b/src/nvim/os/time_defs.h @@ -0,0 +1,4 @@ +#pragma once + +#include +typedef uint64_t Timestamp; diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index f0666435cc..5f77b5a6ee 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -6,12 +6,12 @@ #include #include "auto/config.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/cmdexpand_defs.h" #include "nvim/garray.h" #include "nvim/memory.h" #include "nvim/os/os.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifdef HAVE_PWD_FUNCS # include #endif -- cgit From 64b53b71ba5d804b2c8cf186be68931b2621f53c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 12:10:42 +0800 Subject: refactor(IWYU): create normal_defs.h (#26293) --- src/nvim/os/shell.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 0aaa7be2b8..994c67ae4c 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -31,7 +31,6 @@ #include "nvim/message.h" #include "nvim/option_vars.h" #include "nvim/os/fs.h" -#include "nvim/os/os_defs.h" #include "nvim/os/shell.h" #include "nvim/os/signal.h" #include "nvim/os/time.h" -- cgit From a6cba103cebce535279db197f9efeb34e9d1171f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 20:32:40 +0800 Subject: refactor: move some constants out of vim_defs.h (#26298) --- src/nvim/os/input.c | 1 - src/nvim/os/os_defs.h | 2 ++ src/nvim/os/os_win_console.c | 4 +++- src/nvim/os/shell.c | 1 + src/nvim/os/users.c | 3 +++ 5 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 5ae24c89ab..f3bd1c7ed9 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -28,7 +28,6 @@ #include "nvim/profile.h" #include "nvim/rbuffer.h" #include "nvim/state.h" -#include "nvim/vim_defs.h" #define READ_BUFFER_SIZE 0xfff #define INPUT_BUFFER_SIZE (READ_BUFFER_SIZE * 4) diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h index e5060a5e6a..9db559e7a5 100644 --- a/src/nvim/os/os_defs.h +++ b/src/nvim/os/os_defs.h @@ -41,6 +41,8 @@ // Command-processing buffer. Use large buffers for all platforms. #define CMDBUFFSIZE 1024 +#define ROOT_UID 0 + /// Converts libuv error (negative int) to error description string. #define os_strerror uv_strerror diff --git a/src/nvim/os/os_win_console.c b/src/nvim/os/os_win_console.c index 1a5ecefaa9..816e81e997 100644 --- a/src/nvim/os/os_win_console.c +++ b/src/nvim/os/os_win_console.c @@ -1,8 +1,10 @@ +#include + +#include "nvim/globals.h" #include "nvim/os/fs.h" #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/os/os_win_console.h" -#include "nvim/vim_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/os_win_console.c.generated.h" diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 994c67ae4c..191be784e8 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -38,6 +38,7 @@ #include "nvim/pos_defs.h" #include "nvim/profile.h" #include "nvim/rbuffer.h" +#include "nvim/state_defs.h" #include "nvim/strings.h" #include "nvim/tag.h" #include "nvim/types_defs.h" diff --git a/src/nvim/os/users.c b/src/nvim/os/users.c index 5f77b5a6ee..ae0994a73f 100644 --- a/src/nvim/os/users.c +++ b/src/nvim/os/users.c @@ -17,6 +17,9 @@ #endif #ifdef MSWIN # include + +# include "nvim/mbyte.h" +# include "nvim/message.h" #endif // All user names (for ~user completion as done by shell). -- cgit From 86cc791debba09c8ed1aa0d863be844108866a38 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 23:10:21 +0800 Subject: refactor: move function macros out of vim_defs.h (#26300) --- src/nvim/os/fs.c | 1 + src/nvim/os/os.h | 10 ++++++++++ src/nvim/os/os_defs.h | 10 +++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src/nvim/os') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 3fc9e0ab69..8f939c3b40 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -53,6 +53,7 @@ #ifdef MSWIN # include "nvim/mbyte.h" # include "nvim/option.h" +# include "nvim/strings.h" #endif #ifdef INCLUDE_GENERATED_DECLARATIONS diff --git a/src/nvim/os/os.h b/src/nvim/os/os.h index cbc2be47e0..302d84d066 100644 --- a/src/nvim/os/os.h +++ b/src/nvim/os/os.h @@ -10,6 +10,16 @@ #include "nvim/os/os_defs.h" // IWYU pragma: export #include "nvim/os/stdpaths_defs.h" // IWYU pragma: keep +#define HAVE_PATHDEF + +// Some file names are stored in pathdef.c, which is generated from the +// Makefile to make their value depend on the Makefile. +#ifdef HAVE_PATHDEF +extern char *default_vim_dir; +extern char *default_vimruntime_dir; +extern char *default_lib_dir; +#endif + #ifdef INCLUDE_GENERATED_DECLARATIONS // IWYU pragma: begin_exports # include "os/env.h.generated.h" diff --git a/src/nvim/os/os_defs.h b/src/nvim/os/os_defs.h index 9db559e7a5..12de55a227 100644 --- a/src/nvim/os/os_defs.h +++ b/src/nvim/os/os_defs.h @@ -6,10 +6,12 @@ #include #include +#include "auto/config.h" + // Note: Some systems need both string.h and strings.h (Savage). #include #ifdef HAVE_STRINGS_H -# include +# include // IWYU pragma: export #endif #ifdef MSWIN @@ -105,3 +107,9 @@ # define S_ISLNK(m) 0 # endif #endif + +// BSD is supposed to cover FreeBSD and similar systems. +#if (defined(BSD) || defined(__FreeBSD_kernel__)) \ + && (defined(S_ISCHR) || defined(S_IFCHR)) +# define OPEN_CHR_FILES +#endif -- cgit