Commit a3553a13 authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

5.6.45-86.1

parent 24a0d7c5
...@@ -6,7 +6,7 @@ FUNCTION(TOKU_GET_DEPENDEND_OS_LIBS target result) ...@@ -6,7 +6,7 @@ FUNCTION(TOKU_GET_DEPENDEND_OS_LIBS target result)
IF(deps) IF(deps)
FOREACH(lib ${deps}) FOREACH(lib ${deps})
# Filter out keywords for used for debug vs optimized builds # Filter out keywords for used for debug vs optimized builds
IF(NOT lib MATCHES "general" AND NOT lib MATCHES "debug" AND NOT lib MATCHES "optimized") IF(TARGET ${lib})
GET_TARGET_PROPERTY(lib_location ${lib} LOCATION) GET_TARGET_PROPERTY(lib_location ${lib} LOCATION)
IF(NOT lib_location) IF(NOT lib_location)
SET(ret ${ret} ${lib}) SET(ret ${ret} ${lib})
......
include(ExternalProject) include(ExternalProject)
if (NOT DEFINED LIBJEMALLOC)
## add jemalloc with an external project
set(JEMALLOC_SOURCE_DIR "${TokuDB_SOURCE_DIR}/third_party/jemalloc" CACHE FILEPATH "Where to find jemalloc sources.")
if (EXISTS "${JEMALLOC_SOURCE_DIR}/configure")
set(jemalloc_configure_opts "CC=${CMAKE_C_COMPILER}" "--with-jemalloc-prefix=" "--with-private-namespace=tokudb_jemalloc_internal_" "--enable-cc-silence")
option(JEMALLOC_DEBUG "Build jemalloc with --enable-debug." OFF)
if (JEMALLOC_DEBUG)
list(APPEND jemalloc_configure_opts --enable-debug)
endif ()
ExternalProject_Add(build_jemalloc
PREFIX jemalloc
SOURCE_DIR "${JEMALLOC_SOURCE_DIR}"
CONFIGURE_COMMAND
"${JEMALLOC_SOURCE_DIR}/configure" ${jemalloc_configure_opts}
"--prefix=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/jemalloc"
)
add_library(jemalloc STATIC IMPORTED GLOBAL)
set_target_properties(jemalloc PROPERTIES IMPORTED_LOCATION
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/jemalloc/lib/libjemalloc_pic.a")
add_dependencies(jemalloc build_jemalloc)
add_library(jemalloc_nopic STATIC IMPORTED GLOBAL)
set_target_properties(jemalloc_nopic PROPERTIES IMPORTED_LOCATION
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/jemalloc/lib/libjemalloc.a")
add_dependencies(jemalloc_nopic build_jemalloc)
# detect when we are being built as a subproject
if (NOT DEFINED MYSQL_PROJECT_NAME_DOCSTRING)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/jemalloc/lib" DESTINATION .
COMPONENT tokukv_libs_extra)
endif ()
endif ()
endif ()
## add lzma with an external project ## add lzma with an external project
set(xz_configure_opts --with-pic --enable-static) set(xz_configure_opts --with-pic --enable-static)
if (APPLE) if (APPLE)
......
...@@ -20,7 +20,6 @@ target_link_libraries(${LIBTOKUPORTABILITY} LINK_PUBLIC ${CMAKE_THREAD_LIBS_INIT ...@@ -20,7 +20,6 @@ target_link_libraries(${LIBTOKUPORTABILITY} LINK_PUBLIC ${CMAKE_THREAD_LIBS_INIT
add_library(tokuportability_static_conv STATIC ${tokuportability_srcs}) add_library(tokuportability_static_conv STATIC ${tokuportability_srcs})
set_target_properties(tokuportability_static_conv PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(tokuportability_static_conv PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_dependencies(tokuportability_static_conv build_jemalloc)
set(tokuportability_source_libs tokuportability_static_conv ${LIBJEMALLOC} ${CMAKE_THREAD_LIBS_INIT} ${EXTRA_SYSTEM_LIBS}) set(tokuportability_source_libs tokuportability_static_conv ${LIBJEMALLOC} ${CMAKE_THREAD_LIBS_INIT} ${EXTRA_SYSTEM_LIBS})
toku_merge_static_libs(${LIBTOKUPORTABILITY}_static ${LIBTOKUPORTABILITY}_static "${tokuportability_source_libs}") toku_merge_static_libs(${LIBTOKUPORTABILITY}_static ${LIBTOKUPORTABILITY}_static "${tokuportability_source_libs}")
......
...@@ -26,7 +26,7 @@ if [ ! -d build ] ; then ...@@ -26,7 +26,7 @@ if [ ! -d build ] ; then
-D RUN_LONG_TESTS=ON \ -D RUN_LONG_TESTS=ON \
-D TOKUDB_DATA=$tokudbdir/../tokudb.data \ -D TOKUDB_DATA=$tokudbdir/../tokudb.data \
.. ..
ninja build_jemalloc build_lzma build_snappy ninja build_lzma build_snappy
popd popd
fi fi
......
...@@ -25,7 +25,7 @@ if [ ! -d build ] ; then ...@@ -25,7 +25,7 @@ if [ ! -d build ] ; then
-D RUN_LONG_TESTS=ON \ -D RUN_LONG_TESTS=ON \
-D TOKUDB_DATA=$tokudbdir/../tokudb.data \ -D TOKUDB_DATA=$tokudbdir/../tokudb.data \
.. ..
ninja build_jemalloc build_lzma build_snappy ninja build_lzma build_snappy
popd popd
fi fi
......
...@@ -25,7 +25,7 @@ if [ ! -d build ] ; then ...@@ -25,7 +25,7 @@ if [ ! -d build ] ; then
-D RUN_LONG_TESTS=ON \ -D RUN_LONG_TESTS=ON \
-D TOKUDB_DATA=$tokudbdir/../tokudb.data \ -D TOKUDB_DATA=$tokudbdir/../tokudb.data \
.. ..
ninja build_jemalloc build_lzma build_snappy ninja build_lzma build_snappy
popd popd
fi fi
......
...@@ -1075,7 +1075,8 @@ static inline int tokudb_generate_row(DB* dest_db, ...@@ -1075,7 +1075,8 @@ static inline int tokudb_generate_row(DB* dest_db,
} }
buff = (uchar *)dest_key->data; buff = (uchar *)dest_key->data;
assert_always(buff != NULL && max_key_len > 0); assert_always(buff != nullptr);
assert_always(max_key_len > 0);
} else { } else {
assert_unreachable(); assert_unreachable();
} }
......
...@@ -387,7 +387,8 @@ inline void TOKUDB_SHARE::init_cardinality_counts( ...@@ -387,7 +387,8 @@ inline void TOKUDB_SHARE::init_cardinality_counts(
assert_debug(_mutex.is_owned_by_me()); assert_debug(_mutex.is_owned_by_me());
// can not change number of keys live // can not change number of keys live
assert_always(_rec_per_key == NULL && _rec_per_keys == 0); assert_always(_rec_per_key == nullptr);
assert_always(_rec_per_keys == 0);
_rec_per_keys = rec_per_keys; _rec_per_keys = rec_per_keys;
_rec_per_key = rec_per_key; _rec_per_key = rec_per_key;
} }
......
...@@ -954,9 +954,8 @@ static inline int tokudb_compare_two_hidden_keys( ...@@ -954,9 +954,8 @@ static inline int tokudb_compare_two_hidden_keys(
const void* saved_key_data, const void* saved_key_data,
const uint32_t saved_key_size const uint32_t saved_key_size
) { ) {
assert_always( assert_always(new_key_size >= TOKUDB_HIDDEN_PRIMARY_KEY_LENGTH);
(new_key_size >= TOKUDB_HIDDEN_PRIMARY_KEY_LENGTH) && assert_always(saved_key_size >= TOKUDB_HIDDEN_PRIMARY_KEY_LENGTH);
(saved_key_size >= TOKUDB_HIDDEN_PRIMARY_KEY_LENGTH));
ulonglong a = hpk_char_to_num((uchar *) new_key_data); ulonglong a = hpk_char_to_num((uchar *) new_key_data);
ulonglong b = hpk_char_to_num((uchar *) saved_key_data); ulonglong b = hpk_char_to_num((uchar *) saved_key_data);
return a < b ? -1 : (a > b ? 1 : 0); return a < b ? -1 : (a > b ? 1 : 0);
...@@ -2534,7 +2533,8 @@ static uint32_t create_toku_secondary_key_pack_descriptor ( ...@@ -2534,7 +2533,8 @@ static uint32_t create_toku_secondary_key_pack_descriptor (
bool is_col_in_pk = false; bool is_col_in_pk = false;
if (bitmap_is_set(&kc_info->key_filters[pk_index],field_index)) { if (bitmap_is_set(&kc_info->key_filters[pk_index],field_index)) {
assert_always(!has_hpk && prim_key != NULL); assert_always(!has_hpk);
assert_always(prim_key != nullptr);
is_col_in_pk = true; is_col_in_pk = true;
} }
else { else {
......
...@@ -54,16 +54,20 @@ static void test_int8() { ...@@ -54,16 +54,20 @@ static void test_int8() {
assert(over); assert(over);
else if (m < -max) else if (m < -max)
assert(over); assert(over);
else else {
assert(!over && n == m); assert(!over);
assert(n == m);
}
n = int_sub(x, y, 8, &over); n = int_sub(x, y, 8, &over);
m = x - y; m = x - y;
if (m > max-1) if (m > max-1)
assert(over); assert(over);
else if (m < -max) else if (m < -max)
assert(over); assert(over);
else else {
assert(!over && n == m); assert(!over);
asset(n == m);
}
} }
} }
} }
...@@ -82,16 +86,20 @@ static void test_int16() { ...@@ -82,16 +86,20 @@ static void test_int16() {
assert(over); assert(over);
else if (m < -max) else if (m < -max)
assert(over); assert(over);
else else {
assert(!over && n == m); assert(!over);
assert(n == m);
}
n = int_sub(x, y, 16, &over); n = int_sub(x, y, 16, &over);
m = x - y; m = x - y;
if (m > max-1) if (m > max-1)
assert(over); assert(over);
else if (m < -max) else if (m < -max)
assert(over); assert(over);
else else {
assert(!over && n == m); assert(!over);
assert(n == m);
}
} }
} }
} }
...@@ -104,20 +112,42 @@ static void test_int24() { ...@@ -104,20 +112,42 @@ static void test_int24() {
s = int_add(1, (1ULL<<23)-1, 24, &over); assert(over); s = int_add(1, (1ULL<<23)-1, 24, &over); assert(over);
s = int_add((1ULL<<23)-1, 1, 24, &over); assert(over); s = int_add((1ULL<<23)-1, 1, 24, &over); assert(over);
s = int_sub(-1, (1ULL<<23), 24, &over); assert(!over && s == (1ULL<<23)-1); s = int_sub(-1, (1ULL<<23), 24, &over);
assert(!over);
assert(s == (1ULL<<23)-1);
s = int_sub((1ULL<<23), 1, 24, &over); assert(over); s = int_sub((1ULL<<23), 1, 24, &over); assert(over);
s = int_add(0, 0, 24, &over); assert(!over && s == 0); s = int_add(0, 0, 24, &over);
s = int_sub(0, 0, 24, &over); assert(!over && s == 0); assert(!over);
s = int_add(0, -1, 24, &over); assert(!over && s == -1); assert(s == 0);
s = int_sub(0, 1, 24, &over); assert(!over && s == -1); s = int_sub(0, 0, 24, &over);
s = int_add(0, (1ULL<<23), 24, &over); assert(!over && (s & ((1ULL<<24)-1)) == (1ULL<<23)); assert(!over);
s = int_sub(0, (1ULL<<23)-1, 24, &over); assert(!over && (s & ((1ULL<<24)-1)) == (1ULL<<23)+1); assert(s == 0);
s = int_add(0, -1, 24, &over);
s = int_add(-1, 0, 24, &over); assert(!over && s == -1); assert(!over);
s = int_add(-1, 1, 24, &over); assert(!over && s == 0); assert(s == -1);
s = int_sub(-1, -1, 24, &over); assert(!over && s == 0); s = int_sub(0, 1, 24, &over);
s = int_sub(-1, (1ULL<<23)-1, 24, &over); assert(!over && (s & ((1ULL<<24)-1)) == (1ULL<<23)); assert(!over);
assert(s == -1);
s = int_add(0, (1ULL<<23), 24, &over);
assert(!over);
assert((s & ((1ULL<<24)-1)) == (1ULL<<23));
s = int_sub(0, (1ULL<<23)-1, 24, &over);
assert(!over);
assert((s & ((1ULL<<24)-1)) == (1ULL<<23)+1);
s = int_add(-1, 0, 24, &over);
assert(!over);
assert(s == -1);
s = int_add(-1, 1, 24, &over);
assert(!over);
assert(s == 0);
s = int_sub(-1, -1, 24, &over);
assert(!over);
assert(s == 0);
s = int_sub(-1, (1ULL<<23)-1, 24, &over);
assert(!over);
assert((s & ((1ULL<<24)-1)) == (1ULL<<23));
} }
static void test_int32() { static void test_int32() {
...@@ -128,20 +158,42 @@ static void test_int32() { ...@@ -128,20 +158,42 @@ static void test_int32() {
s = int_add(1, (1ULL<<31)-1, 32, &over); assert(over); s = int_add(1, (1ULL<<31)-1, 32, &over); assert(over);
s = int_add((1ULL<<31)-1, 1, 32, &over); assert(over); s = int_add((1ULL<<31)-1, 1, 32, &over); assert(over);
s = int_sub(-1, (1ULL<<31), 32, &over); assert(s == (1ULL<<31)-1 && !over); s = int_sub(-1, (1ULL<<31), 32, &over);
assert(s == (1ULL<<31)-1);
assert(!over);
s = int_sub((1ULL<<31), 1, 32, &over); assert(over); s = int_sub((1ULL<<31), 1, 32, &over); assert(over);
s = int_add(0, 0, 32, &over); assert(s == 0 && !over); s = int_add(0, 0, 32, &over);
s = int_sub(0, 0, 32, &over); assert(s == 0 && !over); assert(s == 0);
s = int_add(0, -1, 32, &over); assert(s == -1 && !over); assert(!over);
s = int_sub(0, 1, 32, &over); assert(s == -1 && !over); s = int_sub(0, 0, 32, &over);
s = int_add(0, (1ULL<<31), 32, &over); assert((s & ((1ULL<<32)-1)) == (1ULL<<31) && !over); assert(s == 0);
s = int_sub(0, (1ULL<<31)-1, 32, &over); assert((s & ((1ULL<<32)-1)) == (1ULL<<31)+1 && !over); assert(!over);
s = int_add(0, -1, 32, &over);
s = int_add(-1, 0, 32, &over); assert(s == -1 && !over); assert(s == -1);
s = int_add(-1, 1, 32, &over); assert(s == 0 && !over); assert(!over);
s = int_sub(-1, -1, 32, &over); assert(s == 0 && !over); s = int_sub(0, 1, 32, &over);
s = int_sub(-1, (1ULL<<31)-1, 32, &over); assert((s & ((1ULL<<32)-1)) == (1ULL<<31) && !over); assert(s == -1);
assert(!over);
s = int_add(0, (1ULL<<31), 32, &over);
assert((s & ((1ULL<<32)-1)) == (1ULL<<31));
assert(!over);
s = int_sub(0, (1ULL<<31)-1, 32, &over);
assert((s & ((1ULL<<32)-1)) == (1ULL<<31)+1);
assert(!over);
s = int_add(-1, 0, 32, &over);
assert(s == -1);
assert(!over);
s = int_add(-1, 1, 32, &over);
assert(s == 0);
assert(!over);
s = int_sub(-1, -1, 32, &over);
assert(s == 0);
assert(!over);
s = int_sub(-1, (1ULL<<31)-1, 32, &over);
assert((s & ((1ULL<<32)-1)) == (1ULL<<31));
assert(!over);
} }
static void test_int64() { static void test_int64() {
...@@ -152,20 +204,42 @@ static void test_int64() { ...@@ -152,20 +204,42 @@ static void test_int64() {
s = int_add(1, (1ULL<<63)-1, 64, &over); assert(over); s = int_add(1, (1ULL<<63)-1, 64, &over); assert(over);
s = int_add((1ULL<<63)-1, 1, 64, &over); assert(over); s = int_add((1ULL<<63)-1, 1, 64, &over); assert(over);
s = int_sub(-1, (1ULL<<63), 64, &over); assert(s == (1ULL<<63)-1 && !over); s = int_sub(-1, (1ULL<<63), 64, &over);
assert(s == (1ULL<<63)-1);
assert(!over);
s = int_sub((1ULL<<63), 1, 64, &over); assert(over); s = int_sub((1ULL<<63), 1, 64, &over); assert(over);
s = int_add(0, 0, 64, &over); assert(s == 0 && !over); s = int_add(0, 0, 64, &over);
s = int_sub(0, 0, 64, &over); assert(s == 0 && !over); assert(s == 0);
s = int_add(0, -1, 64, &over); assert(s == -1 && !over); assert(!over);
s = int_sub(0, 1, 64, &over); assert(s == -1 && !over); s = int_sub(0, 0, 64, &over);
s = int_add(0, (1ULL<<63), 64, &over); assert(s == (int64_t)(1ULL<<63) && !over); assert(s == 0);
s = int_sub(0, (1ULL<<63)-1, 64, &over); assert(s == (int64_t)((1ULL<<63)+1) && !over); assert(!over);
s = int_add(0, -1, 64, &over);
s = int_add(-1, 0, 64, &over); assert(s == -1 && !over); assert(s == -1);
s = int_add(-1, 1, 64, &over); assert(s == 0 && !over); assert(!over);
s = int_sub(-1, -1, 64, &over); assert(s == 0 && !over); s = int_sub(0, 1, 64, &over);
s = int_sub(-1, (1ULL<<63)-1, 64, &over); assert(s == (int64_t)(1ULL<<63) && !over); assert(s == -1);
assert(!over);
s = int_add(0, (1ULL<<63), 64, &over);
assert(s == (int64_t)(1ULL<<63));
assert(!over);
s = int_sub(0, (1ULL<<63)-1, 64, &over);
assert(s == (int64_t)((1ULL<<63)+1));
assert(!over);
s = int_add(-1, 0, 64, &over);
assert(s == -1);
assert(!over);
s = int_add(-1, 1, 64, &over);
assert(s == 0);
assert(!over);
s = int_sub(-1, -1, 64, &over);
assert(s == 0);
assert(!over);
s = int_sub(-1, (1ULL<<63)-1, 64, &over);
assert(s == (int64_t)(1ULL<<63));
assert(!over);
} }
static void test_int_sign(uint length_bits) { static void test_int_sign(uint length_bits) {
......
...@@ -51,14 +51,18 @@ static void test_uint8() { ...@@ -51,14 +51,18 @@ static void test_uint8() {
m = x + y; m = x + y;
if (m > (1ULL<<8)-1) if (m > (1ULL<<8)-1)
assert(over); assert(over);
else else {
assert(!over && n == (m % 256)); assert(!over);
assert(n == (m % 256));
}
n = uint_sub(x, y, 8, &over); n = uint_sub(x, y, 8, &over);
m = x - y; m = x - y;
if (m > x) if (m > x)
assert(over); assert(over);
else else {
assert(!over && n == (m % 256)); assert(!over);
assert(n == (m % 256));
}
} }
} }
} }
...@@ -75,14 +79,18 @@ static void test_uint16() { ...@@ -75,14 +79,18 @@ static void test_uint16() {
m = x + y; m = x + y;
if (m > (1ULL<<16)-1) if (m > (1ULL<<16)-1)
assert(over); assert(over);
else else {
assert(!over && n == (m % (1ULL<<16))); assert(!over);
assert(n == (m % (1ULL<<16)));
}
n = uint_sub(x, y, 16, &over); n = uint_sub(x, y, 16, &over);
m = x - y; m = x - y;
if (m > x) if (m > x)
assert(over); assert(over);
else else {
assert(!over && n == (m % (1ULL<<16))); assert(!over);
assert(n == (m % (1ULL<<16)));
}
} }
} }
} }
...@@ -95,13 +103,23 @@ static void test_uint24() { ...@@ -95,13 +103,23 @@ static void test_uint24() {
s = uint_add((1ULL<<24)-1, (1ULL<<24)-1, 24, &over); assert(over); s = uint_add((1ULL<<24)-1, (1ULL<<24)-1, 24, &over); assert(over);
s = uint_add((1ULL<<24)-1, 1, 24, &over); assert(over); s = uint_add((1ULL<<24)-1, 1, 24, &over); assert(over);
s = uint_add((1ULL<<24)-1, 0, 24, &over); assert(!over && s == (1ULL<<24)-1); s = uint_add((1ULL<<24)-1, 0, 24, &over);
s = uint_add(0, 1, 24, &over); assert(!over && s == 1); assert(!over);
s = uint_add(0, 0, 24, &over); assert(!over && s == 0); assert(s == (1ULL<<24)-1);
s = uint_sub(0, 0, 24, &over); assert(!over && s == 0); s = uint_add(0, 1, 24, &over);
assert(!over);
assert(s == 1);
s = uint_add(0, 0, 24, &over);
assert(!over);
assert(s == 0);
s = uint_sub(0, 0, 24, &over);
assert(!over);
assert(s == 0);
s = uint_sub(0, 1, 24, &over); assert(over); s = uint_sub(0, 1, 24, &over); assert(over);
s = uint_sub(0, (1ULL<<24)-1, 24, &over); assert(over); s = uint_sub(0, (1ULL<<24)-1, 24, &over); assert(over);
s = uint_sub((1ULL<<24)-1, (1ULL<<24)-1, 24, &over); assert(!over && s == 0); s = uint_sub((1ULL<<24)-1, (1ULL<<24)-1, 24, &over);
assert(!over);
assert(s == 0);
} }
static void test_uint32() { static void test_uint32() {
...@@ -112,13 +130,23 @@ static void test_uint32() { ...@@ -112,13 +130,23 @@ static void test_uint32() {
s = uint_add((1ULL<<32)-1, (1ULL<<32)-1, 32, &over); assert(over); s = uint_add((1ULL<<32)-1, (1ULL<<32)-1, 32, &over); assert(over);
s = uint_add((1ULL<<32)-1, 1, 32, &over); assert(over); s = uint_add((1ULL<<32)-1, 1, 32, &over); assert(over);
s = uint_add((1ULL<<32)-1, 0, 32, &over); assert(!over && s == (1ULL<<32)-1); s = uint_add((1ULL<<32)-1, 0, 32, &over);
s = uint_add(0, 1, 32, &over); assert(!over && s == 1); assert(!over);
s = uint_add(0, 0, 32, &over); assert(!over && s == 0); assert(s == (1ULL<<32)-1);
s = uint_sub(0, 0, 32, &over); assert(!over && s == 0); s = uint_add(0, 1, 32, &over);
assert(!over);
assert(s == 1);
s = uint_add(0, 0, 32, &over);
assert(!over);
assert(s == 0);
s = uint_sub(0, 0, 32, &over);
assert(!over);
assert(s == 0);
s = uint_sub(0, 1, 32, &over); assert(over); s = uint_sub(0, 1, 32, &over); assert(over);
s = uint_sub(0, (1ULL<<32)-1, 32, &over); assert(over); s = uint_sub(0, (1ULL<<32)-1, 32, &over); assert(over);
s = uint_sub((1ULL<<32)-1, (1ULL<<32)-1, 32, &over); assert(!over && s == 0); s = uint_sub((1ULL<<32)-1, (1ULL<<32)-1, 32, &over);
assert(!over);
assert(s == 0);
} }
static void test_uint64() { static void test_uint64() {
...@@ -129,13 +157,23 @@ static void test_uint64() { ...@@ -129,13 +157,23 @@ static void test_uint64() {
s = uint_add(~0ULL, ~0ULL, 64, &over); assert(over); s = uint_add(~0ULL, ~0ULL, 64, &over); assert(over);
s = uint_add(~0ULL, 1, 64, &over); assert(over); s = uint_add(~0ULL, 1, 64, &over); assert(over);
s = uint_add(~0ULL, 0, 64, &over); assert(!over && s == ~0ULL); s = uint_add(~0ULL, 0, 64, &over);
s = uint_add(0, 1, 64, &over); assert(!over && s == 1); assert(!over);
s = uint_add(0, 0, 64, &over); assert(!over && s == 0); assert(s == ~0ULL);
s = uint_sub(0, 0, 64, &over); assert(!over && s == 0); s = uint_add(0, 1, 64, &over);
assert(!over);
assert(s == 1);
s = uint_add(0, 0, 64, &over);
assert(!over);
assert(s == 0);
s = uint_sub(0, 0, 64, &over);
assert(!over);
assert(s == 0);
s = uint_sub(0, 1, 64, &over); assert(over); s = uint_sub(0, 1, 64, &over); assert(over);
s = uint_sub(0, ~0ULL, 64, &over); assert(over); s = uint_sub(0, ~0ULL, 64, &over); assert(over);
s = uint_sub(~0ULL, ~0ULL, 64, &over); assert(!over && s == 0); s = uint_sub(~0ULL, ~0ULL, 64, &over);
assert(!over);
assert(s == 0);
} }
int main() { int main() {
......
...@@ -27,7 +27,6 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. ...@@ -27,7 +27,6 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
#include <stdint.h> #include <stdint.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <sys/types.h> #include <sys/types.h>
#include <tokudb_math.h> #include <tokudb_math.h>
......
...@@ -32,9 +32,13 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. ...@@ -32,9 +32,13 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
static void test_null() { static void test_null() {
tokudb::buffer b; tokudb::buffer b;
assert(b.data() == NULL && b.size() == 0 && b.limit() == 0); assert(b.data() == nullptr);
assert(b.size() == 0);
assert(b.limit() == 0);
b.append(NULL, 0); b.append(NULL, 0);
assert(b.data() == NULL && b.size() == 0 && b.limit() == 0); assert(b.data() == nullptr);
assert(b.size() == 0);
assert(b.limit() == 0);
} }
static void append_az(tokudb::buffer &b) { static void append_az(tokudb::buffer &b) {
...@@ -132,7 +136,8 @@ static void test_replace_grow() { ...@@ -132,7 +136,8 @@ static void test_replace_grow() {
} }
for (size_t i = 0; i < a.size()/2; i++) { for (size_t i = 0; i < a.size()/2; i++) {
unsigned char *cp = (unsigned char *) a.data() + 2*i; unsigned char *cp = (unsigned char *) a.data() + 2*i;
assert(cp[0] == 'a'+i && cp[1] == 'a'+i); assert(cp[0] == 'a'+i);
assert(cp[1] == 'a'+i);
} }
} }
......
...@@ -27,7 +27,6 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. ...@@ -27,7 +27,6 @@ Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
#include <stdint.h> #include <stdint.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
#include <sys/types.h> #include <sys/types.h>
#include <tokudb_math.h> #include <tokudb_math.h>
......
...@@ -52,7 +52,8 @@ static void test_vlq_uint32_error(void) { ...@@ -52,7 +52,8 @@ static void test_vlq_uint32_error(void) {
in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, 1); in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, 1);
assert(in_s == 0); assert(in_s == 0);
in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, 2); in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, 2);
assert(in_s == 2 && n == 128); assert(in_s == 2);
assert(n == 128);
} }
static void test_80000000(void) { static void test_80000000(void) {
...@@ -63,7 +64,8 @@ static void test_80000000(void) { ...@@ -63,7 +64,8 @@ static void test_80000000(void) {
out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b); out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b);
assert(out_s == 5); assert(out_s == 5);
in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s); in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s);
assert(in_s == 5 && n == v); assert(in_s == 5);
assert(n == v);
} }
static void test_100000000(void) { static void test_100000000(void) {
...@@ -74,7 +76,8 @@ static void test_100000000(void) { ...@@ -74,7 +76,8 @@ static void test_100000000(void) {
out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b); out_s = tokudb::vlq_encode_ui<uint64_t>(v, b, sizeof b);
assert(out_s == 5); assert(out_s == 5);
in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s); in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s);
assert(in_s == 5 && n == v); assert(in_s == 5);
assert(n == v);
} }
int main(void) { int main(void) {
......
...@@ -44,7 +44,8 @@ static void test_vlq_uint32(void) { ...@@ -44,7 +44,8 @@ static void test_vlq_uint32(void) {
assert(out_s == 1); assert(out_s == 1);
uint32_t n; uint32_t n;
size_t in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s); size_t in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s);
assert(in_s == 1 && n == v); assert(in_s == 1);
assert(n == v);
} }
printf("%u\n", 1<<7); printf("%u\n", 1<<7);
...@@ -54,7 +55,8 @@ static void test_vlq_uint32(void) { ...@@ -54,7 +55,8 @@ static void test_vlq_uint32(void) {
assert(out_s == 2); assert(out_s == 2);
uint32_t n; uint32_t n;
size_t in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s); size_t in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s);
assert(in_s == 2 && n == v); assert(in_s == 2);
assert(n == v);
} }
printf("%u\n", 1<<14); printf("%u\n", 1<<14);
...@@ -64,7 +66,8 @@ static void test_vlq_uint32(void) { ...@@ -64,7 +66,8 @@ static void test_vlq_uint32(void) {
assert(out_s == 3); assert(out_s == 3);
uint32_t n; uint32_t n;
size_t in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s); size_t in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s);
assert(in_s == 3 && n == v); assert(in_s == 3);
assert(n == v);
} }
printf("%u\n", 1<<21); printf("%u\n", 1<<21);
...@@ -74,7 +77,8 @@ static void test_vlq_uint32(void) { ...@@ -74,7 +77,8 @@ static void test_vlq_uint32(void) {
assert(out_s == 4); assert(out_s == 4);
uint32_t n; uint32_t n;
size_t in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s); size_t in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s);
assert(in_s == 4 && n == v); assert(in_s == 4);
assert(n == v);
} }
printf("%u\n", 1<<28); printf("%u\n", 1<<28);
...@@ -84,7 +88,8 @@ static void test_vlq_uint32(void) { ...@@ -84,7 +88,8 @@ static void test_vlq_uint32(void) {
assert(out_s == 5); assert(out_s == 5);
uint32_t n; uint32_t n;
size_t in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s); size_t in_s = tokudb::vlq_decode_ui<uint32_t>(&n, b, out_s);
assert(in_s == 5 && n == v); assert(in_s == 5);
assert(n == v);
} }
} }
......
...@@ -46,7 +46,8 @@ static void test_vlq_uint64(uint64_t start, uint64_t stride) { ...@@ -46,7 +46,8 @@ static void test_vlq_uint64(uint64_t start, uint64_t stride) {
assert(out_s == 1); assert(out_s == 1);
uint64_t n; uint64_t n;
size_t in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s); size_t in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s);
assert(in_s == 1 && n == v); assert(in_s == 1);
assert(n == v);
} }
printf("%u\n", 1<<7); printf("%u\n", 1<<7);
...@@ -56,7 +57,8 @@ static void test_vlq_uint64(uint64_t start, uint64_t stride) { ...@@ -56,7 +57,8 @@ static void test_vlq_uint64(uint64_t start, uint64_t stride) {
assert(out_s == 2); assert(out_s == 2);
uint64_t n; uint64_t n;
size_t in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s); size_t in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s);
assert(in_s == 2 && n == v); assert(in_s == 2);
assert(n == v);
} }
printf("%u\n", 1<<14); printf("%u\n", 1<<14);
...@@ -66,7 +68,8 @@ static void test_vlq_uint64(uint64_t start, uint64_t stride) { ...@@ -66,7 +68,8 @@ static void test_vlq_uint64(uint64_t start, uint64_t stride) {
assert(out_s == 3); assert(out_s == 3);
uint64_t n; uint64_t n;
size_t in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s); size_t in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s);
assert(in_s == 3 && n == v); assert(in_s == 3);
assert(n == v);
} }
printf("%u\n", 1<<21); printf("%u\n", 1<<21);
...@@ -76,7 +79,8 @@ static void test_vlq_uint64(uint64_t start, uint64_t stride) { ...@@ -76,7 +79,8 @@ static void test_vlq_uint64(uint64_t start, uint64_t stride) {
assert(out_s == 4); assert(out_s == 4);
uint64_t n; uint64_t n;
size_t in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s); size_t in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s);
assert(in_s == 4 && n == v); assert(in_s == 4);
assert(n == v);
} }
printf("%u\n", 1<<28); printf("%u\n", 1<<28);
...@@ -90,7 +94,8 @@ static void test_vlq_uint64(uint64_t start, uint64_t stride) { ...@@ -90,7 +94,8 @@ static void test_vlq_uint64(uint64_t start, uint64_t stride) {
assert(out_s == 5); assert(out_s == 5);
uint64_t n; uint64_t n;
size_t in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s); size_t in_s = tokudb::vlq_decode_ui<uint64_t>(&n, b, out_s);
assert(in_s == 5 && n == v); assert(in_s == 5);
assert(n == v);
} }
} }
......
...@@ -134,8 +134,8 @@ class buffer { ...@@ -134,8 +134,8 @@ class buffer {
char* data_offset = (char*)m_data + offset; char* data_offset = (char*)m_data + offset;
if (new_s != old_s) { if (new_s != old_s) {
size_t n = m_size - (offset + old_s); size_t n = m_size - (offset + old_s);
assert_always( assert_always(offset + new_s + n <= m_limit);
offset + new_s + n <= m_limit && offset + old_s + n <= m_limit); assert_always(offset + old_s + n <= m_limit);
memmove(data_offset + new_s, data_offset + old_s, n); memmove(data_offset + new_s, data_offset + old_s, n);
if (new_s > old_s) if (new_s > old_s)
m_size += new_s - old_s; m_size += new_s - old_s;
......
...@@ -59,7 +59,8 @@ TOKUDB_UNUSED(static uint64_t uint_add( ...@@ -59,7 +59,8 @@ TOKUDB_UNUSED(static uint64_t uint_add(
bool* over)); bool* over));
static uint64_t uint_add(uint64_t x, uint64_t y, uint length_bits, bool *over) { static uint64_t uint_add(uint64_t x, uint64_t y, uint length_bits, bool *over) {
uint64_t mask = uint_mask(length_bits); uint64_t mask = uint_mask(length_bits);
assert_always((x & ~mask) == 0 && (y & ~mask) == 0); assert_always((x & ~mask) == 0);
assert_always((y & ~mask) == 0);
uint64_t s = (x + y) & mask; uint64_t s = (x + y) & mask;
*over = s < x; // check for overflow *over = s < x; // check for overflow
return s; return s;
...@@ -75,7 +76,8 @@ TOKUDB_UNUSED(static uint64_t uint_sub( ...@@ -75,7 +76,8 @@ TOKUDB_UNUSED(static uint64_t uint_sub(
bool* over)); bool* over));
static uint64_t uint_sub(uint64_t x, uint64_t y, uint length_bits, bool *over) { static uint64_t uint_sub(uint64_t x, uint64_t y, uint length_bits, bool *over) {
uint64_t mask = uint_mask(length_bits); uint64_t mask = uint_mask(length_bits);
assert_always((x & ~mask) == 0 && (y & ~mask) == 0); assert_always((x & ~mask) == 0);
assert_always((y & ~mask) == 0);
uint64_t s = (x - y) & mask; uint64_t s = (x - y) & mask;
*over = s > x; // check for overflow *over = s > x; // check for overflow
return s; return s;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment