[gegl/gsoc2009-gpu] Remove obscure buffer iterator finalization



commit a0ed772a0953b1a831b441f90f78ba1cdaa7f7be
Author: Jerson Michael Perpetua <jersonperpetua gmail com>
Date:   Mon Jul 6 01:33:48 2009 +0800

    Remove obscure buffer iterator finalization
    
    Remove obscure buffer iterator finalization, replace it with a more logical
    one (through gegl_buffer_iterator_free()) and update all existing uses of
    buffer iterators to also free them after use.

 gegl/buffer/gegl-buffer-access.c                |    3 ++
 gegl/buffer/gegl-buffer-iterator.c              |   33 +++++++++++++++++--
 gegl/buffer/gegl-buffer-iterator.h              |   39 +++++++++++------------
 gegl/operation/gegl-operation-point-composer.c  |    2 +
 gegl/operation/gegl-operation-point-composer3.c |    2 +
 gegl/operation/gegl-operation-point-filter.c    |    1 +
 gegl/operation/gegl-operation-point-render.c    |    2 +
 operations/affine/affine.c                      |    1 +
 tests/buffer/buffer-test.c                      |    1 +
 9 files changed, 60 insertions(+), 24 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index dd6f4c7..508e159 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -1699,6 +1699,8 @@ gegl_buffer_copy (GeglBuffer          *src,
       read = gegl_buffer_iterator_add (i, src, src_rect, src->format, GEGL_BUFFER_READ);
       while (gegl_buffer_iterator_next (i))
         babl_process (fish, i->data[read], i->data[0], i->length);
+
+      gegl_buffer_iterator_free (i);
     }
 }
 
@@ -1729,6 +1731,7 @@ gegl_buffer_clear (GeglBuffer          *dst,
     {
       memset (((guchar*)(i->data[0])), 0, i->length * pxsize);
     }
+  gegl_buffer_iterator_free (i);
 }
 
 GeglBuffer *
diff --git a/gegl/buffer/gegl-buffer-iterator.c b/gegl/buffer/gegl-buffer-iterator.c
index d9646c9..cf32250 100644
--- a/gegl/buffer/gegl-buffer-iterator.c
+++ b/gegl/buffer/gegl-buffer-iterator.c
@@ -68,6 +68,7 @@ typedef struct _GeglBufferIterator
   /* the following is private */
   gint                    iterable_count;
   gint                    iteration_no;
+  gboolean                is_done;
 
   GeglBuffer             *buffer  [GEGL_BUFFER_MAX_ITERABLES];
   GeglRectangle           rect    [GEGL_BUFFER_MAX_ITERABLES];
@@ -404,7 +405,7 @@ gegl_buffer_iterator_next (GeglBufferIterator *iterator)
 
   _GeglBufferIterator *i = (gpointer) iterator;
 
-  if (i->buf[0] == (void*) 0xdeadbeef)
+  if (i->is_done)
     g_error ("%s called on finished buffer iterator", G_STRFUNC);
 
   /* first we need to finish off any pending write work */
@@ -523,15 +524,17 @@ gegl_buffer_iterator_next (GeglBufferIterator *iterator)
   if (result == FALSE)
     {
       for (no = 0; no < i->iterable_count; no++)
-        g_object_unref (i->buffer[no]);
+        {
+          g_object_unref (i->buffer[no]);
+          i->buffer[no] = NULL;
+        }
 
 #if DEBUG_DIRECT
       g_print ("%f %f\n",
                100.0 * direct_read / (in_direct_read + direct_read),
                100.0 * direct_write / (in_direct_write + direct_write));
 #endif
-      i->buf[0] = (void*) 0xdeadbeef;
-      g_free (i);
+      i->is_done = TRUE;
     }
 
   return result;
@@ -547,3 +550,25 @@ gegl_buffer_iterator_new (GeglBuffer          *buffer,
   gegl_buffer_iterator_add (i, buffer, roi, format, flags);
   return i;
 }
+
+void
+gegl_buffer_iterator_free (GeglBufferIterator *iterator)
+{
+  gint cnt;
+
+  _GeglBufferIterator *i = (gpointer) iterator;
+
+  for (cnt = 0; cnt < i->iterable_count; cnt++)
+    {
+      if (i->buffer[cnt] != NULL)
+        {
+          g_object_unref (i->buffer[cnt]);
+          i->buffer[cnt] = NULL;
+        }
+
+      if (i->buf[cnt] != NULL)
+        iterator_buf_pool_release (i->buf[cnt]);
+    }
+
+  g_free (i);
+}
diff --git a/gegl/buffer/gegl-buffer-iterator.h b/gegl/buffer/gegl-buffer-iterator.h
index 3cd5583..53268c3 100644
--- a/gegl/buffer/gegl-buffer-iterator.h
+++ b/gegl/buffer/gegl-buffer-iterator.h
@@ -62,10 +62,12 @@ typedef struct GeglBufferIterator
  * Returns: a new buffer iterator that can be used to iterate through the
  * buffers pixels.
  */
-GeglBufferIterator * gegl_buffer_iterator_new  (GeglBuffer          *buffer,
-                                                const GeglRectangle *roi, 
-                                                const Babl          *format,
-                                                guint                flags);
+GeglBufferIterator *gegl_buffer_iterator_new  (GeglBuffer          *buffer,
+                                               const GeglRectangle *roi, 
+                                               const Babl          *format,
+                                               guint                flags);
+
+void                gegl_buffer_iterator_free (GeglBufferIterator  *iterator);
 
 /**
  * gegl_buffer_iterator_add:
@@ -83,12 +85,11 @@ GeglBufferIterator * gegl_buffer_iterator_new  (GeglBuffer          *buffer,
  * Returns: an integer handle refering to the index in the iterator structure
  * of the added buffer.
  */
-gint                 gegl_buffer_iterator_add  (GeglBufferIterator  *iterator,
-                                                GeglBuffer          *buffer,
-                                                const GeglRectangle *roi, 
-                                                const Babl          *format,
-                                                guint                flags);
-
+gint                gegl_buffer_iterator_add  (GeglBufferIterator  *iterator,
+                                               GeglBuffer          *buffer,
+                                               const GeglRectangle *roi, 
+                                               const Babl          *format,
+                                               guint                flags);
 
 /**
  * gegl_buffer_iterator_next:
@@ -102,25 +103,23 @@ gint                 gegl_buffer_iterator_add  (GeglBufferIterator  *iterator,
  *
  * Returns: TRUE if there is more work FALSE if iteration is complete.
  */
-gboolean             gegl_buffer_iterator_next (GeglBufferIterator *iterator);
+gboolean            gegl_buffer_iterator_next (GeglBufferIterator *iterator);
 
 
 #ifdef EXAMPLE
+  GeglBufferIterator *gi = gegl_buffer_iterator_new (buffer,
+                                                     roi,
+                                                     babl_format("Y' float"),
+                                                     GEGL_BUFFER_WRITE);
 
-  GeglBufferIterator *gi;
-  gi = gegl_buffer_iterator_new (buffer, roi,
-                                 babl_format("Y' float"), GEGL_BUFFER_WRITE);
   while (gegl_buffer_iterator_next (gi))
     {
       gfloat *buf = gi->data[0];
       gint    i;
-      for (i=0; i<gi->length; i++)
-        {
-          buf[i]=0.5;
-        }
-    }
-
 
+      for (i = 0; i < gi->length; i++)
+        buf[i] = 0.5;
+    }
 #endif
 
 #endif
diff --git a/gegl/operation/gegl-operation-point-composer.c b/gegl/operation/gegl-operation-point-composer.c
index b9e477d..55d7add 100644
--- a/gegl/operation/gegl-operation-point-composer.c
+++ b/gegl/operation/gegl-operation-point-composer.c
@@ -224,6 +224,8 @@ gegl_operation_point_composer_process (GeglOperation       *operation,
                point_composer_class->process (operation, i->data[read], NULL, i->data[0], i->length, &(i->roi[0]));
             }
         }
+
+      gegl_buffer_iterator_free (i);
       return TRUE;
     }
   return TRUE;
diff --git a/gegl/operation/gegl-operation-point-composer3.c b/gegl/operation/gegl-operation-point-composer3.c
index 904045b..e23a3ec 100644
--- a/gegl/operation/gegl-operation-point-composer3.c
+++ b/gegl/operation/gegl-operation-point-composer3.c
@@ -197,6 +197,8 @@ gegl_operation_point_composer3_process (GeglOperation       *operation,
                 }
             }
         }
+
+      gegl_buffer_iterator_free (i);
       return TRUE;
     }
   return TRUE;
diff --git a/gegl/operation/gegl-operation-point-filter.c b/gegl/operation/gegl-operation-point-filter.c
index 7d8c336..b05f864 100644
--- a/gegl/operation/gegl-operation-point-filter.c
+++ b/gegl/operation/gegl-operation-point-filter.c
@@ -82,6 +82,7 @@ gegl_operation_point_filter_process (GeglOperation       *operation,
       while (gegl_buffer_iterator_next (i))
            point_filter_class->process (operation, i->data[read], i->data[0], i->length, &i->roi[0]);
 
+      gegl_buffer_iterator_free (i);
     }
   return TRUE;
 }
diff --git a/gegl/operation/gegl-operation-point-render.c b/gegl/operation/gegl-operation-point-render.c
index 1626b39..af714ec 100644
--- a/gegl/operation/gegl-operation-point-render.c
+++ b/gegl/operation/gegl-operation-point-render.c
@@ -99,6 +99,8 @@ gegl_operation_point_render_process (GeglOperation       *operation,
 
       while (gegl_buffer_iterator_next (i))
           point_render_class->process (operation, i->data[0], i->length, &i->roi[0]);
+
+      gegl_buffer_iterator_free (i);
     }
   return TRUE;
 }
diff --git a/operations/affine/affine.c b/operations/affine/affine.c
index 600a2e8..d227542 100644
--- a/operations/affine/affine.c
+++ b/operations/affine/affine.c
@@ -709,6 +709,7 @@ affine_generic (GeglBuffer  *dest,
            v_start += inverse [1][1];
         }
     }
+  gegl_buffer_iterator_free (i);
 }
 
 void  gegl_sampler_prepare     (GeglSampler *self);
diff --git a/tests/buffer/buffer-test.c b/tests/buffer/buffer-test.c
index 1975709..b7d8023 100644
--- a/tests/buffer/buffer-test.c
+++ b/tests/buffer/buffer-test.c
@@ -268,6 +268,7 @@ static void fill_rect (GeglBuffer          *buffer,
           buf[i]=value;
         }
     }
+  gegl_buffer_iterator_free (gi);
 }
 
 void rectangle (GeglBuffer *buffer,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]