libgimp: add some const to input parameters, like const GimpValueArray*

for procedure arguments. This implies creating a new value array in
gimp_procedure_run() if the passed array is too short, instead of
just appending to the passed array, which was ugly anyway.
This commit is contained in:
Michael Natterer 2019-08-07 00:02:29 +02:00
parent fc33489223
commit 2599c6e071
10 changed files with 162 additions and 138 deletions

View File

@ -49,8 +49,8 @@
#include "../../libgimp/gimpgpparams-body.c"
GParamSpec *
_gimp_gp_param_def_to_param_spec (gpointer gimp,
GPParamDef *param_def)
_gimp_gp_param_def_to_param_spec (gpointer gimp,
const GPParamDef *param_def)
{
const gchar *name = param_def->name;
const gchar *nick = param_def->nick;

View File

@ -168,11 +168,11 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
}
void
_gimp_gp_param_to_value (gpointer gimp,
GPParam *param,
GType type,
GValue *value,
gboolean full_copy)
_gimp_gp_param_to_value (gpointer gimp,
const GPParam *param,
GType type,
GValue *value,
gboolean full_copy)
{
g_return_if_fail (param != NULL);
g_return_if_fail (value != NULL);
@ -327,13 +327,13 @@ _gimp_gp_param_to_value (gpointer gimp,
}
GimpValueArray *
_gimp_gp_params_to_value_array (gpointer gimp,
GParamSpec **pspecs,
gint n_pspecs,
GPParam *params,
gint n_params,
gboolean return_values,
gboolean full_copy)
_gimp_gp_params_to_value_array (gpointer gimp,
GParamSpec **pspecs,
gint n_pspecs,
const GPParam *params,
gint n_params,
gboolean return_values,
gboolean full_copy)
{
GimpValueArray *args;
gint i;
@ -570,8 +570,8 @@ _gimp_value_to_gp_param (const GValue *value,
}
GPParam *
_gimp_value_array_to_gp_params (GimpValueArray *args,
gboolean full_copy)
_gimp_value_array_to_gp_params (const GimpValueArray *args,
gboolean full_copy)
{
GPParam *params;
gint length;

View File

@ -40,8 +40,8 @@
#include "gimpgpparams-body.c"
GParamSpec *
_gimp_gp_param_def_to_param_spec (gpointer gimp,
GPParamDef *param_def)
_gimp_gp_param_def_to_param_spec (gpointer gimp,
const GPParamDef *param_def)
{
const gchar *name = param_def->name;
const gchar *nick = param_def->nick;

View File

@ -25,30 +25,30 @@
G_BEGIN_DECLS
GParamSpec * _gimp_gp_param_def_to_param_spec (gpointer gimp,
GPParamDef *param_def);
GParamSpec * _gimp_gp_param_def_to_param_spec (gpointer gimp,
const GPParamDef *param_def);
void _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
GPParamDef *param_def);
void _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
GPParamDef *param_def);
void _gimp_gp_param_to_value (gpointer gimp,
GPParam *param,
GType type,
GValue *value,
gboolean full_copy);
GimpValueArray * _gimp_gp_params_to_value_array (gpointer gimp,
GParamSpec **pspecs,
gint n_pspecs,
GPParam *params,
gint n_params,
gboolean return_values,
gboolean full_copy);
void _gimp_gp_param_to_value (gpointer gimp,
const GPParam *param,
GType type,
GValue *value,
gboolean full_copy);
GimpValueArray * _gimp_gp_params_to_value_array (gpointer gimp,
GParamSpec **pspecs,
gint n_pspecs,
const GPParam *params,
gint n_params,
gboolean return_values,
gboolean full_copy);
void _gimp_value_to_gp_param (const GValue *value,
GPParam *param,
gboolean full_copy);
GPParam * _gimp_value_array_to_gp_params (GimpValueArray *args,
gboolean full_copy);
void _gimp_value_to_gp_param (const GValue *value,
GPParam *param,
gboolean full_copy);
GPParam * _gimp_value_array_to_gp_params (const GimpValueArray *args,
gboolean full_copy);
G_END_DECLS

View File

@ -787,8 +787,8 @@ gimp_run_procedure2 (const gchar *name,
}
GimpValueArray *
gimp_run_procedure_array (const gchar *name,
GimpValueArray *arguments)
gimp_run_procedure_array (const gchar *name,
const GimpValueArray *arguments)
{
GPProcRun proc_run;
GPProcReturn *proc_return;

View File

@ -268,8 +268,8 @@ GimpParam * gimp_run_procedure2 (const gchar *name,
/* Run a procedure in the procedure database. The parameters are
* specified as a GimpValueArray, so are the return values.
*/
GimpValueArray * gimp_run_procedure_array (const gchar *name,
GimpValueArray *arguments);
GimpValueArray * gimp_run_procedure_array (const gchar *name,
const GimpValueArray *arguments);
/* Destroy the an array of parameters. This is useful for
* destroying the return values returned by a call to

View File

@ -246,9 +246,9 @@ gimp_pdb_run_procedure_valist (GimpPDB *pdb,
* Returns: (transfer full): the returned values for the procedure call.
*/
GimpValueArray *
gimp_pdb_run_procedure_array (GimpPDB *pdb,
const gchar *procedure_name,
GimpValueArray *arguments)
gimp_pdb_run_procedure_array (GimpPDB *pdb,
const gchar *procedure_name,
const GimpValueArray *arguments)
{
GPProcRun proc_run;
GPProcReturn *proc_return;

View File

@ -67,23 +67,23 @@ struct _GimpPDBClass
GType gimp_pdb_get_type (void) G_GNUC_CONST;
gboolean gimp_pdb_procedure_exists (GimpPDB *pdb,
const gchar *procedure_name);
gboolean gimp_pdb_procedure_exists (GimpPDB *pdb,
const gchar *procedure_name);
GimpProcedure * gimp_pdb_lookup_procedure (GimpPDB *pdb,
const gchar *procedure_name);
GimpProcedure * gimp_pdb_lookup_procedure (GimpPDB *pdb,
const gchar *procedure_name);
GimpValueArray * gimp_pdb_run_procedure (GimpPDB *pdb,
const gchar *procedure_name,
GType first_type,
GimpValueArray * gimp_pdb_run_procedure (GimpPDB *pdb,
const gchar *procedure_name,
GType first_type,
...);
GimpValueArray * gimp_pdb_run_procedure_valist (GimpPDB *pdb,
const gchar *procedure_name,
GType first_type,
va_list args);
GimpValueArray * gimp_pdb_run_procedure_array (GimpPDB *pdb,
const gchar *procedure_name,
GimpValueArray *arguments);
GimpValueArray * gimp_pdb_run_procedure_valist (GimpPDB *pdb,
const gchar *procedure_name,
GType first_type,
va_list args);
GimpValueArray * gimp_pdb_run_procedure_array (GimpPDB *pdb,
const gchar *procedure_name,
const GimpValueArray *arguments);
/* Cruft API */

View File

@ -95,7 +95,7 @@ static GimpValueArray *
static gboolean gimp_procedure_validate_args (GimpProcedure *procedure,
GParamSpec **param_specs,
gint n_param_specs,
GimpValueArray *args,
const GimpValueArray *args,
gboolean return_vals,
GError **error);
@ -1042,8 +1042,8 @@ gimp_procedure_new_return_values (GimpProcedure *procedure,
* Since: 3.0
**/
GimpValueArray *
gimp_procedure_run (GimpProcedure *procedure,
GimpValueArray *args)
gimp_procedure_run (GimpProcedure *procedure,
const GimpValueArray *args)
{
GimpValueArray *return_vals;
GError *error = NULL;
@ -1066,19 +1066,43 @@ gimp_procedure_run (GimpProcedure *procedure,
}
/* add missing args with default values */
for (i = gimp_value_array_length (args); i < procedure->priv->n_args; i++)
if (gimp_value_array_length (args) < procedure->priv->n_args)
{
GParamSpec *pspec = procedure->priv->args[i];
GValue value = G_VALUE_INIT;
GimpValueArray *complete = gimp_value_array_new (0);
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);
for (i = 0; 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));
if (i < gimp_value_array_length (args))
{
GValue *orig = gimp_value_array_index (args, i);
g_value_copy (orig, &value);
}
else
{
g_param_value_set_default (pspec, &value);
}
gimp_value_array_append (complete, &value);
g_value_unset (&value);
}
/* call the procedure */
return_vals = GIMP_PROCEDURE_GET_CLASS (procedure)->run (procedure,
complete);
gimp_value_array_unref (complete);
}
else
{
/* call the procedure */
return_vals = GIMP_PROCEDURE_GET_CLASS (procedure)->run (procedure,
args);
}
/* call the procedure */
return_vals = GIMP_PROCEDURE_GET_CLASS (procedure)->run (procedure, args);
if (! return_vals)
{
@ -1127,12 +1151,12 @@ gimp_procedure_extension_ready (GimpProcedure *procedure)
/* private functions */
static gboolean
gimp_procedure_validate_args (GimpProcedure *procedure,
GParamSpec **param_specs,
gint n_param_specs,
GimpValueArray *args,
gboolean return_vals,
GError **error)
gimp_procedure_validate_args (GimpProcedure *procedure,
GParamSpec **param_specs,
gint n_param_specs,
const GimpValueArray *args,
gboolean return_vals,
GError **error)
{
gint i;

View File

@ -88,79 +88,79 @@ struct _GimpProcedureClass
GType gimp_procedure_get_type (void) G_GNUC_CONST;
GimpProcedure * gimp_procedure_new (GimpPlugIn *plug_in,
const gchar *name,
GimpPDBProcType proc_type,
GimpRunFunc run_func,
gpointer run_data,
GDestroyNotify run_data_destroy);
GimpProcedure * gimp_procedure_new (GimpPlugIn *plug_in,
const gchar *name,
GimpPDBProcType proc_type,
GimpRunFunc run_func,
gpointer run_data,
GDestroyNotify run_data_destroy);
GimpPlugIn * gimp_procedure_get_plug_in (GimpProcedure *procedure);
const gchar * gimp_procedure_get_name (GimpProcedure *procedure);
GimpPDBProcType gimp_procedure_get_proc_type (GimpProcedure *procedure);
GimpPlugIn * gimp_procedure_get_plug_in (GimpProcedure *procedure);
const gchar * gimp_procedure_get_name (GimpProcedure *procedure);
GimpPDBProcType gimp_procedure_get_proc_type (GimpProcedure *procedure);
void gimp_procedure_set_image_types (GimpProcedure *procedure,
const gchar *image_types);
const gchar * gimp_procedure_get_image_types (GimpProcedure *procedure);
void gimp_procedure_set_image_types (GimpProcedure *procedure,
const gchar *image_types);
const gchar * gimp_procedure_get_image_types (GimpProcedure *procedure);
void gimp_procedure_set_menu_label (GimpProcedure *procedure,
const gchar *menu_label);
const gchar * gimp_procedure_get_menu_label (GimpProcedure *procedure);
void gimp_procedure_set_menu_label (GimpProcedure *procedure,
const gchar *menu_label);
const gchar * gimp_procedure_get_menu_label (GimpProcedure *procedure);
void gimp_procedure_add_menu_path (GimpProcedure *procedure,
const gchar *menu_path);
GList * gimp_procedure_get_menu_paths (GimpProcedure *procedure);
void gimp_procedure_add_menu_path (GimpProcedure *procedure,
const gchar *menu_path);
GList * gimp_procedure_get_menu_paths (GimpProcedure *procedure);
void gimp_procedure_set_documentation (GimpProcedure *procedure,
const gchar *blurb,
const gchar *help,
const gchar *help_id);
const gchar * gimp_procedure_get_blurb (GimpProcedure *procedure);
const gchar * gimp_procedure_get_help (GimpProcedure *procedure);
const gchar * gimp_procedure_get_help_id (GimpProcedure *procedure);
void gimp_procedure_set_documentation (GimpProcedure *procedure,
const gchar *blurb,
const gchar *help,
const gchar *help_id);
const gchar * gimp_procedure_get_blurb (GimpProcedure *procedure);
const gchar * gimp_procedure_get_help (GimpProcedure *procedure);
const gchar * gimp_procedure_get_help_id (GimpProcedure *procedure);
void gimp_procedure_set_attribution (GimpProcedure *procedure,
const gchar *authors,
const gchar *copyright,
const gchar *date);
const gchar * gimp_procedure_get_authors (GimpProcedure *procedure);
const gchar * gimp_procedure_get_copyright (GimpProcedure *procedure);
const gchar * gimp_procedure_get_date (GimpProcedure *procedure);
void gimp_procedure_set_attribution (GimpProcedure *procedure,
const gchar *authors,
const gchar *copyright,
const gchar *date);
const gchar * gimp_procedure_get_authors (GimpProcedure *procedure);
const gchar * gimp_procedure_get_copyright (GimpProcedure *procedure);
const gchar * gimp_procedure_get_date (GimpProcedure *procedure);
void gimp_procedure_set_icon (GimpProcedure *procedure,
GimpIconType icon_type,
const guint8 *icon_data);
GimpIconType gimp_procedure_get_icon (GimpProcedure *procedure,
const guint8 **icon_data,
gint *icon_data_length);
void gimp_procedure_set_icon (GimpProcedure *procedure,
GimpIconType icon_type,
const guint8 *icon_data);
GimpIconType gimp_procedure_get_icon (GimpProcedure *procedure,
const guint8 **icon_data,
gint *icon_data_length);
void gimp_procedure_add_argument (GimpProcedure *procedure,
GParamSpec *pspec);
void gimp_procedure_add_argument (GimpProcedure *procedure,
GParamSpec *pspec);
void gimp_procedure_add_argument_from_property
(GimpProcedure *procedure,
GObject *config,
const gchar *prop_name);
void gimp_procedure_add_return_value (GimpProcedure *procedure,
GParamSpec *pspec);
(GimpProcedure *procedure,
GObject *config,
const gchar *prop_name);
void gimp_procedure_add_return_value (GimpProcedure *procedure,
GParamSpec *pspec);
void gimp_procedure_add_return_value_from_property
(GimpProcedure *procedure,
GObject *config,
const gchar *prop_name);
(GimpProcedure *procedure,
GObject *config,
const gchar *prop_name);
GParamSpec ** gimp_procedure_get_arguments (GimpProcedure *procedure,
gint *n_arguments);
GParamSpec ** gimp_procedure_get_return_values (GimpProcedure *procedure,
gint *n_return_values);
GParamSpec ** gimp_procedure_get_arguments (GimpProcedure *procedure,
gint *n_arguments);
GParamSpec ** gimp_procedure_get_return_values (GimpProcedure *procedure,
gint *n_return_values);
GimpValueArray * gimp_procedure_new_arguments (GimpProcedure *procedure);
GimpValueArray * gimp_procedure_new_return_values (GimpProcedure *procedure,
GimpPDBStatusType status,
GError *error);
GimpValueArray * gimp_procedure_new_arguments (GimpProcedure *procedure);
GimpValueArray * gimp_procedure_new_return_values (GimpProcedure *procedure,
GimpPDBStatusType status,
GError *error);
GimpValueArray * gimp_procedure_run (GimpProcedure *procedure,
GimpValueArray *args);
GimpValueArray * gimp_procedure_run (GimpProcedure *procedure,
const GimpValueArray *args);
void gimp_procedure_extension_ready (GimpProcedure *procedure);
void gimp_procedure_extension_ready (GimpProcedure *procedure);
G_END_DECLS