[gegl] gegl-tile: keep destroy_notify member in sync with data



commit 0d02a9af096c2b8d4944b0b07dbaa9a95c496ad0
Author: Massimo Valentini <mvalentini src gnome org>
Date:   Fri Aug 19 13:01:10 2011 +0200

    gegl-tile: keep destroy_notify member in sync with data
    
    add a test that exercises the paths modified, mainly to
    be executed with valgrind

 gegl/buffer/gegl-tile.c                         |    5 ++++
 tests/buffer/reference/dup_linear_from_data.buf |   13 +++++++++++
 tests/buffer/tests/dup_linear_from_data.c       |   26 +++++++++++++++++++++++
 3 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/gegl/buffer/gegl-tile.c b/gegl/buffer/gegl-tile.c
index 79ac438..5de2f1e 100644
--- a/gegl/buffer/gegl-tile.c
+++ b/gegl/buffer/gegl-tile.c
@@ -115,6 +115,9 @@ gegl_tile_dup (GeglTile *src)
   tile->data       = src->data;
   tile->size       = src->size;
 
+  tile->destroy_notify      = src->destroy_notify;
+  tile->destroy_notify_data = src->destroy_notify_data;
+
   tile->next_shared              = src->next_shared;
   src->next_shared               = tile;
   tile->prev_shared              = src;
@@ -160,6 +163,8 @@ gegl_tile_unclone (GeglTile *tile)
        * create a local copy
        */
       tile->data                     = gegl_memdup (tile->data, tile->size);
+      tile->destroy_notify           = default_free;
+      tile->destroy_notify_data      = NULL;
       tile->prev_shared->next_shared = tile->next_shared;
       tile->next_shared->prev_shared = tile->prev_shared;
       tile->prev_shared              = tile;
diff --git a/tests/buffer/reference/dup_linear_from_data.buf b/tests/buffer/reference/dup_linear_from_data.buf
new file mode 100644
index 0000000..be48f76
--- /dev/null
+++ b/tests/buffer/reference/dup_linear_from_data.buf
@@ -0,0 +1,13 @@
+Test: dup_linear_from_data
+ââââââââââââ
+â          â
+â          â
+ââââââââââââ
+ââââââââââââ
+ââââââââââââ
+ââââââââââââ
+ââââââââââââ
+ââââââââââââ
+ââââââââââââ
+ââââââââââââ
+ââââââââââââ
diff --git a/tests/buffer/tests/dup_linear_from_data.c b/tests/buffer/tests/dup_linear_from_data.c
new file mode 100644
index 0000000..2530dc5
--- /dev/null
+++ b/tests/buffer/tests/dup_linear_from_data.c
@@ -0,0 +1,26 @@
+TEST ()
+{
+  GeglBuffer   *buffer, *buffer2;
+  GeglRectangle extent = {0,0, 10, 10};
+  gfloat       *buf;
+  gint          i;
+  test_start();
+
+  buf = g_malloc (sizeof (float) * 10 * 10);
+  for (i=0;i<100;i++)
+    buf[i]=i/100.0;
+
+  buffer = gegl_buffer_linear_new_from_data (buf, babl_format ("Y float"),
+                                             &extent,
+                                             10 * 4,
+                                             G_CALLBACK(g_free), /* destroy_notify */
+                                             NULL   /* destroy_notify_data */);
+  buffer2 = gegl_buffer_dup (buffer);
+  gegl_buffer_destroy (buffer2);
+  buffer2 = gegl_buffer_dup (buffer);
+  vgrad (buffer);
+  print_buffer (buffer);
+  gegl_buffer_destroy (buffer);
+  gegl_buffer_destroy (buffer2);
+  test_end ();
+}



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