diff --git a/src/box/applier.cc b/src/box/applier.cc index 02b60c05b83cafc978e54aa1081f4ec4ceb70fe0..29b82ce537287b1c7a07c822935b6c013f57e3ec 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 6c7e52d0f8e7bad836106fdd1c508d336d3eabfe..06191f14bd0dd9a4e6b68a6d202ef70c3f0d2745 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 b9ba13db7d9637abf340b1295095bfe726b6bc72..a5216eaf1175376c398bd1d3350df61b1bafc5ae 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 677c664a1d9e2e622c9785c9838143e7bac37724..ef1e707d167399ae86a9ed27f0bd1b72198358fb 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 79e7e52f25c4a1d82cf2aae3f306eae56115e00b..c16eebb8881c9b1af1c7701a661b40dcba3056b8 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 0000000000000000000000000000000000000000..039935583656ddfa028fdc58df187a31b344749d --- /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 f6e1c30e5666603d2fec136d2c304e10d5407727..bf63f390c124b47e1c1112d1634e0de7a22b63a3 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