From 4bd5f1cbcf92225004bc9365a410b0088d56d519 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Sat, 10 Oct 2015 13:59:21 +0300 Subject: [PATCH] cleanup: trim util.h from unused legacy, extract version* to an own header --- src/box/applier.cc | 2 +- src/box/xrow.cc | 1 + src/main.cc | 1 + src/trivia/util.h | 81 ++++++++++++---------------------------------- src/util.cc | 5 +-- src/version.h | 70 +++++++++++++++++++++++++++++++++++++++ test/unit/xrow.cc | 1 + 7 files changed, 97 insertions(+), 64 deletions(-) create mode 100644 src/version.h diff --git a/src/box/applier.cc b/src/box/applier.cc index 02b60c05b8..29b82ce537 100644 --- a/src/box/applier.cc +++ b/src/box/applier.cc @@ -40,7 +40,7 @@ #include "msgpuck/msgpuck.h" #include "box/cluster.h" #include "iproto_constants.h" -#include "trivia/util.h" +#include "version.h" static const int RECONNECT_DELAY = 1.0; STRS(applier_state, applier_STATE); diff --git a/src/box/xrow.cc b/src/box/xrow.cc index 6c7e52d0f8..06191f14bd 100644 --- a/src/box/xrow.cc +++ b/src/box/xrow.cc @@ -35,6 +35,7 @@ #include "scramble.h" #include "third_party/base64.h" #include "iproto_constants.h" +#include "version.h" enum { HEADER_LEN_MAX = 40, BODY_LEN_MAX = 128 }; diff --git a/src/main.cc b/src/main.cc index b9ba13db7d..a5216eaf11 100644 --- a/src/main.cc +++ b/src/main.cc @@ -65,6 +65,7 @@ #include "iobuf.h" #include <third_party/gopt/gopt.h> #include "cfg.h" +#include "version.h" #include <readline/history.h> static pid_t master_pid = getpid(); diff --git a/src/trivia/util.h b/src/trivia/util.h index 677c664a1d..ef1e707d16 100644 --- a/src/trivia/util.h +++ b/src/trivia/util.h @@ -113,27 +113,6 @@ strindex(const char **haystack, const char *needle, uint32_t hmax); #define lengthof(array) (sizeof (array) / sizeof ((array)[0])) #endif -#ifndef TYPEALIGN -#define TYPEALIGN(ALIGNVAL,LEN) \ - (((uintptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((uintptr_t) ((ALIGNVAL) - 1))) - -#define SHORTALIGN(LEN) TYPEALIGN(sizeof(int16_t), (LEN)) -#define INTALIGN(LEN) TYPEALIGN(sizeof(int32_t), (LEN)) -#define MAXALIGN(LEN) TYPEALIGN(sizeof(int64_t), (LEN)) -#define PTRALIGN(LEN) TYPEALIGN(sizeof(void*), (LEN)) -#define CACHEALIGN(LEN) TYPEALIGN(32, (LEN)) -#endif - -#define CRLF "\n" - -#ifdef GCC -# define FORMAT_PRINTF gnu_printf -#else -# define FORMAT_PRINTF printf -#endif - -extern int forked; -pid_t tfork(); void close_all_xcpt(int fdc, ...); void coredump(int dump_interval); @@ -151,12 +130,15 @@ extern void *__libc_stack_end; #ifdef ENABLE_BACKTRACE void print_backtrace(); -char *backtrace(void *frame, void *stack, size_t stack_size); + +char * +backtrace(void *frame, void *stack, size_t stack_size); typedef int (backtrace_cb)(int frameno, void *frameret, const char *func, size_t offset, void *cb_ctx); -void backtrace_foreach(backtrace_cb cb, void *frame, void *stack, size_t stack_size, - void *cb_ctx); +void +backtrace_foreach(backtrace_cb cb, void *frame, void *stack, + size_t stack_size, void *cb_ctx); #endif /* ENABLE_BACKTRACE */ #ifdef HAVE_BFD @@ -165,13 +147,20 @@ struct symbol { const char *name; void *end; }; -struct symbol *addr2symbol(void *addr); -void symbols_load(const char *name); -void symbols_free(); +struct symbol * +addr2symbol(void *addr); + +void +symbols_load(const char *name); + +void +symbols_free(); #endif /* HAVE_BFD */ -char *find_path(const char *argv0); +char * +find_path(const char *argv0); -char *abspath(const char *filename); +char * +abspath(const char *filename); char * int2str(long int val); @@ -218,40 +207,10 @@ int clock_gettime(uint32_t clock_id, struct timespec *tp); } /* extern "C" */ #endif /* defined(__cplusplus) */ - #if defined(__cplusplus) #define API_EXPORT extern "C" __attribute__ ((visibility ("default"))) -#else +#else /* defined(__cplusplus) */ #define API_EXPORT extern __attribute__ ((visibility ("default"))) -#endif - -/** - * Pack version into uint32_t. - * The highest byte or result means major version, next - minor, - * middle - patch, last - revision. - */ -static inline uint32_t -version_id(unsigned major, unsigned minor, unsigned patch) -{ - return (((major << 8) | minor) << 8) | patch; -} - -static inline unsigned -version_id_major(uint32_t version_id) -{ - return (version_id >> 16) & 0xff; -} - -static inline unsigned -version_id_minor(uint32_t version_id) -{ - return (version_id >> 8) & 0xff; -} - -static inline unsigned -version_id_patch(uint32_t version_id) -{ - return version_id & 0xff; -} +#endif /* defined(__cplusplus) */ #endif /* TARANTOOL_UTIL_H_INCLUDED */ diff --git a/src/util.cc b/src/util.cc index 79e7e52f25..c16eebb888 100644 --- a/src/util.cc +++ b/src/util.cc @@ -52,6 +52,7 @@ void *__libc_stack_end; #endif +#define CRLF "\n" /** Find a string in an array of strings. * @@ -327,7 +328,7 @@ backtrace_foreach(backtrace_cb cb, void *frame_, void *stack, size_t stack_size, } } -extern "C" void +void print_backtrace() { void *frame = __builtin_frame_address(0); @@ -382,7 +383,7 @@ abspath(const char *filename) char * int2str(long int val) { - static char __thread buf[22]; + static __thread char buf[22]; snprintf(buf, sizeof(buf), "%ld", val); return buf; } diff --git a/src/version.h b/src/version.h new file mode 100644 index 0000000000..0399355836 --- /dev/null +++ b/src/version.h @@ -0,0 +1,70 @@ +#ifndef INCLUDES_TARANTOOL_VERSION_H +#define INCLUDES_TARANTOOL_VERSION_H +/* + * Copyright 2010-2015, Tarantool AUTHORS, please see AUTHORS file. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#if defined(__cplusplus) +extern "C" { +#endif /* defined(__cplusplus) */ + +/** + * Pack version into uint32_t. + * The highest byte or result means major version, next - minor, + * middle - patch, last - revision. + */ +static inline uint32_t +version_id(unsigned major, unsigned minor, unsigned patch) +{ + return (((major << 8) | minor) << 8) | patch; +} + +static inline unsigned +version_id_major(uint32_t version_id) +{ + return (version_id >> 16) & 0xff; +} + +static inline unsigned +version_id_minor(uint32_t version_id) +{ + return (version_id >> 8) & 0xff; +} + +static inline unsigned +version_id_patch(uint32_t version_id) +{ + return version_id & 0xff; +} + +#if defined(__cplusplus) +} /* extern "C" */ +#endif /* defined(__cplusplus) */ + +#endif /* INCLUDES_TARANTOOL_VERSION_H */ diff --git a/test/unit/xrow.cc b/test/unit/xrow.cc index f6e1c30e56..bf63f390c1 100644 --- a/test/unit/xrow.cc +++ b/test/unit/xrow.cc @@ -35,6 +35,7 @@ extern "C" { #include "box/xrow.h" #include "box/iproto_constants.h" #include "tt_uuid.h" +#include "version.h" #include "random.h" int -- GitLab