libgimp: make sure GimpProcedures always get all their arguments

gimp_procedure_run(): fill the value array with default values so a
procedure's run callback always gets a complete value array. No more
number-of-arguments checking in any new-style plug-in.
This commit is contained in:
Michael Natterer 2019-08-03 16:56:31 +02:00
parent 5cd09366e1
commit 5b8deb68b4
1 changed files with 13 additions and 0 deletions

View File

@ -922,6 +922,7 @@ gimp_procedure_run (GimpProcedure *procedure,
{
GimpValueArray *return_vals;
GError *error = NULL;
gint i;
g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), NULL);
g_return_val_if_fail (args != NULL, NULL);
@ -939,6 +940,18 @@ gimp_procedure_run (GimpProcedure *procedure,
return return_vals;
}
/* add missing args with default values */
for (i = gimp_value_array_length (args); i < procedure->priv->n_args; i++)
{
GParamSpec *pspec = procedure->priv->args[i];
GValue value = G_VALUE_INIT;
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
g_param_value_set_default (pspec, &value);
gimp_value_array_append (args, &value);
g_value_unset (&value);
}
/* call the procedure */
return_vals = procedure->priv->run_func (procedure, args,
procedure->priv->run_data);