]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Created data_stack_frame_t type for data_stack_frame
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 1 Sep 2016 05:31:14 +0000 (08:31 +0300)
committerGitLab <gitlab@git.dovecot.net>
Fri, 2 Sep 2016 07:50:29 +0000 (10:50 +0300)
src/lib/data-stack.c
src/lib/data-stack.h
src/lib/ioloop.c
src/lib/mempool-datastack.c
src/lib/test-data-stack.c

index 7421e1220b926e6303f4834b5e4e1e167d093e35..8e1b53bffa76a76398a64d5a67ef70e3d4f30615 100644 (file)
@@ -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");
index eb5546f3cbccc857de97e210bafb39399c0b4012..14aeb81385bf6e2ce58366c9e0ec795b656d809f 100644 (file)
@@ -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
index eab5624d21345b326595c897fa113f4a52b809d6..91da3830ae770ee2e2bad1bc4d8b586c7318cfaf 100644 (file)
@@ -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);
index 0a986af2f1164f3727387bf8f321bd67db11500f..83578c669489ee7beadc244d04e8dc2fd2911cf3 100644 (file)
@@ -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)
index c870249f6b012b8ad9fa5d738de8a261ac18da79..9f315c7af00911ca2b8fcb2c3adcbd91ea5cbce5 100644 (file)
@@ -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;
        }