From: Timo Sirainen Date: Thu, 1 Sep 2016 05:31:14 +0000 (+0300) Subject: lib: Created data_stack_frame_t type for data_stack_frame X-Git-Tag: 2.3.0.rc1~3089 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2588872c1fe79642589b805aaab9fbb6750771b;p=thirdparty%2Fdovecot%2Fcore.git lib: Created data_stack_frame_t type for data_stack_frame --- diff --git a/src/lib/data-stack.c b/src/lib/data-stack.c index 7421e1220b..8e1b53bffa 100644 --- a/src/lib/data-stack.c +++ b/src/lib/data-stack.c @@ -67,7 +67,7 @@ struct stack_frame_block { #endif }; -unsigned int data_stack_frame = 0; +data_stack_frame_t data_stack_frame = 0; static bool data_stack_initialized = FALSE; static int frame_pos = BLOCK_FRAME_COUNT-1; /* in current_frame_block */ @@ -127,7 +127,7 @@ static void data_stack_last_buffer_reset(bool preserve_data ATTR_UNUSED) } } -unsigned int t_push(const char *marker) +data_stack_frame_t t_push(const char *marker) { struct stack_frame_block *frame_block; @@ -179,9 +179,9 @@ unsigned int t_push(const char *marker) return data_stack_frame++; } -unsigned int t_push_named(const char *format, ...) +data_stack_frame_t t_push_named(const char *format, ...) { - unsigned int ret = t_push(NULL); + data_stack_frame_t ret = t_push(NULL); #ifdef DEBUG va_list args; va_start(args, format); @@ -260,7 +260,7 @@ static void t_pop_verify(void) } #endif -unsigned int t_pop(void) +data_stack_frame_t t_pop(void) { struct stack_frame_block *frame_block; @@ -310,7 +310,7 @@ unsigned int t_pop(void) return --data_stack_frame; } -void t_pop_check(unsigned int *id) +void t_pop_check(data_stack_frame_t *id) { if (unlikely(t_pop() != *id)) i_panic("Leaked t_pop() call"); diff --git a/src/lib/data-stack.h b/src/lib/data-stack.h index eb5546f3cb..14aeb81385 100644 --- a/src/lib/data-stack.h +++ b/src/lib/data-stack.h @@ -31,7 +31,9 @@ overflows. */ -extern unsigned int data_stack_frame; +typedef unsigned int data_stack_frame_t; + +extern data_stack_frame_t data_stack_frame; /* All t_..() allocations between t_push*() and t_pop() are freed after t_pop() is called. Returns the current stack frame number, which can be used @@ -43,24 +45,24 @@ extern unsigned int data_stack_frame; but is safe to call in a loop as it performs the allocation within its own frame. However, you should always prefer to use T_BEGIN { ... } T_END below. */ -unsigned int t_push(const char *marker) ATTR_HOT; -unsigned int t_push_named(const char *format, ...) ATTR_HOT ATTR_FORMAT(1, 2); -unsigned int t_pop(void) ATTR_HOT; +data_stack_frame_t t_push(const char *marker) ATTR_HOT; +data_stack_frame_t t_push_named(const char *format, ...) ATTR_HOT ATTR_FORMAT(1, 2); +data_stack_frame_t t_pop(void) ATTR_HOT; /* Simplifies the if (t_pop() != x) check by comparing it internally and panicking if it doesn't match. */ -void t_pop_check(unsigned int *id) ATTR_HOT; +void t_pop_check(data_stack_frame_t *id) ATTR_HOT; /* Usage: T_BEGIN { code } T_END */ #ifndef DEBUG #define T_BEGIN \ - STMT_START { unsigned int _data_stack_cur_id = t_push(NULL); + STMT_START { data_stack_frame_t _data_stack_cur_id = t_push(NULL); #elif defined (__GNUC__) && !defined (__STRICT_ANSI__) #define T_BEGIN \ - STMT_START { unsigned int _data_stack_cur_id = t_push(__FUNCTION__); + STMT_START { data_stack_frame_t _data_stack_cur_id = t_push(__FUNCTION__); #else #define T_CAT2(a,b) (a ":" #b) #define T_BEGIN \ - STMT_START { unsigned int _data_stack_cur_id = t_push(T_CAT2(__FILE__,__LINE__)); + STMT_START { data_stack_frame_t _data_stack_cur_id = t_push(T_CAT2(__FILE__,__LINE__)); #endif #define T_END \ t_pop_check(&_data_stack_cur_id); } STMT_END diff --git a/src/lib/ioloop.c b/src/lib/ioloop.c index eab5624d21..91da3830ae 100644 --- a/src/lib/ioloop.c +++ b/src/lib/ioloop.c @@ -478,7 +478,7 @@ static void io_loop_handle_timeouts_real(struct ioloop *ioloop) { struct priorityq_item *item; struct timeval tv, tv_call, prev_ioloop_timeval = ioloop_timeval; - unsigned int t_id; + data_stack_frame_t t_id; if (gettimeofday(&ioloop_timeval, NULL) < 0) i_fatal("gettimeofday(): %m"); @@ -549,7 +549,7 @@ void io_loop_handle_timeouts(struct ioloop *ioloop) void io_loop_call_io(struct io *io) { struct ioloop *ioloop = io->ioloop; - unsigned int t_id; + data_stack_frame_t t_id; if (io->pending) { i_assert(ioloop->io_pending_count > 0); diff --git a/src/lib/mempool-datastack.c b/src/lib/mempool-datastack.c index 0a986af2f1..83578c6694 100644 --- a/src/lib/mempool-datastack.c +++ b/src/lib/mempool-datastack.c @@ -40,7 +40,7 @@ struct datastack_pool { struct pool pool; int refcount; - unsigned int data_stack_frame; + data_stack_frame_t data_stack_frame; }; pool_t pool_datastack_create(void) diff --git a/src/lib/test-data-stack.c b/src/lib/test-data-stack.c index c870249f6b..9f315c7af0 100644 --- a/src/lib/test-data-stack.c +++ b/src/lib/test-data-stack.c @@ -93,7 +93,7 @@ static void test_ds_recurse(int depth, int number, size_t size) char **ps; char tag[2] = { depth+1, '\0' }; int try_fails = 0; - unsigned int t_id = t_push_named("test_ds_recurse[%i]", depth); + data_stack_frame_t t_id = t_push_named("test_ds_recurse[%i]", depth); ps = t_buffer_get_type(char *, number); i_assert(ps != NULL); t_buffer_alloc_type(char *, number); @@ -148,9 +148,10 @@ void test_data_stack(void) enum fatal_test_state fatal_data_stack(int stage) { #ifdef DEBUG +#define NONEXISTENT_STACK_FRAME_ID (data_stack_frame_t)999999999 /* If we abort, then we'll be left with a dangling t_push() keep a record of our temporary stack id, so we can clean up. */ - static unsigned int t_id = 999999999; + static data_stack_frame_t t_id = NONEXISTENT_STACK_FRAME_ID; static unsigned char *undo_ptr = NULL; static unsigned char undo_data; static bool things_are_messed_up = FALSE; @@ -164,10 +165,10 @@ enum fatal_test_state fatal_data_stack(int stage) undo_ptr = NULL; /* t_pop musn't abort, that would cause recursion */ things_are_messed_up = TRUE; - if (t_id != 999999999 && t_pop() != t_id) + if (t_id != NONEXISTENT_STACK_FRAME_ID && t_pop() != t_id) return FATAL_TEST_ABORT; /* abort, things are messed up with us */ things_are_messed_up = FALSE; - t_id = 999999999; + t_id = NONEXISTENT_STACK_FRAME_ID; test_end(); } @@ -205,7 +206,7 @@ enum fatal_test_state fatal_data_stack(int stage) *undo_ptr = '*'; /* t_pop will now fail */ (void)t_pop(); - t_id = 999999999; /* We're FUBAR, mustn't pop next entry */ + t_id = NONEXISTENT_STACK_FRAME_ID; /* We're FUBAR, mustn't pop next entry */ return FATAL_TEST_FAILURE; } @@ -218,7 +219,7 @@ enum fatal_test_state fatal_data_stack(int stage) *undo_ptr = '*'; /* t_pop will now fail */ (void)t_pop(); - t_id = 999999999; /* We're FUBAR, mustn't pop next entry */ + t_id = NONEXISTENT_STACK_FRAME_ID; /* We're FUBAR, mustn't pop next entry */ return FATAL_TEST_FAILURE; }