libgimp: various fixes for !10950 review.

- There is no reason whatsoever to make gimp_param_resource_value_set_default()
  a no-op on core side. Also remove the whole commenting on this basic
  function, especially as it's mostly wrong (why would core not use
  default values? Why would we not transfer ownership? That's the whole
  point of g_value_set_object() which increases the reference, hence
  transfer ownership to the new reference…)
- Also removes the comment on GimpParamResource which is just explaining
  basic GObject stuff and would only confuse contributors.
- Small indentation or coding-style fixes.
This commit is contained in:
Jehan 2024-09-01 03:03:18 +02:00
parent 73733335c8
commit cb1f3b297c
1 changed files with 12 additions and 66 deletions

View File

@ -984,40 +984,10 @@ gimp_param_spec_display (const gchar *name,
return G_PARAM_SPEC (dspec);
}
/* Notes about GimpParamResource
*
* Similar to GimpParamColor.
* Except this does not define convenience method: get_default returning GimpResource.
* There is only value_get_default, which returns a GValue.
*
* GParamSpec and derived classes are used not only to describe args to
* long-lived GimpProcedure (which are often properties of a config)
* but to describe other properties
* and to describe args of short-lived temporary procedures (e.g. callbacks.)
* In the other uses, the default field is often not used,
* Thus the default field can be NULL.
* See gimpgpparamspecs-body.c where the default is always NULL.
*
* g_param_spec_get_default_value: this is unusual and subtle
* and not documented without reading GObject code!!!
* g_param_spec_get_default_value is a method of the superclass GParamSpec.
* It is virtual, but not pure virtual i.e. need not be reimplemented,
* and has a base implementation.
* Its implementation calls g_param_value_set_default, a virtual method
* of the superclass that subclasses should override.
* Note that it is named value_set_default, not just set_default.
* The method g_param_value_set_default does NOT set any field in a GParamSpec,
* but sets an OUT GValue.
* In pattern/idiom terms, GParamSpec.get_default_value is a "template" method.
* It calls the "abstract primitive operation" value_set_default.
* If a subclass of GParamSpec does NOT override value_set_default,
* then method GParamSpec.get_default_value calls the base implementation
* of value_set_default which returns a zero'd GValue.
*/
/*
* GIMP_TYPE_PARAM_RESOURCE
*/
/*
* GIMP_TYPE_PARAM_RESOURCE
*/
static void gimp_param_resource_class_init (GParamSpecClass *klass);
static void gimp_param_resource_init (GParamSpec *pspec);
@ -1052,14 +1022,14 @@ gimp_param_spec_display (const gchar *name,
return type;
}
static void
gimp_param_resource_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_RESOURCE;
klass->finalize = gimp_param_resource_finalize;
klass->value_validate = gimp_param_resource_validate;
klass->value_set_default = gimp_param_resource_value_set_default;
}
static void
gimp_param_resource_class_init (GParamSpecClass *klass)
{
klass->value_type = GIMP_TYPE_RESOURCE;
klass->finalize = gimp_param_resource_finalize;
klass->value_validate = gimp_param_resource_validate;
klass->value_set_default = gimp_param_resource_value_set_default;
}
static void
gimp_param_resource_init (GParamSpec *pspec)
@ -1103,37 +1073,13 @@ gimp_param_resource_validate (GParamSpec *pspec,
return FALSE;
}
/* Set gvalue from pspec's default value.
*
* Implements virtual method GParamSpec.value_get_default,
* which is called by superclass method GParamSpec.get_default_value,
* which yields a GValue that will
* "remain valid for the life of p-spec and must not be modified."
* Without this, the base implementation of GParamSpec.get_default_value
* returns a zero'ed GValue value.
*
* This does nothing on the core side.
* Core does not use the defaulting mechanism of GParamSpec for objects.
*
* When the pspec is not valid, or the pspec has a NULL default_value,
* may return with gvalue's value==NULL.
*
* Inherited by subclasses of GimpParamSpecResource.
*/
static void
gimp_param_resource_value_set_default (GParamSpec *pspec,
GValue *value)
{
#ifdef LIBGIMP_COMPILATION
g_return_if_fail (GIMP_IS_PARAM_SPEC_RESOURCE (pspec));
g_return_if_fail ( GIMP_IS_PARAM_SPEC_RESOURCE (pspec));
/* not transfer ownership */
g_value_set_object (value, GIMP_PARAM_SPEC_RESOURCE (pspec)->default_value);
#endif
/* Whether on core or libgimp, the OUT GValue might hold a NULL object pointer. */
}