[gegl] Don't use 0xdeadbeef "special address" to mark finished iterators.



commit 4c0253928bb6a9650ad5f42578abdcbd8355ab98
Author: Nils Philippsen <nils redhat com>
Date:   Thu Aug 4 16:23:03 2011 +0200

    Don't use 0xdeadbeef "special address" to mark finished iterators.
    
    Add is_finished member to struct GeglBufferIterator instead as
    0xdeadbeef is a valid address.

 gegl/buffer/gegl-buffer-iterator.c |    6 ++++--
 gegl/buffer/gegl-buffer-iterator.h |    1 +
 2 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-iterator.c b/gegl/buffer/gegl-buffer-iterator.c
index e0f8681..4d4f5ab 100644
--- a/gegl/buffer/gegl-buffer-iterator.c
+++ b/gegl/buffer/gegl-buffer-iterator.c
@@ -374,7 +374,7 @@ gboolean gegl_buffer_iterator_next     (GeglBufferIterator *iterator)
   gboolean result = FALSE;
   gint no;
 
-  if (i->buf[0] == (void*)0xdeadbeef)
+  if (i->is_finished)
     g_error ("%s called on finished buffer iterator", G_STRFUNC);
   if (i->iteration_no == 0)
     {
@@ -524,7 +524,7 @@ gboolean gegl_buffer_iterator_next     (GeglBufferIterator *iterator)
       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;
+      i->is_finished = TRUE;
       g_slice_free (GeglBufferIterators, i);
     }
 
@@ -538,6 +538,8 @@ GeglBufferIterator *gegl_buffer_iterator_new (GeglBuffer          *buffer,
                                               guint                flags)
 {
   GeglBufferIterator *i = (gpointer)g_slice_new0 (GeglBufferIterators);
+  /* Because the iterator is nulled above, we can forgo explicitly setting
+   * i->is_finished to FALSE. */
   gegl_buffer_iterator_add (i, buffer, roi, format, flags);
   return i;
 }
diff --git a/gegl/buffer/gegl-buffer-iterator.h b/gegl/buffer/gegl-buffer-iterator.h
index 68b2619..c07ba92 100644
--- a/gegl/buffer/gegl-buffer-iterator.h
+++ b/gegl/buffer/gegl-buffer-iterator.h
@@ -33,6 +33,7 @@ typedef struct GeglBufferIterator
   gint          length;
   gpointer      data[GEGL_BUFFER_MAX_ITERATORS];
   GeglRectangle roi[GEGL_BUFFER_MAX_ITERATORS];
+  gboolean      is_finished;
 } GeglBufferIterator;
 
 



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