Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CCTZ contrib #9687

Merged
merged 10 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ endif ()

# Need to process before "contrib" dir:
include (cmake/find/jemalloc.cmake)
include (cmake/find/cctz.cmake)
include (cmake/find/mysqlclient.cmake)

# When testing for memory leaks with Valgrind, don't link tcmalloc or jemalloc.
Expand Down
11 changes: 3 additions & 8 deletions base/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ endif ()

target_include_directories(common PUBLIC .. ${CMAKE_CURRENT_BINARY_DIR}/..)

if(CCTZ_INCLUDE_DIR)
target_include_directories(common BEFORE PRIVATE ${CCTZ_INCLUDE_DIR})
endif()

if (NOT USE_INTERNAL_BOOST_LIBRARY)
target_include_directories (common SYSTEM BEFORE PUBLIC ${Boost_INCLUDE_DIRS})
endif ()
Expand All @@ -53,10 +49,6 @@ if(NOT USE_INTERNAL_POCO_LIBRARY)
target_include_directories (common SYSTEM BEFORE PUBLIC ${Poco_Foundation_INCLUDE_DIR})
endif()

if(CCTZ_LIBRARY)
target_link_libraries(common PRIVATE ${CCTZ_LIBRARY})
endif()

# allow explicitly fallback to readline
if (NOT ENABLE_REPLXX AND ENABLE_READLINE)
message (STATUS "Attempt to fallback to readline explicitly")
Expand Down Expand Up @@ -88,6 +80,9 @@ target_link_libraries (common
${Boost_SYSTEM_LIBRARY}
FastMemcpy
replxx

PRIVATE
cctz
)

if (ENABLE_TESTS)
Expand Down
7 changes: 4 additions & 3 deletions base/common/DateLUT.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <common/DateLUT.h>
#include "DateLUT.h"

#include <filesystem>
#include <Poco/DigestStream.h>
#include <Poco/Exception.h>
#include <Poco/SHA1Engine.h>
#include <Poco/DigestStream.h>

#include <filesystem>
#include <fstream>


Expand Down
19 changes: 7 additions & 12 deletions base/common/DateLUT.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
#pragma once

#include "DateLUTImpl.h"
#include <unordered_map>
#include <atomic>
#include <mutex>
#include <memory>

#include "defines.h"

#include <boost/noncopyable.hpp>

// Also defined in Core/Defines.h
#if !defined(ALWAYS_INLINE)
#if defined(_MSC_VER)
#define ALWAYS_INLINE __forceinline
#else
#define ALWAYS_INLINE __attribute__((__always_inline__))
#endif
#endif
#include <atomic>
#include <memory>
#include <mutex>
#include <unordered_map>


/// This class provides lazy initialization and lookup of singleton DateLUTImpl objects for a given timezone.
Expand Down
17 changes: 4 additions & 13 deletions base/common/DateLUTImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
#if __has_include(<cctz/civil_time.h>)
#include <cctz/civil_time.h> // bundled, debian
#else
#include <civil_time.h> // freebsd
#endif
#include "DateLUTImpl.h"

#if __has_include(<cctz/time_zone.h>)
#include <cctz/civil_time.h>
#include <cctz/time_zone.h>
#else
#include <time_zone.h>
#endif

#include <common/DateLUTImpl.h>
#include <Poco/Exception.h>

#include <memory>
#include <cassert>
#include <chrono>
#include <cstring>
#include <cassert>
#include <iostream>
#include <memory>

#define DATE_LUT_MIN 0

Expand Down
5 changes: 3 additions & 2 deletions base/common/DateLUTImpl.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once

#include "Types.h"
#include "DayNum.h"
#include "likely.h"
#include "defines.h"
#include "types.h"

#include <ctime>
#include <string>

Expand Down
2 changes: 1 addition & 1 deletion base/common/DayNum.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <common/Types.h>
#include <common/types.h>
#include <common/strong_typedef.h>

/** Represents number of days since 1970-01-01.
Expand Down
2 changes: 1 addition & 1 deletion base/common/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <typeinfo>
#include <Poco/Exception.h>
#include <common/StringRef.h>
#include <common/Types.h>
#include <common/types.h>


/** Очень простой класс для чтения JSON (или его кусочков).
Expand Down
2 changes: 1 addition & 1 deletion base/common/LineReader.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <common/Types.h>
#include <common/types.h>

#include <atomic>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion base/common/StringRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <functional>
#include <ostream>

#include <common/Types.h>
#include <common/types.h>
#include <common/unaligned.h>

#include <city.h>
Expand Down
87 changes: 87 additions & 0 deletions base/common/defines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#pragma once

#if defined(_MSC_VER)
# if !defined(likely)
# define likely(x) (x)
# endif
# if !defined(unlikely)
# define unlikely(x) (x)
# endif
#else
# if !defined(likely)
# define likely(x) (__builtin_expect(!!(x), 1))
# endif
# if !defined(unlikely)
# define unlikely(x) (__builtin_expect(!!(x), 0))
# endif
#endif

#if defined(_MSC_VER)
# define ALWAYS_INLINE __forceinline
# define NO_INLINE static __declspec(noinline)
# define MAY_ALIAS
#else
# define ALWAYS_INLINE __attribute__((__always_inline__))
# define NO_INLINE __attribute__((__noinline__))
# define MAY_ALIAS __attribute__((__may_alias__))
#endif

#if !defined(__x86_64__) && !defined(__aarch64__) && !defined(__PPC__)
# error "The only supported platforms are x86_64 and AArch64, PowerPC (work in progress)"
#endif

/// Check for presence of address sanitizer
#if !defined(ADDRESS_SANITIZER)
# if defined(__has_feature)
# if __has_feature(address_sanitizer)
# define ADDRESS_SANITIZER 1
# endif
# elif defined(__SANITIZE_ADDRESS__)
# define ADDRESS_SANITIZER 1
# endif
#endif

#if !defined(THREAD_SANITIZER)
# if defined(__has_feature)
# if __has_feature(thread_sanitizer)
# define THREAD_SANITIZER 1
# endif
# elif defined(__SANITIZE_THREAD__)
# define THREAD_SANITIZER 1
# endif
#endif

#if !defined(MEMORY_SANITIZER)
# if defined(__has_feature)
# if __has_feature(memory_sanitizer)
# define MEMORY_SANITIZER 1
# endif
# elif defined(__MEMORY_SANITIZER__)
# define MEMORY_SANITIZER 1
# endif
#endif

/// TODO: Strange enough, there is no way to detect UB sanitizer.

/// Explicitly allow undefined behaviour for certain functions. Use it as a function attribute.
/// It is useful in case when compiler cannot see (and exploit) it, but UBSan can.
/// Example: multiplication of signed integers with possibility of overflow when both sides are from user input.
#if defined(__clang__)
# define NO_SANITIZE_UNDEFINED __attribute__((__no_sanitize__("undefined")))
# define NO_SANITIZE_ADDRESS __attribute__((__no_sanitize__("address")))
# define NO_SANITIZE_THREAD __attribute__((__no_sanitize__("thread")))
#else /// It does not work in GCC. GCC 7 cannot recognize this attribute and GCC 8 simply ignores it.
# define NO_SANITIZE_UNDEFINED
# define NO_SANITIZE_ADDRESS
# define NO_SANITIZE_THREAD
#endif

#if defined __GNUC__ && !defined __clang__
# define OPTIMIZE(x) __attribute__((__optimize__(x)))
#else
# define OPTIMIZE(x)
#endif

/// A macro for suppressing warnings about unused variables or function results.
/// Useful for structured bindings which have no standard way to declare this.
#define UNUSED(...) (void)(__VA_ARGS__)
1 change: 0 additions & 1 deletion base/common/itoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <cstddef>
#include <cstring>
#include <type_traits>
#include "likely.h"

using int128_t = __int128;
using uint128_t = unsigned __int128;
Expand Down
15 changes: 0 additions & 15 deletions base/common/likely.h

This file was deleted.

28 changes: 6 additions & 22 deletions base/common/memory.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <new>
#include "likely.h"
#include "defines.h"

#if __has_include(<common/config_common.h>)
#include <common/config_common.h>
Expand All @@ -19,27 +19,11 @@
#include <cstdlib>
#endif

// Also defined in Core/Defines.h
#if !defined(ALWAYS_INLINE)
#if defined(_MSC_VER)
#define ALWAYS_INLINE inline __forceinline
#else
#define ALWAYS_INLINE inline __attribute__((__always_inline__))
#endif
#endif

#if !defined(NO_INLINE)
#if defined(_MSC_VER)
#define NO_INLINE static __declspec(noinline)
#else
#define NO_INLINE __attribute__((__noinline__))
#endif
#endif

namespace Memory
{

ALWAYS_INLINE void * newImpl(std::size_t size)
inline ALWAYS_INLINE void * newImpl(std::size_t size)
{
auto * ptr = malloc(size);
if (likely(ptr != nullptr))
Expand All @@ -49,19 +33,19 @@ ALWAYS_INLINE void * newImpl(std::size_t size)
throw std::bad_alloc{};
}

ALWAYS_INLINE void * newNoExept(std::size_t size) noexcept
inline ALWAYS_INLINE void * newNoExept(std::size_t size) noexcept
{
return malloc(size);
}

ALWAYS_INLINE void deleteImpl(void * ptr) noexcept
inline ALWAYS_INLINE void deleteImpl(void * ptr) noexcept
{
free(ptr);
}

#if USE_JEMALLOC

ALWAYS_INLINE void deleteSized(void * ptr, std::size_t size) noexcept
inline ALWAYS_INLINE void deleteSized(void * ptr, std::size_t size) noexcept
{
if (unlikely(ptr == nullptr))
return;
Expand All @@ -71,7 +55,7 @@ ALWAYS_INLINE void deleteSized(void * ptr, std::size_t size) noexcept

#else

ALWAYS_INLINE void deleteSized(void * ptr, std::size_t size [[maybe_unused]]) noexcept
inline ALWAYS_INLINE void deleteSized(void * ptr, std::size_t size [[maybe_unused]]) noexcept
{
free(ptr);
}
Expand Down
2 changes: 1 addition & 1 deletion base/common/shift10.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <common/shift10.h>

#include <common/likely.h>
#include "defines.h"

#include <limits>

Expand Down
2 changes: 1 addition & 1 deletion base/common/shift10.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <common/Types.h>
#include <common/types.h>

/** Almost the same as x = x * exp10(exponent), but gives more accurate result.
* Example:
Expand Down
2 changes: 1 addition & 1 deletion base/common/terminalColors.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <string>
#include <common/Types.h>
#include <common/types.h>


/** Set color in terminal based on 64-bit hash value.
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion base/daemon/BaseDaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <Poco/Util/ServerApplication.h>
#include <Poco/Net/SocketAddress.h>
#include <Poco/Version.h>
#include <common/Types.h>
#include <common/types.h>
#include <common/logger_useful.h>
#include <common/getThreadId.h>
#include <daemon/GraphiteWriter.h>
Expand Down
2 changes: 1 addition & 1 deletion base/mysqlxx/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <limits>

#include <common/preciseExp10.h>
#include <common/Types.h>
#include <common/types.h>
#include <common/DateLUT.h>

#include <mysqlxx/Types.h>
Expand Down