aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-07-13 16:46:05 +0100
committerLewis Russell <lewis6991@gmail.com>2023-08-31 15:08:52 +0100
commit038ac39b8e3be4a41e763442c306680633806170 (patch)
treed787aee27bfa15b25c999e6b16cfac8d95cddb04
parentaf3c667ac13e23b5ff838e720c8b26fa4a12644a (diff)
downloadrneovim-038ac39b8e3be4a41e763442c306680633806170.tar.gz
rneovim-038ac39b8e3be4a41e763442c306680633806170.tar.bz2
rneovim-038ac39b8e3be4a41e763442c306680633806170.zip
refactor(option): pass varp to set_string_option
-rw-r--r--src/nvim/option.c2
-rw-r--r--src/nvim/optionstr.c21
2 files changed, 9 insertions, 14 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 077aef052b..5a582d2d64 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -3828,7 +3828,7 @@ const char *set_option_value(const char *const name, const OptVal value, int opt
break;
}
case kOptValTypeString: {
- errmsg = set_string_option(opt_idx, v.data.string.data, opt_flags, &value_checked, errbuf,
+ errmsg = set_string_option(opt_idx, varp, v.data.string.data, opt_flags, &value_checked, errbuf,
sizeof(errbuf));
break;
}
diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c
index c68ee65fcf..17afd10ee3 100644
--- a/src/nvim/optionstr.c
+++ b/src/nvim/optionstr.c
@@ -429,19 +429,14 @@ void set_string_option_direct_in_buf(buf_T *buf, const char *name, int opt_idx,
/// #OPT_GLOBAL.
///
/// @return NULL on success, an untranslated error message on error.
-const char *set_string_option(const int opt_idx, const char *value, const int opt_flags,
- bool *value_checked, char *const errbuf, const size_t errbuflen)
+const char *set_string_option(const int opt_idx, void *varp_arg, const char *value,
+ const int opt_flags, bool *value_checked, char *const errbuf,
+ const size_t errbuflen)
FUNC_ATTR_WARN_UNUSED_RESULT
{
vimoption_T *opt = get_option(opt_idx);
- if (value == NULL) {
- value = "";
- }
-
- char **varp = (char **)get_varp_scope(opt, ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
- ? ((opt->indir & PV_BOTH) ? OPT_GLOBAL : OPT_LOCAL)
- : opt_flags));
+ void *varp = (char **)varp_arg;
char *origval_l = NULL;
char *origval_g = NULL;
@@ -450,11 +445,11 @@ const char *set_string_option(const int opt_idx, const char *value, const int op
// reset, use the global value here.
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
&& ((int)opt->indir & PV_BOTH)) {
- varp = (char **)opt->var;
+ varp = opt->var;
}
// The old value is kept until we are sure that the new value is valid.
- char *const oldval = *varp;
+ char *oldval = *(char **)varp;
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) {
origval_l = *(char **)get_varp_scope(opt, OPT_LOCAL);
@@ -476,7 +471,7 @@ const char *set_string_option(const int opt_idx, const char *value, const int op
origval = oldval;
}
- *varp = xstrdup(value);
+ *(char **)varp = xstrdup(value != NULL ? value : empty_option);
char *const saved_origval = (origval != NULL) ? xstrdup(origval) : NULL;
char *const saved_oldval_l = (origval_l != NULL) ? xstrdup(origval_l) : 0;
@@ -484,7 +479,7 @@ const char *set_string_option(const int opt_idx, const char *value, const int op
// newval (and varp) may become invalid if the buffer is closed by
// autocommands.
- char *const saved_newval = xstrdup(*varp);
+ char *const saved_newval = xstrdup(*(char **)varp);
const int secure_saved = secure;