[gimp] app: do not assume procedures always have a run mode.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: do not assume procedures always have a run mode.
- Date: Thu, 1 Aug 2019 16:30:35 +0000 (UTC)
commit 71d0251d2c377bfd96891fe482a6bbc7fce58efe
Author: Jehan <jehan girinstud io>
Date: Thu Aug 1 18:20:31 2019 +0200
app: do not assume procedures always have a run mode.
This is especially true since procedures are defined by plug-ins,
possibly third-party. So they may not have a first run mode parameter.
Also we don't want plug-ins to generate CRITICALs in the core
application.
Therefore before trying to get and/or set the run mode parameter, always
check that this first parameter exists, and if so, is it a GimpRunMode
enum?
Fixes similar errors:
> GIMP-CRITICAL: gimp_value_array_index: assertion 'index < value_array->n_values' failed
Moreover it also makes sense to allow plug-ins to not have such
parameter. What if you make a plug-in which always work in a single mode
and don't ever plan/want to make it work interactively for instance?
Lastly old Python 2 plug-ins didn't even have a run mode parameter (I
guess our old Python 2 wrapper was getting rid of it?).
app/actions/procedure-commands.c | 67 +++++++++++++++++++++++++++-------------
1 file changed, 46 insertions(+), 21 deletions(-)
---
diff --git a/app/actions/procedure-commands.c b/app/actions/procedure-commands.c
index d67391d774..b12fb4461e 100644
--- a/app/actions/procedure-commands.c
+++ b/app/actions/procedure-commands.c
@@ -60,7 +60,8 @@ procedure_commands_get_run_mode_arg (GimpProcedure *procedure)
n_args++;
}
- gimp_value_array_truncate (args, n_args);
+ if (n_args > 0)
+ gimp_value_array_truncate (args, n_args);
return args;
}
@@ -75,9 +76,13 @@ procedure_commands_get_data_args (GimpProcedure *procedure,
args = gimp_procedure_get_arguments (procedure);
/* initialize the first argument */
- g_value_set_enum (gimp_value_array_index (args, n_args),
- GIMP_RUN_INTERACTIVE);
- n_args++;
+ if (gimp_value_array_length (args) > n_args &&
+ GIMP_IS_PARAM_SPEC_RUN_MODE (procedure->args[n_args]))
+ {
+ g_value_set_enum (gimp_value_array_index (args, n_args),
+ GIMP_RUN_INTERACTIVE);
+ n_args++;
+ }
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_STRING (procedure->args[n_args]))
@@ -96,7 +101,8 @@ procedure_commands_get_data_args (GimpProcedure *procedure,
}
}
- gimp_value_array_truncate (args, n_args);
+ if (n_args > 0)
+ gimp_value_array_truncate (args, n_args);
return args;
}
@@ -111,9 +117,13 @@ procedure_commands_get_image_args (GimpProcedure *procedure,
args = gimp_procedure_get_arguments (procedure);
/* initialize the first argument */
- g_value_set_enum (gimp_value_array_index (args, n_args),
- GIMP_RUN_INTERACTIVE);
- n_args++;
+ if (gimp_value_array_length (args) > n_args &&
+ GIMP_IS_PARAM_SPEC_RUN_MODE (procedure->args[n_args]))
+ {
+ g_value_set_enum (gimp_value_array_index (args, n_args),
+ GIMP_RUN_INTERACTIVE);
+ n_args++;
+ }
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[n_args]))
@@ -131,7 +141,8 @@ procedure_commands_get_image_args (GimpProcedure *procedure,
}
}
- gimp_value_array_truncate (args, n_args);
+ if (n_args)
+ gimp_value_array_truncate (args, n_args);
return args;
}
@@ -147,9 +158,13 @@ procedure_commands_get_item_args (GimpProcedure *procedure,
args = gimp_procedure_get_arguments (procedure);
/* initialize the first argument */
- g_value_set_enum (gimp_value_array_index (args, n_args),
- GIMP_RUN_INTERACTIVE);
- n_args++;
+ if (gimp_value_array_length (args) > n_args &&
+ GIMP_IS_PARAM_SPEC_RUN_MODE (procedure->args[n_args]))
+ {
+ g_value_set_enum (gimp_value_array_index (args, n_args),
+ GIMP_RUN_INTERACTIVE);
+ n_args++;
+ }
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->args[n_args]))
@@ -180,7 +195,8 @@ procedure_commands_get_item_args (GimpProcedure *procedure,
}
}
- gimp_value_array_truncate (args, n_args);
+ if (n_args)
+ gimp_value_array_truncate (args, n_args);
return args;
}
@@ -196,9 +212,13 @@ procedure_commands_get_display_args (GimpProcedure *procedure,
args = gimp_procedure_get_arguments (procedure);
/* initialize the first argument */
- g_value_set_enum (gimp_value_array_index (args, n_args),
- GIMP_RUN_INTERACTIVE);
- n_args++;
+ if (gimp_value_array_length (args) > n_args &&
+ GIMP_IS_PARAM_SPEC_RUN_MODE (procedure->args[n_args]))
+ {
+ g_value_set_enum (gimp_value_array_index (args, n_args),
+ GIMP_RUN_INTERACTIVE);
+ n_args++;
+ }
if (gimp_value_array_length (args) > n_args &&
GIMP_IS_PARAM_SPEC_DISPLAY_ID (procedure->args[n_args]))
@@ -256,7 +276,8 @@ procedure_commands_get_display_args (GimpProcedure *procedure,
n_args++;
}
- gimp_value_array_truncate (args, n_args);
+ if (n_args)
+ gimp_value_array_truncate (args, n_args);
return args;
}
@@ -275,8 +296,10 @@ procedure_commands_run_procedure (GimpProcedure *procedure,
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE);
g_return_val_if_fail (args != NULL, FALSE);
- g_value_set_enum (gimp_value_array_index (args, 0),
- GIMP_RUN_NONINTERACTIVE);
+ if (gimp_value_array_length (args) > 0 &&
+ GIMP_IS_PARAM_SPEC_RUN_MODE (procedure->args[0]))
+ g_value_set_enum (gimp_value_array_index (args, 0),
+ GIMP_RUN_NONINTERACTIVE);
return_vals = gimp_procedure_execute (procedure, gimp,
gimp_get_user_context (gimp),
@@ -313,8 +336,10 @@ procedure_commands_run_procedure_async (GimpProcedure *procedure,
g_return_val_if_fail (display == NULL || GIMP_IS_DISPLAY (display), FALSE);
g_return_val_if_fail (args != NULL, FALSE);
- g_value_set_enum (gimp_value_array_index (args, 0),
- run_mode);
+ if (gimp_value_array_length (args) > 0 &&
+ GIMP_IS_PARAM_SPEC_RUN_MODE (procedure->args[0]))
+ g_value_set_enum (gimp_value_array_index (args, 0),
+ run_mode);
gimp_procedure_execute_async (procedure, gimp,
gimp_get_user_context (gimp),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]