[gegl] gegl: fix the memory management of gegl_chant_curve()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] gegl: fix the memory management of gegl_chant_curve()
- Date: Sun, 2 Jun 2013 22:42:17 +0000 (UTC)
commit 3133c01b47c29472acd8b5a8de0793091757e868
Author: Michael Natterer <mitch gimp org>
Date: Mon Jun 3 00:38:43 2013 +0200
gegl: fix the memory management of gegl_chant_curve()
Make it ref the passed default_curve, and create a new one for each
chanted property. Changed gegl_curve_default_curve() to
gegl_curve_new_default() and always return a newly allocated one. Add
gegl_curve_duplicate() because we can't use the default curve in
GeglParamCurve::value_set_default().
gegl/gegl-chant.h | 6 +++-
gegl/property-types/gegl-curve.c | 44 ++++++++++++++++++++++++++++---------
gegl/property-types/gegl-curve.h | 22 +++++++++++++++++-
3 files changed, 57 insertions(+), 15 deletions(-)
---
diff --git a/gegl/gegl-chant.h b/gegl/gegl-chant.h
index b2bafa0..09c2703 100644
--- a/gegl/gegl-chant.h
+++ b/gegl/gegl-chant.h
@@ -970,13 +970,15 @@ gegl_chant_class_intern_init (gpointer klass)
G_PARAM_CONSTRUCT |\
GEGL_PARAM_PAD_INPUT)));
#define gegl_chant_curve(name, nick, blurb) \
+ { GeglCurve *_gegl_chant_default_curve = gegl_curve_new_default (); \
g_object_class_install_property (object_class, PROP_##name, \
gegl_param_spec_curve (#name, nick, blurb,\
- gegl_curve_default_curve(),\
+ _gegl_chant_default_curve,\
(GParamFlags) ( \
G_PARAM_READWRITE |\
G_PARAM_CONSTRUCT |\
- GEGL_PARAM_PAD_INPUT)));
+ GEGL_PARAM_PAD_INPUT)));\
+ g_object_unref (_gegl_chant_default_curve); }
#include GEGL_CHANT_C_FILE
diff --git a/gegl/property-types/gegl-curve.c b/gegl/property-types/gegl-curve.c
index 68a4b57..2e42155 100644
--- a/gegl/property-types/gegl-curve.c
+++ b/gegl/property-types/gegl-curve.c
@@ -146,26 +146,48 @@ gegl_curve_new (gdouble y_min,
GeglCurve *self = GEGL_CURVE (g_object_new (GEGL_TYPE_CURVE, NULL));
GeglCurvePrivate *priv = GEGL_CURVE_GET_PRIVATE (self);
- gegl_curve_init (self);
priv->y_min = y_min;
priv->y_max = y_max;
return self;
}
-GeglCurve*
-gegl_curve_default_curve (void)
+GeglCurve *
+gegl_curve_new_default (void)
+{
+ GeglCurve *curve = gegl_curve_new (0.0, 1.0);
+
+ gegl_curve_add_point (curve, 0.0, 0.0);
+ gegl_curve_add_point (curve, 1.0, 1.0);
+
+ return curve;
+}
+
+GeglCurve *
+gegl_curve_duplicate (GeglCurve *curve)
{
- static GeglCurve *curve = NULL;
+ GeglCurve *new;
+ gdouble min_y, max_y;
+ gint n_points;
+ gint i;
+
+ g_return_val_if_fail (GEGL_IS_CURVE (curve), NULL);
+
+ gegl_curve_get_y_bounds (curve, &min_y, &max_y);
+
+ new = gegl_curve_new (min_y, max_y);
- if (curve == NULL)
+ n_points = gegl_curve_num_points (curve);
+
+ for (i = 0; i < n_points; i++)
{
- curve = gegl_curve_new (0.0, 1.0);
- gegl_curve_add_point (curve, 0.0, 0.0);
- gegl_curve_add_point (curve, 1.0, 1.0);
+ gdouble x, y;
+
+ gegl_curve_get_point (curve, i, &x, &y);
+ gegl_curve_add_point (new, x, y);
}
- return curve;
+ return new;
}
void
@@ -465,7 +487,7 @@ value_set_default (GParamSpec *param_spec,
{
GeglParamCurve *gegl_curve = GEGL_PARAM_CURVE (param_spec);
- g_value_set_object (value, gegl_curve->default_curve);
+ g_value_take_object (value, gegl_curve_duplicate (gegl_curve->default_curve));
}
GType
@@ -506,7 +528,7 @@ gegl_param_spec_curve (const gchar *name,
param_curve = g_param_spec_internal (GEGL_TYPE_PARAM_CURVE,
name, nick, blurb, flags);
- param_curve->default_curve = default_curve;
+ param_curve->default_curve = g_object_ref (default_curve);
return G_PARAM_SPEC (param_curve);
}
diff --git a/gegl/property-types/gegl-curve.h b/gegl/property-types/gegl-curve.h
index c1eb59f..8e6f602 100644
--- a/gegl/property-types/gegl-curve.h
+++ b/gegl/property-types/gegl-curve.h
@@ -65,6 +65,26 @@ GType gegl_curve_get_type (void) G_GNUC_CONST;
GeglCurve * gegl_curve_new (gdouble y_min,
gdouble y_max);
+/**
+ * gegl_curve_new_default:
+ *
+ * Create a default #GeglCurve with an identify mapping of
+ * (0.0..1.0) -> (0.0..1.0).
+ *
+ * Returns the newly created default #GeglCurve.
+ */
+GeglCurve * gegl_curve_new_default (void);
+
+/**
+ * gegl_curve_duplicate:
+ * @curve: the curve to duplicate.
+ *
+ * Create a copy of @curve.
+ *
+ * Returns the copied #GeglCurve.
+ */
+GeglCurve * gegl_curve_duplicate (GeglCurve *curve);
+
/**
* gegl_curve_get_y_bounds:
@@ -165,8 +185,6 @@ void gegl_curve_calc_values (GeglCurve *curve,
#define GEGL_TYPE_PARAM_CURVE (gegl_param_curve_get_type ())
#define GEGL_IS_PARAM_SPEC_CURVE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GEGL_TYPE_PARAM_CURVE))
-GeglCurve * gegl_curve_default_curve (void) G_GNUC_CONST;
-
GType gegl_param_curve_get_type (void) G_GNUC_CONST;
GParamSpec * gegl_param_spec_curve (const gchar *name,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]