eval_call_provider(): free unused return value #12819

Caller can pass discard=true to free the unwanted return value.
This commit is contained in:
Jacques Germishuys 2020-09-02 04:22:42 +01:00 committed by GitHub
parent 4bcf54478a
commit a166c2aadb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 9 deletions

View File

@ -103,8 +103,10 @@ Examples:
The provider framework invokes VimL from C. It is composed of two functions
in eval.c:
- eval_call_provider(name, method, arguments): calls provider#{name}#Call
with the method and arguments.
- eval_call_provider(name, method, arguments, discard): calls
provider#{name}#Call with the method and arguments. If discard is true, any
value returned by the provider will be discarded and and empty value be
returned.
- eval_has_provider(name): Checks the `g:loaded_{name}_provider` variable
which must be set to 2 by the provider script to indicate that it is
"enabled and working". Called by |has()| to check if features are available.

View File

@ -10383,10 +10383,13 @@ void script_host_eval(char *name, typval_T *argvars, typval_T *rettv)
list_T *args = tv_list_alloc(1);
tv_list_append_string(args, (const char *)argvars[0].vval.v_string, -1);
*rettv = eval_call_provider(name, "eval", args);
*rettv = eval_call_provider(name, "eval", args, false);
}
typval_T eval_call_provider(char *provider, char *method, list_T *arguments)
/// @param discard Clears the value returned by the provider and returns
/// an empty typval_T.
typval_T eval_call_provider(char *provider, char *method, list_T *arguments,
bool discard)
{
if (!eval_has_provider(provider)) {
emsgf("E319: No \"%s\" provider found. Run \":checkhealth provider\"",
@ -10445,6 +10448,10 @@ typval_T eval_call_provider(char *provider, char *method, list_T *arguments)
provider_call_nesting--;
assert(provider_call_nesting >= 0);
if (discard) {
tv_clear(&rettv);
}
return rettv;
}

View File

@ -4157,7 +4157,7 @@ static void script_host_execute(char *name, exarg_T *eap)
tv_list_append_number(args, (int)eap->line1);
tv_list_append_number(args, (int)eap->line2);
(void)eval_call_provider(name, "execute", args);
(void)eval_call_provider(name, "execute", args, true);
}
}
@ -4172,7 +4172,7 @@ static void script_host_execute_file(char *name, exarg_T *eap)
// current range
tv_list_append_number(args, (int)eap->line1);
tv_list_append_number(args, (int)eap->line2);
(void)eval_call_provider(name, "execute_file", args);
(void)eval_call_provider(name, "execute_file", args, true);
}
static void script_host_do_range(char *name, exarg_T *eap)
@ -4181,7 +4181,7 @@ static void script_host_do_range(char *name, exarg_T *eap)
tv_list_append_number(args, (int)eap->line1);
tv_list_append_number(args, (int)eap->line2);
tv_list_append_string(args, (const char *)eap->arg, -1);
(void)eval_call_provider(name, "do_range", args);
(void)eval_call_provider(name, "do_range", args, true);
}
/// ":drop"

View File

@ -5919,7 +5919,7 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet)
const char regname = (char)name;
tv_list_append_string(args, &regname, 1);
typval_T result = eval_call_provider("clipboard", "get", args);
typval_T result = eval_call_provider("clipboard", "get", args, false);
if (result.v_type != VAR_LIST) {
if (result.v_type == VAR_NUMBER && result.vval.v_number == 0) {
@ -6067,7 +6067,7 @@ static void set_clipboard(int name, yankreg_T *reg)
tv_list_append_string(args, &regtype, 1); // -V614
tv_list_append_string(args, ((char[]) { (char)name }), 1);
(void)eval_call_provider("clipboard", "set", args);
(void)eval_call_provider("clipboard", "set", args, true);
}
/// Avoid slow things (clipboard) during batch operations (while/for-loops).