mirror of
https://github.com/neovim/neovim.git
synced 2025-10-02 07:58:35 +00:00
eval: Change the point at which arg_errmsg and its length are changed
Ref #6437
This commit is contained in:
@@ -2045,11 +2045,14 @@ bool tv_islocked(const typval_T *const tv)
|
||||
///
|
||||
/// @param[in] lock Lock status.
|
||||
/// @param[in] name Variable name, used in the error message.
|
||||
/// @param[in] name_len Variable name length.
|
||||
/// @param[in] name_len Variable name length. Use #TV_TRANSLATE to translate
|
||||
/// variable name and compute the length. Use #TV_CSTRING
|
||||
/// to compute the length with strlen() without
|
||||
/// translating.
|
||||
///
|
||||
/// @return true if variable is locked, false otherwise.
|
||||
bool tv_check_lock(const VarLockStatus lock, const char *const name,
|
||||
const size_t name_len)
|
||||
bool tv_check_lock(const VarLockStatus lock, const char *name,
|
||||
size_t name_len)
|
||||
FUNC_ATTR_WARN_UNUSED_RESULT
|
||||
{
|
||||
const char *error_message = NULL;
|
||||
@@ -2068,10 +2071,17 @@ bool tv_check_lock(const VarLockStatus lock, const char *const name,
|
||||
}
|
||||
assert(error_message != NULL);
|
||||
|
||||
const char *const unknown_name = _("Unknown");
|
||||
if (name == NULL) {
|
||||
name = _("Unknown");
|
||||
name_len = strlen(name);
|
||||
} else if (name_len == TV_TRANSLATE) {
|
||||
name = _(name);
|
||||
name_len = strlen(name);
|
||||
} else if (name_len == TV_CSTRING) {
|
||||
name_len = strlen(name);
|
||||
}
|
||||
|
||||
emsgf(_(error_message), (name != NULL ? name_len : strlen(unknown_name)),
|
||||
(name != NULL ? name : unknown_name));
|
||||
emsgf(_(error_message), (int)name_len, name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -423,6 +423,17 @@ static inline bool tv_is_func(const typval_T tv)
|
||||
return tv.v_type == VAR_FUNC || tv.v_type == VAR_PARTIAL;
|
||||
}
|
||||
|
||||
/// Specify that argument needs to be translated
|
||||
///
|
||||
/// Used for size_t length arguments to avoid calling gettext() and strlen()
|
||||
/// unless needed.
|
||||
#define TV_TRANSLATE (SIZE_MAX)
|
||||
|
||||
/// Specify that argument is a NUL-terminated C string
|
||||
///
|
||||
/// Used for size_t length arguments to avoid calling strlen() unless needed.
|
||||
#define TV_CSTRING (SIZE_MAX - 1)
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "eval/typval.h.generated.h"
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user