Revert "Add aligned allocator functions to GSK"
authorBenjamin Otte <otte@redhat.com>
Tue, 19 Jun 2018 17:54:19 +0000 (19:54 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 19 Jun 2018 18:00:53 +0000 (20:00 +0200)
This reverts commit 8e74eb382f0c617b7b65a6850952d6acc9fd3018.

This code is not necessary. It worked around a bug in graphene where
graphene was requiring stricter alignment than glib allocators could
guarantee.

gsk/gskalloc.c [deleted file]
gsk/gskallocprivate.h [deleted file]
gsk/gskrendernode.c
gsk/meson.build

diff --git a/gsk/gskalloc.c b/gsk/gskalloc.c
deleted file mode 100644 (file)
index cf1c031..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-#include "config.h"
-
-#if defined(HAVE_POSIX_MEMALIGN) && !defined(_XOPEN_SOURCE)
-# define _XOPEN_SOURCE 600
-#endif
-
-#include "gskallocprivate.h"
-
-#if defined(HAVE_MEMALIGN) || defined(HAVE__ALIGNED_MALLOC)
-/* Required for _aligned_malloc() and _aligned_free() on Windows */
-#include <malloc.h>
-#endif
-
-#include <errno.h>
-#include <string.h>
-
-#ifdef HAVE__ALIGNED_MALLOC
-/* _aligned_malloc() takes parameters of aligned_alloc() in reverse order */
-# define aligned_alloc(alignment, size) _aligned_malloc (size, alignment)
-
-/* _aligned_malloc()'ed memory must be freed by _align_free() on Windows */
-# define aligned_free(x) _aligned_free (x)
-#else
-# define aligned_free(x) free (x)
-#endif
-
-/**
- * gsk_aligned_alloc:
- * @size: the size of the memory to allocate
- * @number: the multiples of @size to allocate
- * @alignment: the alignment to be enforced, as a power of 2
- *
- * Allocates @number times @size memory, with the given @alignment.
- *
- * If the total requested memory overflows %G_MAXSIZE, this function
- * will abort.
- *
- * If allocation fails, this function will abort, in line with
- * the behaviour of GLib.
- *
- * Returns: (transfer full): the allocated memory
- */
-gpointer
-gsk_aligned_alloc (gsize size,
-                   gsize number,
-                   gsize alignment)
-{
-  gpointer res = NULL;
-  gsize real_size;
-
-  if (G_UNLIKELY (number > G_MAXSIZE / size))
-    {
-#ifndef G_DISABLE_ASSERT
-      g_error ("%s: overflow in the allocation of (%"G_GSIZE_FORMAT" x %"G_GSIZE_FORMAT") bytes",
-               G_STRLOC, size, number);
-#endif
-      return NULL;
-    }
-
-  real_size = size * number;
-
-#ifndef G_DISABLE_ASSERT
-  errno = 0;
-#endif
-
-#if defined(HAVE_POSIX_MEMALIGN) && !defined (MALLOC_IS_ALIGNED16)
-  errno = posix_memalign (&res, alignment, real_size);
-#elif (defined(HAVE_ALIGNED_ALLOC) || defined(HAVE__ALIGNED_MALLOC)) && !defined (MALLOC_IS_ALIGNED16)
-  /* real_size must be a multiple of alignment */
-  if (real_size % alignment != 0)
-    {
-      gsize offset = real_size % alignment;
-      real_size += (alignment - offset);
-    }
-    
-  res = aligned_alloc (alignment, real_size);
-#elif defined(HAVE_MEMALIGN) && !defined (MALLOC_IS_ALIGNED16)
-  res = memalign (alignment, real_size);
-#else
-  res = malloc (real_size);
-#endif
-
-#ifndef G_DISABLE_ASSERT
-  if (errno != 0 || res == NULL)
-    {
-      g_error ("%s: error in the allocation of (%"G_GSIZE_FORMAT" x %"G_GSIZE_FORMAT") bytes: %s",
-               G_STRLOC, size, number, strerror (errno));
-    }
-#endif
-
-  return res;
-}
-
-/**
- * gsk_aligned_alloc0:
- * @size: the size of the memory to allocate
- * @number: the multiples of @size to allocate
- * @alignment: the alignment to be enforced, as a power of 2
- *
- * Allocates @number times @size memory, with the given @alignment,
- * like gsk_aligned_alloc(), but it also clears the memory.
- *
- * Returns: (transfer full): the allocated, cleared memory
- */
-gpointer
-gsk_aligned_alloc0 (gsize size,
-                    gsize number,
-                    gsize alignment)
-{
-  gpointer mem;
-
-  mem = gsk_aligned_alloc (size, number, alignment);
-
-  if (mem)
-    memset (mem, 0, size * number);
-
-  return mem;
-}
-
-/**
- * gsk_aligned_free:
- * @mem: the memory to deallocate
- *
- * Frees the memory allocated by gsk_aligned_alloc().
- */
-void
-gsk_aligned_free (gpointer mem)
-{
-  aligned_free (mem);
-}
diff --git a/gsk/gskallocprivate.h b/gsk/gskallocprivate.h
deleted file mode 100644 (file)
index fb757ef..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef __GSK_ALLOC_PRIVATE_H__
-#define __GSK_ALLOC_PRIVATE_H__
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-gpointer gsk_aligned_alloc  (gsize    size,
-                             gsize    number,
-                             gsize    alignment);
-gpointer gsk_aligned_alloc0 (gsize    size,
-                             gsize    number,
-                             gsize    alignment);
-void     gsk_aligned_free   (gpointer mem);
-
-G_END_DECLS
-
-#endif /* __GSK_ALLOC_PRIVATE_H__ */
index 3b3c71a71357af7b6140047b9876b30e5da95fd1..343fd4b8cebed2dd222a60a34c63de30b9d57dae 100644 (file)
@@ -42,7 +42,6 @@
 
 #include "gskdebugprivate.h"
 #include "gskrendererprivate.h"
-#include "gskallocprivate.h"
 
 #include <graphene-gobject.h>
 
@@ -67,7 +66,7 @@ gsk_render_node_finalize (GskRenderNode *self)
 {
   self->node_class->finalize (self);
 
-  gsk_aligned_free (self);
+  g_free (self);
 }
 
 /*< private >
@@ -84,7 +83,7 @@ gsk_render_node_new (const GskRenderNodeClass *node_class, gsize extra_size)
   g_return_val_if_fail (node_class != NULL, NULL);
   g_return_val_if_fail (node_class->node_type != GSK_NOT_A_RENDER_NODE, NULL);
 
-  self = gsk_aligned_alloc0 (node_class->struct_size + extra_size, 1, 16);
+  self = g_malloc0 (node_class->struct_size + extra_size);
 
   self->node_class = node_class;
 
index 937c91d596f0cb3d68739b9e658d6a0c73459353..2b9115bb2e8c2a3dbf30ceb02f468e8a8a72ce5b 100644 (file)
@@ -30,7 +30,6 @@ gsk_public_sources = files([
 ])
 
 gsk_private_sources = files([
-  'gskalloc.c',
   'gskcairoblur.c',
   'gskcairorenderer.c',
   'gskdebug.c',