From beeb9b4335d9ca6f947a52528453753a51f194f3 Mon Sep 17 00:00:00 2001 From: iphydf Date: Thu, 12 Jul 2018 17:22:20 +0000 Subject: Style fixes in TCP code; remove MIN and PAIR from util.h. * Moved PAIR to toxav, where it's used (but really this should die). * Replace most MIN calls with typed `min_*` calls. Didn't replace the ones where the desired semantics are unclear. Moved the MIN macro to the one place where it's still used. * Avoid assignments in `while` loops. Instead, factored out the loop body into a separate `bool`-returning function. * Use named types for callbacks (`_cb` types). * Avoid assignments in `if` conditions. * Removed `MAKE_REALLOC` and expanded its two calls. We can't have templates in C, and this fake templating is ugly and hard to analyse and debug (it expands on a single line). * Moved epoll system include to the .c file, out of the .h file. * Avoid assignments in expressions (`a = b = c;`). * Avoid multiple declarators per struct member declaration. * Fix naming inconsistencies. * Replace `net_to_host` macro with function. --- toxcore/util.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'toxcore/util.h') diff --git a/toxcore/util.h b/toxcore/util.h index 4c5023cf..76951fff 100644 --- a/toxcore/util.h +++ b/toxcore/util.h @@ -36,20 +36,18 @@ extern "C" { #endif -#define MIN(a,b) (((a)<(b))?(a):(b)) -#define PAIR(TYPE1__, TYPE2__) struct { TYPE1__ first; TYPE2__ second; } - /* id functions */ bool id_equal(const uint8_t *dest, const uint8_t *src); uint32_t id_copy(uint8_t *dest, const uint8_t *src); /* return value is CLIENT_ID_SIZE */ void host_to_net(uint8_t *num, uint16_t numbytes); -#define net_to_host(x, y) host_to_net(x, y) +void net_to_host(uint8_t *num, uint16_t numbytes); /* Returns -1 if failed or 0 if success */ int create_recursive_mutex(pthread_mutex_t *mutex); int32_t max_s32(int32_t a, int32_t b); +uint32_t min_u32(uint32_t a, uint32_t b); uint64_t min_u64(uint64_t a, uint64_t b); #ifdef __cplusplus -- cgit v1.2.3