[glib/ebassi/aligned-alloc] fixup! Add aligned memory allocators
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/ebassi/aligned-alloc] fixup! Add aligned memory allocators
- Date: Fri, 11 Feb 2022 13:50:21 +0000 (UTC)
commit c0a180025e2b6bd44f96b8882baf0b9bdb9d82f9
Author: Philip Withnall <pwithnall endlessos org>
Date: Fri Feb 11 13:39:34 2022 +0000
fixup! Add aligned memory allocators
glib/gmem.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/glib/gmem.c b/glib/gmem.c
index 17c4add0a..060e91af9 100644
--- a/glib/gmem.c
+++ b/glib/gmem.c
@@ -546,8 +546,8 @@ g_mem_profile (void)
* g_aligned_alloc:
* @n_blocks: the number of blocks to allocate
* @n_block_bytes: the size of each block in bytes
- * @alignment: the alignment to be enforced, which must be a power of 2 and a
- * multiple of `sizeof(void*)`
+ * @alignment: the alignment to be enforced, which must be a positive power of 2
+ * and a multiple of `sizeof(void*)`
*
* This function is similar to g_malloc(), allocating (@n_blocks * @n_block_bytes)
* bytes, but care is taken to align the allocated memory to with the given
@@ -569,9 +569,9 @@ g_aligned_alloc (gsize n_blocks,
gpointer res = NULL;
gsize real_size;
- if (G_UNLIKELY (alignment & (alignment - 1)) != 0)
+ if (G_UNLIKELY ((alignment == 0) || (alignment & (alignment - 1)) != 0))
{
- g_error ("%s: alignment %"G_GSIZE_FORMAT" must be a power of two",
+ g_error ("%s: alignment %"G_GSIZE_FORMAT" must be a positive power of two",
G_STRLOC, alignment);
}
@@ -643,7 +643,8 @@ g_aligned_alloc (gsize n_blocks,
* g_aligned_alloc0:
* @n_blocks: the number of blocks to allocate
* @n_block_bytes: the size of each block in bytes
- * @alignment: the alignment to be enforced, as a power of 2
+ * @alignment: the alignment to be enforced, which must be a positive power of 2
+ * and a multiple of `sizeof(void*)`
*
* This function is similar to g_aligned_alloc(), but it will
* also clear the allocated memory before returning it.
[
Date Prev][
Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]