dovecot-2.2: lib: data-stack - helper macro for requested/alloca...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jul 28 13:54:28 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/38c7901e9ff6
changeset: 17643:38c7901e9ff6
user: Phil Carmody <phil at dovecot.fi>
date: Mon Jul 28 16:45:33 2014 +0300
description:
lib: data-stack - helper macro for requested/allocated size
Rather than #if/#else/#endif around such calculations, or even
having the possibility to mistype such expressions, just extract
the calculation into a helper macro defined appropriately for
the DEBUG mode.
Signed-off-by: Phil Carmody <phil at dovecot.fi>
diffstat:
src/lib/data-stack.c | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)
diffs (41 lines):
diff -r 9d85b31dfb74 -r 38c7901e9ff6 src/lib/data-stack.c
--- a/src/lib/data-stack.c Mon Jul 28 16:45:33 2014 +0300
+++ b/src/lib/data-stack.c Mon Jul 28 16:45:33 2014 +0300
@@ -26,10 +26,12 @@
# define SENTRY_COUNT (4*8)
# define BLOCK_CANARY ((void *)0xBADBADD5BADBADD5) /* contains 'D5' */
# define BLOCK_CANARY_CHECK(block) i_assert((block)->canary == BLOCK_CANARY)
+# define ALLOC_SIZE(size) (MEM_ALIGN(sizeof(size_t)) + MEM_ALIGN(size + SENTRY_COUNT))
#else
# define CLEAR_CHR 0
# define BLOCK_CANARY NULL
# define BLOCK_CANARY_CHECK(block) do { ; } while(0)
+# define ALLOC_SIZE(size) MEM_ALIGN(size)
#endif
struct stack_block {
@@ -236,9 +238,8 @@
if (used_size - pos < requested_size)
i_panic("data stack[%s]: saved alloc size broken",
current_frame_block->marker[frame_pos]);
- pos += MEM_ALIGN(sizeof(size_t));
- max_pos = pos + MEM_ALIGN(requested_size + SENTRY_COUNT);
- pos += requested_size;
+ max_pos = pos + ALLOC_SIZE(requested_size);
+ pos += MEM_ALIGN(sizeof(size_t)) + requested_size;
for (; pos < max_pos; pos++) {
if (p[pos] != CLEAR_CHR)
@@ -368,10 +369,8 @@
/* allocate only aligned amount of memory so alignment comes
always properly */
-#ifndef DEBUG
- alloc_size = MEM_ALIGN(size);
-#else
- alloc_size = MEM_ALIGN(sizeof(size)) + MEM_ALIGN(size + SENTRY_COUNT);
+ alloc_size = ALLOC_SIZE(size);
+#ifdef DEBUG
if(permanent) {
current_frame_block->alloc_bytes[frame_pos] += alloc_size;
current_frame_block->alloc_count[frame_pos]++;
More information about the dovecot-cvs
mailing list