Commit 5499882d authored by Debarshi Ray's avatar Debarshi Ray

operations: Simplify code

Leverage modern GLib API like g_clear_*, and the fact that g_free is
already NULL-safe.

https://bugzilla.gnome.org/show_bug.cgi?id=789543
parent 0d0c1817
......@@ -450,14 +450,9 @@ operation_process (GeglOperation *operation,
success = process (operation, input, aux, aux2, output, result, level);
}
if (input != NULL)
g_object_unref (input);
if (aux != NULL)
g_object_unref (aux);
if (aux2 != NULL)
g_object_unref (aux2);
g_clear_object (&input);
g_clear_object (&aux);
g_clear_object (&aux2);
return success;
}
......
......@@ -189,8 +189,7 @@ dispose (GObject *object)
g_signal_handler_disconnect (o->buffer, p->buffer_changed_handler);
/* XXX: should decrement signal connected count */
g_object_unref (o->buffer);
o->buffer = NULL;
g_clear_object (&o->buffer);
}
if (p)
......
......@@ -93,11 +93,7 @@ finalize (GObject *object)
{
GeglProperties *o = GEGL_PROPERTIES (object);
if (o->user_data)
{
g_free (o->user_data);
o->user_data = NULL;
}
g_clear_pointer (&o->user_data, g_free);
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
......@@ -114,11 +110,7 @@ notify (GObject *object,
/* one of the properties has changed,
* invalidate the preprocessed coefficients
*/
if (o->user_data)
{
g_free (o->user_data);
o->user_data = NULL;
}
g_clear_pointer (&o->user_data, g_free);
}
if (G_OBJECT_CLASS (gegl_op_parent_class)->notify)
......
......@@ -158,8 +158,7 @@ cl_process (GeglOperation *self,
g_free (ysf);
return FALSE;
error:
if (ysf)
g_free (ysf);
g_free (ysf);
if (cl_curve)
gegl_clReleaseMemObject (cl_curve);
......
......@@ -67,8 +67,7 @@ prepare (GeglOperation *operation)
if (!o->user_data || !g_str_equal (o->user_data, o->string))
{
if (o->user_data)
g_free (o->user_data);
g_free (o->user_data);
o->user_data = g_strdup (o->string);
input = gegl_node_get_input_proxy (gegl, "input");
......@@ -86,8 +85,7 @@ prepare (GeglOperation *operation)
if (error)
{
gegl_node_set (gegl, "error", error->message, NULL);
g_error_free (error);
error = NULL;
g_clear_error (&error);
}
else
g_object_set (operation, "error", "", NULL);
......
......@@ -92,11 +92,7 @@ gegl_introspect_dispose (GObject *object)
{
GeglProperties *o = GEGL_PROPERTIES (object);
if (o->user_data != NULL)
{
g_object_unref (o->user_data);
o->user_data = NULL;
}
g_clear_object (&o->user_data);
G_OBJECT_CLASS (gegl_op_parent_class)->dispose (object);
}
......
......@@ -104,8 +104,7 @@ do_setup (GeglOperation *operation)
if (self->cached_path != NULL)
{
gegl_node_link (self->input, self->output);
g_free (self->cached_path);
self->cached_path = NULL;
g_clear_pointer (&self->cached_path, g_free);
}
return;
......@@ -119,8 +118,7 @@ do_setup (GeglOperation *operation)
gegl_node_set (self->composite_op,
"operation", o->composite_op,
NULL);
if (self->p_composite_op)
g_free (self->p_composite_op);
g_free (self->p_composite_op);
self->p_composite_op = g_strdup (o->composite_op);
}
......@@ -142,8 +140,7 @@ do_setup (GeglOperation *operation)
if (!self->cached_path)
gegl_node_link_many (self->input, self->composite_op, self->output, NULL);
if (self->cached_path)
g_free (self->cached_path);
g_free (self->cached_path);
self->cached_path = g_strdup (o->src);
}
......@@ -243,10 +240,8 @@ finalize (GObject *object)
{
GeglOp *self = GEGL_OP (object);
if (self->cached_path)
g_free (self->cached_path);
if (self->p_composite_op)
g_free (self->p_composite_op);
g_free (self->cached_path);
g_free (self->p_composite_op);
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
......
......@@ -116,9 +116,9 @@ static void finalize (GObject *object)
{
GeglOperation *op = (void*) object;
GeglProperties *o = GEGL_PROPERTIES (op);
if (o->user_data)
g_object_unref (o->user_data);
o->user_data = NULL;
g_clear_object (&o->user_data);
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
......
......@@ -431,7 +431,6 @@ mantiuk06_matrix_alloc (guint size)
static inline void
mantiuk06_matrix_free (gfloat *m)
{
g_return_if_fail (m);
g_free (m);
}
......@@ -650,17 +649,8 @@ mantiuk06_pyramid_free (pyramid_t *pyramid)
{
pyramid_t *const next = pyramid->next;
if (pyramid->Gx != NULL)
{
g_free (pyramid->Gx);
pyramid->Gx = NULL;
}
if (pyramid->Gy != NULL)
{
g_free (pyramid->Gy);
pyramid->Gy = NULL;
}
g_clear_pointer (&pyramid->Gx, g_free);
g_clear_pointer (&pyramid->Gy, g_free);
pyramid->prev = NULL;
pyramid->next = NULL;
......
......@@ -116,9 +116,7 @@ finalize (GObject *object)
Priv *p = (Priv*)o->user_data;
g_object_unref (p->acc);
g_free (o->user_data);
o->user_data = NULL;
g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
......
......@@ -174,8 +174,7 @@ gegl_save_dispose (GObject *object)
{
GeglOp *self = GEGL_OP (object);
g_free (self->cached_path);
self->cached_path = NULL;
g_clear_pointer (&self->cached_path, g_free);
G_OBJECT_CLASS (gegl_op_parent_class)->dispose (object);
}
......
......@@ -98,19 +98,8 @@ clear_cache (GeglProperties *o)
if (! priv)
return;
if (priv->lookup)
{
g_free (priv->lookup);
priv->lookup = NULL;
}
if (priv->buffer)
{
g_object_unref (priv->buffer);
priv->buffer = NULL;
}
g_clear_pointer (&priv->lookup, g_free);
g_clear_object (&priv->buffer);
while (priv->processed_stroke)
{
......
......@@ -353,11 +353,8 @@ operation_process (GeglOperation *operation,
success = process (operation, input, aux, output, result, level);
}
if (input != NULL)
g_object_unref (input);
if (aux != NULL)
g_object_unref (aux);
g_clear_object (&input);
g_clear_object (&aux);
return success;
}
......
......@@ -122,11 +122,7 @@ dispose (GObject *object)
{
GeglProperties *o = GEGL_PROPERTIES (object);
if (o->buffer)
{
g_object_unref (o->buffer);
o->buffer = NULL;
}
g_clear_object (&o->buffer);
G_OBJECT_CLASS (gegl_op_parent_class)->dispose (object);
}
......
......@@ -59,11 +59,7 @@ process (GeglOperation *operation,
if (o->cache != (void *) operation->node->cache)
{
if (o->cache)
{
g_object_unref (o->cache);
o->cache = NULL;
}
g_clear_object (&o->cache);
if (operation->node->cache)
o->cache = g_object_ref (operation->node->cache);
......
......@@ -269,8 +269,7 @@ cleanup:
g_object_unref (stream);
}
if (file != NULL)
g_object_unref (file);
g_clear_object (&file);
g_free (buffer);
......
......@@ -139,8 +139,7 @@ ff_cleanup (GeglProperties *o)
if (p)
{
clear_audio_track (o);
if (p->loadedfilename)
g_free (p->loadedfilename);
g_free (p->loadedfilename);
if (p->video_stream && p->video_stream->codec)
avcodec_close (p->video_stream->codec);
if (p->audio_stream && p->audio_stream->codec)
......@@ -502,22 +501,19 @@ prepare (GeglOperation *operation)
p->height = p->video_stream->codec->height;
p->lavc_frame = av_frame_alloc ();
if (o->video_codec)
g_free (o->video_codec);
g_free (o->video_codec);
if (p->video_codec->name)
o->video_codec = g_strdup (p->video_codec->name);
else
o->video_codec = g_strdup ("");
if (o->audio_codec)
g_free (o->audio_codec);
g_free (o->audio_codec);
if (p->audio_codec && p->audio_codec->name)
o->audio_codec = g_strdup (p->audio_codec->name);
else
o->audio_codec = g_strdup ("");
if (p->loadedfilename)
g_free (p->loadedfilename);
g_free (p->loadedfilename);
p->loadedfilename = g_strdup (o->path);
p->prevframe = -1;
p->a_prevframe = -1;
......@@ -750,8 +746,7 @@ finalize (GObject *object)
ff_cleanup (o);
g_free (p->loadedfilename);
g_free (o->user_data);
o->user_data = NULL;
g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
......
......@@ -1085,8 +1085,7 @@ finalize (GObject *object)
avio_closep (&p->oc->pb);
avformat_free_context (p->oc);
g_free (o->user_data);
o->user_data = NULL;
g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (g_type_class_peek_parent (G_OBJECT_GET_CLASS (object)))->finalize (object);
......
......@@ -461,11 +461,8 @@ process (GeglOperation *operation,
if (matrices[i])
jas_matrix_destroy (matrices[i]);
if (data_b)
g_free (data_b);
if (data_s)
g_free (data_s);
g_free (data_b);
g_free (data_s);
return ret;
}
......@@ -501,9 +498,7 @@ finalize(GObject *object)
if (o->user_data != NULL)
{
cleanup(GEGL_OPERATION(object));
if (o->user_data != NULL)
g_free(o->user_data);
o->user_data = NULL;
g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS(gegl_op_parent_class)->finalize(object);
......
......@@ -306,7 +306,7 @@ gegl_jpg_load_get_bounding_box (GeglOperation *operation)
gegl_operation_set_format (operation, "output", format);
g_object_unref(stream);
if (file) g_object_unref(file);
g_clear_object(&file);
if (err || status)
return (GeglRectangle) {0, 0, 0, 0};
else
......
......@@ -193,12 +193,8 @@ process (GeglOperation *operation,
}
cleanup:
if (stream != NULL)
g_object_unref (stream);
if (file != NULL)
g_object_unref (file);
g_clear_object (&stream);
g_clear_object (&file);
return status;
}
......
......@@ -243,8 +243,7 @@ gegl_path_stamp (GeglBuffer *buffer,
if (s.buf == NULL ||
s.radius != radius)
{
if (s.buf != NULL)
g_free (s.buf);
g_free (s.buf);
/* allocate a little bit more, just in case due to rounding errors and
* such */
s.buf = g_malloc (4*4* (roi.width + 2 ) * (roi.height + 2));
......
......@@ -207,8 +207,7 @@ gegl_buffer_import_png (GeglBuffer *gegl_buffer,
if (setjmp (png_jmpbuf (load_png_ptr)))
{
png_destroy_read_struct (&load_png_ptr, &load_info_ptr, NULL);
if (row_p)
g_free (row_p);
g_free (row_p);
return -1;
}
......@@ -370,8 +369,7 @@ static gint query_png (GInputStream *stream,
if (setjmp (png_jmpbuf (load_png_ptr)))
{
png_destroy_read_struct (&load_png_ptr, &load_info_ptr, NULL);
if (row_p)
g_free (row_p);
g_free (row_p);
return -1;
}
......@@ -436,7 +434,7 @@ get_bounding_box (GeglOperation *operation)
result.width = width;
result.height = height;
if (infile) g_object_unref(infile);
g_clear_object(&infile);
g_object_unref(stream);
return result;
}
......@@ -468,7 +466,7 @@ process (GeglOperation *operation,
G_OBJECT_TYPE_NAME (operation), o->path);
return FALSE;
}
if (infile) g_object_unref(infile);
g_clear_object(&infile);
g_object_unref(stream);
return TRUE;
}
......
......@@ -222,8 +222,7 @@ finalize (GObject *object)
if (o->user_data)
{
raw_close (o);
g_free (o->user_data);
o->user_data = NULL;
g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (gegl_op_parent_class)->finalize(object);
......
......@@ -142,11 +142,7 @@ finalize (GObject *object)
{
GeglProperties *o = GEGL_PROPERTIES (object);
if (o->user_data)
{
g_free (o->user_data);
o->user_data = NULL;
}
g_clear_pointer (&o->user_data, g_free);
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
......
......@@ -264,9 +264,7 @@ finalize (GObject *object)
if (o->user_data != NULL)
{
cleanup (GEGL_OPERATION (object));
if (o->user_data != NULL)
g_free (o->user_data);
o->user_data = NULL;
g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
......
......@@ -263,11 +263,9 @@ get_bounding_box (GeglOperation *operation)
cairo_destroy (cr);
cairo_surface_destroy (surface);
if (extent->string)
g_free (extent->string);
g_free (extent->string);
extent->string = g_strdup (o->string);
if (extent->font)
g_free (extent->font);
g_free (extent->font);
extent->font = g_strdup (o->font);
extent->size = o->size;
extent->wrap = o->wrap;
......@@ -297,10 +295,8 @@ finalize (GObject *object)
{
GeglOp *self = GEGL_OP (object);
if (self->cex.string)
g_free (self->cex.string);
if (self->cex.font)
g_free (self->cex.font);
g_free (self->cex.string);
g_free (self->cex.font);
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
......
......@@ -296,9 +296,7 @@ close_stream(thandle_t handle)
p->loaded = 0;
p->position = 0;
if (p->buffer != NULL)
g_free(p->buffer);
p->buffer = NULL;
g_clear_pointer(&p->buffer, g_free);
p->allocated = 0;
......@@ -847,9 +845,7 @@ finalize(GObject *object)
if (o->user_data != NULL)
{
cleanup(GEGL_OPERATION(object));
if (o->user_data != NULL)
g_free(o->user_data);
o->user_data = NULL;
g_clear_pointer(&o->user_data, g_free);
}
G_OBJECT_CLASS(gegl_op_parent_class)->finalize(object);
......
......@@ -264,9 +264,7 @@ close_stream(thandle_t handle)
p->position = 0;
if (p->buffer != NULL)
g_free(p->buffer);
p->buffer = NULL;
g_clear_pointer(&p->buffer, g_free);
p->allocated = 0;
......@@ -594,13 +592,8 @@ process(GeglOperation *operation,
cleanup:
cleanup(operation);
if (o->user_data != NULL)
g_free(o->user_data);
o->user_data = NULL;
if (error != NULL)
g_error_free(error);
g_clear_pointer(&o->user_data, g_free);
g_clear_error(&error);
return status;
}
......
......@@ -196,8 +196,8 @@ finalize (GObject *object)
v4lclose (p->vd);
g_free (p->vd);
}
g_free (o->user_data);
o->user_data = NULL;
g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
......
......@@ -317,9 +317,7 @@ finalize(GObject *object)
if (o->user_data != NULL)
{
cleanup (GEGL_OPERATION (object));
if (o->user_data != NULL)
g_free (o->user_data);
o->user_data = NULL;
g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
......
......@@ -170,12 +170,8 @@ process (GeglOperation *operation,
}
cleanup:
if (stream != NULL)
g_object_unref (stream);
if (file != NULL)
g_object_unref (file);
g_clear_object (&stream);
g_clear_object (&file);
return status;
}
......
......@@ -225,11 +225,7 @@ notify (GObject *object,
{
GeglProperties *o = GEGL_PROPERTIES (object);
if (o->user_data)
{
g_free (o->user_data);
o->user_data = NULL;
}
g_clear_pointer (&o->user_data, g_free);
}
if (G_OBJECT_CLASS (gegl_op_parent_class)->notify)
......
......@@ -1180,8 +1180,7 @@ gegl_transform_process (GeglOperation *operation,
gegl_operation_context_take_object (context, "output", G_OBJECT (output));
if (input != NULL)
g_object_unref (input);
g_clear_object (&input);
}
else
{
......@@ -1256,8 +1255,7 @@ gegl_transform_process (GeglOperation *operation,
func (operation, output, input, &matrix, result, level);
}
if (input != NULL)
g_object_unref (input);
g_clear_object (&input);
}
return TRUE;
......
......@@ -145,11 +145,7 @@ finalize (GObject *object)
GeglOperation *op = (void*) object;
GeglProperties *o = GEGL_PROPERTIES (op);
if (o->user_data)
{
g_free (o->user_data);
o->user_data = NULL;
}
g_clear_pointer (&o->user_data, g_free);
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
......
......@@ -685,8 +685,7 @@ finalize (GObject *object)
close_device (p);
p->fd = 0;
}
g_free (o->user_data);
o->user_data = NULL;
g_clear_pointer (&o->user_data, g_free);
}
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
......
......@@ -169,9 +169,7 @@ static void prepare (GeglOperation *operation)
o->user_data = props;
}
if (props->gradient) {
g_free(props->gradient);
}
g_free(props->gradient);
props->gradient = create_linear_gradient(colors, stops, GRADIENT_STOPS,
gradient_length, gradient_channels, output_format);
}
......@@ -182,9 +180,7 @@ static void finalize (GObject *object)
GeglProperties *o = GEGL_PROPERTIES (op);
if (o->user_data) {
GradientMapProperties *props = (GradientMapProperties *)o->user_data;
if (props->gradient) {
g_free(props->gradient);
}
g_free(props->gradient);
o->user_data = NULL;
}
G_OBJECT_CLASS(gegl_op_parent_class)->finalize (object);
......
......@@ -604,11 +604,7 @@ finalize (GObject *object)
GeglOperation *op = (void*) object;
GeglProperties *o = GEGL_PROPERTIES (op);
if (o->user_data)
{
g_free (o->user_data);
o->user_data = NULL;
}
g_clear_pointer (&o->user_data, g_free);
G_OBJECT_CLASS (gegl_op_parent_class)->finalize (object);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment