glib/gslice.[ch] added g_slice_copy() and g_slice_dup() (#442029).
authorSven Neumann <sven@gimp.org>
Wed, 13 Jun 2007 18:56:51 +0000 (18:56 +0000)
committerSven Neumann <neo@src.gnome.org>
Wed, 13 Jun 2007 18:56:51 +0000 (18:56 +0000)
2007-06-13  Sven Neumann  <sven@gimp.org>

* glib/gslice.[ch] added g_slice_copy() and g_slice_dup()
(#442029).

* glib/glib.symbols: updated.

svn path=/trunk/; revision=5554

ChangeLog
glib/glib.symbols
glib/gslice.c
glib/gslice.h

index 2049aa8..7120642 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-06-13  Sven Neumann  <sven@gimp.org>
+
+       * glib/gslice.[ch] added g_slice_copy() and g_slice_dup() (#442029).
+
+       * glib/glib.symbols: updated.
+
 2007-06-12  Behdad Esfahbod  <behdad@gnome.org>
 
        * glib/gunicode.h: Add more G_GNUC_CONST and G_GNUC_PURE.
index a924b6d..4489a23 100644 (file)
@@ -684,6 +684,7 @@ g_blow_chunks
 #if IN_FILE(__G_SLICE_C__)
 g_slice_alloc G_GNUC_MALLOC
 g_slice_alloc0 G_GNUC_MALLOC
+g_slice_copy G_GNUC_MALLOC
 g_slice_free1
 g_slice_free_chain_with_offset
 g_slice_set_config
index db08070..1c0fecd 100644 (file)
@@ -815,6 +815,16 @@ g_slice_alloc0 (gsize mem_size)
   return mem;
 }
 
+gpointer
+g_slice_copy (gsize    mem_size,
+              gpointer mem_block)
+{
+  gpointer mem = g_slice_alloc (mem_size);
+  if (mem)
+    memcpy (mem, mem_block, mem_size);
+  return mem;
+}
+
 void
 g_slice_free1 (gsize    mem_size,
                gpointer mem_block)
index 93b545a..84a6e89 100644 (file)
@@ -31,6 +31,8 @@ G_BEGIN_DECLS
  */
 gpointer g_slice_alloc                 (gsize    block_size) G_GNUC_MALLOC;
 gpointer g_slice_alloc0                (gsize    block_size) G_GNUC_MALLOC;
+gpointer g_slice_copy                   (gsize    block_size,
+                                         gpointer mem_block) G_GNUC_MALLOC;
 void     g_slice_free1                 (gsize    block_size,
                                         gpointer mem_block);
 void     g_slice_free_chain_with_offset (gsize    block_size,
@@ -38,7 +40,10 @@ void     g_slice_free_chain_with_offset (gsize    block_size,
                                         gsize    next_offset);
 #define  g_slice_new(type)      ((type*) g_slice_alloc (sizeof (type)))
 #define  g_slice_new0(type)     ((type*) g_slice_alloc0 (sizeof (type)))
-/*       g_slice_free                   (MemoryBlockType,
+/* MemoryBlockType *
+ *       g_slice_dup                    (MemoryBlockType,
+ *                                      MemoryBlockType *mem_block);
+ *       g_slice_free                   (MemoryBlockType,
  *                                      MemoryBlockType *mem_block);
  *       g_slice_free_chain             (MemoryBlockType,
  *                                       MemoryBlockType *first_chain_block,
@@ -48,6 +53,8 @@ void     g_slice_free_chain_with_offset (gsize    block_size,
  */
 
 /* we go through extra hoops to ensure type safety */
+#define g_slice_dup(type, mem)                                  \
+  (1 ? g_slice_copy (sizeof (type), (mem)) : (type*) ((type*) 0 == (mem)))
 #define g_slice_free(type, mem)                                do {    \
   if (1) g_slice_free1 (sizeof (type), (mem));                 \
   else   (void) ((type*) 0 == (mem));                          \