From 49624284409185696e1d877d50cba98c11e928ea Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Sun, 4 Aug 2019 13:50:15 +0200 Subject: [PATCH] app: relax GIMP_TYPE_INT32 checks in gimp_pdb_execute_procedure_by_name() allow to pass booleans and enums to GIMP_TYPE_INT32 arguments. We didn't have them in the old plug-in API, and being less strict allows for booleans and enums being passed to old procedures transparently. --- app/pdb/gimppdb.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/app/pdb/gimppdb.c b/app/pdb/gimppdb.c index cff9051ef3..a621246d37 100644 --- a/app/pdb/gimppdb.c +++ b/app/pdb/gimppdb.c @@ -390,6 +390,7 @@ gimp_pdb_execute_procedure_by_name (GimpPDB *pdb, { GValue *value; GType arg_type; + GType value_type; gchar *error_msg = NULL; arg_type = va_arg (va_args, GType); @@ -399,10 +400,33 @@ gimp_pdb_execute_procedure_by_name (GimpPDB *pdb, value = gimp_value_array_index (args, i); - if (arg_type != G_VALUE_TYPE (value)) + value_type = G_VALUE_TYPE (value); + + /* GIMP_TYPE_INT32 is widely abused for enums and booleans in + * old plug-ins, silently copy stuff into integers when enums + * and booleans are passed + */ + if (arg_type != value_type + + && + + (value_type == G_TYPE_INT || + value_type == GIMP_TYPE_INT32) + + && + + (arg_type == G_TYPE_INT || + arg_type == GIMP_TYPE_INT32 || + arg_type == G_TYPE_BOOLEAN || + g_type_is_a (arg_type, G_TYPE_ENUM))) + { + arg_type = value_type; + } + + if (arg_type != value_type) { GError *pdb_error; - const gchar *expected = g_type_name (G_VALUE_TYPE (value)); + const gchar *expected = g_type_name (value_type); const gchar *got = g_type_name (arg_type); gimp_value_array_unref (args);