Commit b0a25f01 authored by gabime's avatar gabime

wip - no-exceptions support

parent db1babab
...@@ -63,6 +63,10 @@ if(WIN32) ...@@ -63,6 +63,10 @@ if(WIN32)
option(SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF) option(SPDLOG_WCHAR_SUPPORT "Support wchar api" OFF)
endif() endif()
option(SPDLOG_NO_EXCEPTIONS "Support for -fno-exceptions. Replace throw with std::abort" OFF)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
...@@ -119,6 +123,11 @@ if(SPDLOG_WCHAR_SUPPORT) ...@@ -119,6 +123,11 @@ if(SPDLOG_WCHAR_SUPPORT)
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_TO_UTF8_SUPPORT) target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_WCHAR_TO_UTF8_SUPPORT)
endif() endif()
if(SPDLOG_NO_EXCEPTIONS)
target_compile_definitions(spdlog PUBLIC SPDLOG_NO_EXCEPTIONS)
target_compile_definitions(spdlog_header_only INTERFACE SPDLOG_NO_EXCEPTIONS)
endif()
#--------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------
# Build binaries # Build binaries
......
...@@ -33,7 +33,7 @@ SPDLOG_INLINE void spdlog::async_logger::sink_it_(details::log_msg &msg) ...@@ -33,7 +33,7 @@ SPDLOG_INLINE void spdlog::async_logger::sink_it_(details::log_msg &msg)
} }
else else
{ {
throw spdlog_ex("async log: thread pool doesn't exist anymore"); SPDLOG_THROW spdlog_ex("async log: thread pool doesn't exist anymore");
} }
} }
...@@ -46,7 +46,7 @@ SPDLOG_INLINE void spdlog::async_logger::flush_() ...@@ -46,7 +46,7 @@ SPDLOG_INLINE void spdlog::async_logger::flush_()
} }
else else
{ {
throw spdlog_ex("async flush: thread pool doesn't exist anymore"); SPDLOG_THROW spdlog_ex("async flush: thread pool doesn't exist anymore");
} }
} }
......
...@@ -64,6 +64,12 @@ ...@@ -64,6 +64,12 @@
#define SPDLOG_FUNCTION __FUNCTION__ #define SPDLOG_FUNCTION __FUNCTION__
#endif #endif
#ifdef SPDLOG_NO_EXCEPTIONS
#define SPDLOG_THROW
#else
#define SPDLOG_THROW throw
#endif
namespace spdlog { namespace spdlog {
class formatter; class formatter;
......
...@@ -39,14 +39,14 @@ SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate) ...@@ -39,14 +39,14 @@ SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate)
details::os::sleep_for_millis(open_interval); details::os::sleep_for_millis(open_interval);
} }
throw spdlog_ex("Failed opening file " + os::filename_to_str(_filename) + " for writing", errno); SPDLOG_THROW spdlog_ex("Failed opening file " + os::filename_to_str(_filename) + " for writing", errno);
} }
SPDLOG_INLINE void file_helper::reopen(bool truncate) SPDLOG_INLINE void file_helper::reopen(bool truncate)
{ {
if (_filename.empty()) if (_filename.empty())
{ {
throw spdlog_ex("Failed re opening file - was not opened before"); SPDLOG_THROW spdlog_ex("Failed re opening file - was not opened before");
} }
open(_filename, truncate); open(_filename, truncate);
} }
...@@ -71,7 +71,7 @@ SPDLOG_INLINE void file_helper::write(const fmt::memory_buffer &buf) ...@@ -71,7 +71,7 @@ SPDLOG_INLINE void file_helper::write(const fmt::memory_buffer &buf)
auto data = buf.data(); auto data = buf.data();
if (std::fwrite(data, 1, msg_size, fd_) != msg_size) if (std::fwrite(data, 1, msg_size, fd_) != msg_size)
{ {
throw spdlog_ex("Failed writing to file " + os::filename_to_str(_filename), errno); SPDLOG_THROW spdlog_ex("Failed writing to file " + os::filename_to_str(_filename), errno);
} }
} }
...@@ -79,7 +79,7 @@ SPDLOG_INLINE size_t file_helper::size() const ...@@ -79,7 +79,7 @@ SPDLOG_INLINE size_t file_helper::size() const
{ {
if (fd_ == nullptr) if (fd_ == nullptr)
{ {
throw spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(_filename)); SPDLOG_THROW spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(_filename));
} }
return os::filesize(fd_); return os::filesize(fd_);
} }
......
...@@ -120,13 +120,13 @@ SPDLOG_INLINE void prevent_child_fd(FILE *f) ...@@ -120,13 +120,13 @@ SPDLOG_INLINE void prevent_child_fd(FILE *f)
#if !defined(__cplusplus_winrt) #if !defined(__cplusplus_winrt)
auto file_handle = reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(f))); auto file_handle = reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(f)));
if (!::SetHandleInformation(file_handle, HANDLE_FLAG_INHERIT, 0)) if (!::SetHandleInformation(file_handle, HANDLE_FLAG_INHERIT, 0))
throw spdlog_ex("SetHandleInformation failed", errno); SPDLOG_THROW spdlog_ex("SetHandleInformation failed", errno);
#endif #endif
#else #else
auto fd = fileno(f); auto fd = fileno(f);
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
{ {
throw spdlog_ex("fcntl with FD_CLOEXEC failed", errno); SPDLOG_THROW spdlog_ex("fcntl with FD_CLOEXEC failed", errno);
} }
#endif #endif
} }
...@@ -192,7 +192,7 @@ SPDLOG_INLINE size_t filesize(FILE *f) ...@@ -192,7 +192,7 @@ SPDLOG_INLINE size_t filesize(FILE *f)
{ {
if (f == nullptr) if (f == nullptr)
{ {
throw spdlog_ex("Failed getting file size. fd is null"); SPDLOG_THROW spdlog_ex("Failed getting file size. fd is null");
} }
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
int fd = _fileno(f); int fd = _fileno(f);
...@@ -229,7 +229,7 @@ SPDLOG_INLINE size_t filesize(FILE *f) ...@@ -229,7 +229,7 @@ SPDLOG_INLINE size_t filesize(FILE *f)
} }
#endif #endif
#endif #endif
throw spdlog_ex("Failed getting file size from fd", errno); SPDLOG_THROW spdlog_ex("Failed getting file size from fd", errno);
} }
// Return utc offset in minutes or throw spdlog_ex on failure // Return utc offset in minutes or throw spdlog_ex on failure
......
...@@ -245,7 +245,7 @@ SPDLOG_INLINE void registry::throw_if_exists_(const std::string &logger_name) ...@@ -245,7 +245,7 @@ SPDLOG_INLINE void registry::throw_if_exists_(const std::string &logger_name)
{ {
if (loggers_.find(logger_name) != loggers_.end()) if (loggers_.find(logger_name) != loggers_.end())
{ {
throw spdlog_ex("logger with name '" + logger_name + "' already exists"); SPDLOG_THROW spdlog_ex("logger with name '" + logger_name + "' already exists");
} }
} }
......
...@@ -17,7 +17,7 @@ SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std ...@@ -17,7 +17,7 @@ SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std
{ {
if (threads_n == 0 || threads_n > 1000) if (threads_n == 0 || threads_n > 1000)
{ {
throw spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid " SPDLOG_THROW spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid "
"range is 1-1000)"); "range is 1-1000)");
} }
for (size_t i = 0; i < threads_n; i++) for (size_t i = 0; i < threads_n; i++)
......
...@@ -64,7 +64,7 @@ protected: ...@@ -64,7 +64,7 @@ protected:
if (ret < 0) if (ret < 0)
{ {
throw spdlog_ex("__android_log_write() failed", ret); SPDLOG_THROW spdlog_ex("__android_log_write() failed", ret);
} }
} }
......
...@@ -52,7 +52,7 @@ public: ...@@ -52,7 +52,7 @@ public:
{ {
if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59) if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59)
{ {
throw spdlog_ex("daily_file_sink: Invalid rotation time in ctor"); SPDLOG_THROW spdlog_ex("daily_file_sink: Invalid rotation time in ctor");
} }
auto now = log_clock::now(); auto now = log_clock::now();
file_helper_.open(FileNameCalc::calc_filename(base_filename_, now_tm(now)), truncate_); file_helper_.open(FileNameCalc::calc_filename(base_filename_, now_tm(now)), truncate_);
......
...@@ -112,7 +112,7 @@ SPDLOG_INLINE void rotating_file_sink<Mutex>::rotate_() ...@@ -112,7 +112,7 @@ SPDLOG_INLINE void rotating_file_sink<Mutex>::rotate_()
{ {
file_helper_.reopen(true); // truncate the log file anyway to prevent it to grow beyond its limit! file_helper_.reopen(true); // truncate the log file anyway to prevent it to grow beyond its limit!
current_size_ = 0; current_size_ = 0;
throw spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), errno); SPDLOG_THROW spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), errno);
} }
} }
} }
......
...@@ -66,7 +66,7 @@ protected: ...@@ -66,7 +66,7 @@ protected:
if (err) if (err)
{ {
throw spdlog_ex("Failed writing to systemd", errno); SPDLOG_THROW spdlog_ex("Failed writing to systemd", errno);
} }
} }
......
...@@ -153,7 +153,7 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::write_to_file_(const fmt::memory ...@@ -153,7 +153,7 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::write_to_file_(const fmt::memory
bool ok = ::WriteFile(out_handle_, formatted.data() + total_written, size - total_written, &bytes_written, nullptr) != 0; bool ok = ::WriteFile(out_handle_, formatted.data() + total_written, size - total_written, &bytes_written, nullptr) != 0;
if (!ok || bytes_written == 0) if (!ok || bytes_written == 0)
{ {
throw spdlog_ex("wincolor_sink: write_to_file_ failed. GetLastError(): " + std::to_string(::GetLastError())); SPDLOG_THROW spdlog_ex("wincolor_sink: write_to_file_ failed. GetLastError(): " + std::to_string(::GetLastError()));
} }
total_written += bytes_written; total_written += bytes_written;
} while (total_written < size); } while (total_written < size);
......
...@@ -1074,7 +1074,7 @@ ...@@ -1074,7 +1074,7 @@
}, },
"invocations": [ "invocations": [
{ {
"commandLine": "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.22.27905\\bin\\HostX64\\x64\\c1xx.dll\" -ACf{1F7B090C-16DB-4822-966A-A93D26ED4681} -ACpmspft140.dll -Alint -D_PREFAST_ -D_AST_FE_ -Analyze -zm0x00007FF619B86AB0 -il C:\\Users\\gmelm\\AppData\\Local\\Temp\\_CL_74d41b28ast -typedil -f E:\\devel\\spdlog\\src\\spdlog.cpp -Ze -D_MSC_EXTENSIONS -Zp16 -ZB64 -D_INTEGRAL_MAX_BITS=64 -pc \\:/ -D_MSC_VER=1922 -D_MSC_FULL_VER=192227905 -D_MSC_BUILD=0 -D_M_AMD64=100 -ZILP448 -D_M_X64=100 -D_WIN64 -D_WIN32 -I E:\\devel\\spdlog\\include -nologo -W 4 -WX -diagnostics:column -Ot -DCODE_ANALYSIS -DWIN32 -D_WINDOWS -DSPDLOG_COMPILED_LIB -DCMAKE_INTDIR=\"Debug\" -D_MBCS -EHs -D_CPPUNWIND -EHc -D__MSVC_RUNTIME_CHECKS -RTCs -RTCu -D_DEBUG -D_MT -D_DLL -GS -D_M_FP_PRECISE -Zc:wchar_t -Zc:forScope -GR -D_CPPRTTI -Fospdlog.dir\\Debug\\spdlog.obj -Fdspdlog.dir\\Debug\\spdlog.pdb -Gd -analyze:quiet -analyze:plugin C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.22.27905\\bin\\HostX64\\x64\\EspXEngine.dll -errorreport:prompt -analyze:ruleset C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Team Tools\\Static Analysis Tools\\Rule Sets\\NativeRecommendedRules.ruleset -analyze:projectdirectory E:\\devel\\spdlog\\win64-release -analyze:rulesetdirectory ;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Team Tools\\Static Analysis Tools\\\\Rule Sets -I C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.22.27905\\include -I C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.22.27905\\atlmfc\\include -I C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\VS\\include -I C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17134.0\\ucrt -I C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\VS\\UnitTest\\include -I C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17134.0\\um -I C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17134.0\\shared -I C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17134.0\\winrt -I C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17134.0\\cppwinrt -I C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.7.2\\Include\\um" "commandLine": "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.22.27905\\bin\\HostX64\\x64\\c1xx.dll\" -ACf{1F7B090C-16DB-4822-966A-A93D26ED4681} -ACpmspft140.dll -Alint -D_PREFAST_ -D_AST_FE_ -Analyze -zm0x00007FF619B86AB0 -il C:\\Users\\gmelm\\AppData\\Local\\Temp\\_CL_9a7db7e3ast -typedil -f E:\\devel\\spdlog\\src\\spdlog.cpp -Ze -D_MSC_EXTENSIONS -Zp16 -ZB64 -D_INTEGRAL_MAX_BITS=64 -pc \\:/ -D_MSC_VER=1922 -D_MSC_FULL_VER=192227905 -D_MSC_BUILD=0 -D_M_AMD64=100 -ZILP448 -D_M_X64=100 -D_WIN64 -D_WIN32 -I E:\\devel\\spdlog\\include -nologo -W 4 -WX -diagnostics:column -Ot -DCODE_ANALYSIS -DWIN32 -D_WINDOWS -DSPDLOG_COMPILED_LIB -DCMAKE_INTDIR=\"Debug\" -D_MBCS -EHs -D_CPPUNWIND -EHc -D__MSVC_RUNTIME_CHECKS -RTCs -RTCu -D_DEBUG -D_MT -D_DLL -GS -D_M_FP_PRECISE -Zc:wchar_t -Zc:forScope -GR -D_CPPRTTI -Fospdlog.dir\\Debug\\spdlog.obj -Fdspdlog.dir\\Debug\\spdlog.pdb -Gd -analyze:quiet -analyze:plugin C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.22.27905\\bin\\HostX64\\x64\\EspXEngine.dll -errorreport:prompt -analyze:ruleset C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Team Tools\\Static Analysis Tools\\Rule Sets\\NativeRecommendedRules.ruleset -analyze:projectdirectory E:\\devel\\spdlog\\win64-release -analyze:rulesetdirectory ;C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Team Tools\\Static Analysis Tools\\\\Rule Sets -I C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.22.27905\\include -I C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.22.27905\\atlmfc\\include -I C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\VS\\include -I C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17134.0\\ucrt -I C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\VS\\UnitTest\\include -I C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17134.0\\um -I C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17134.0\\shared -I C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17134.0\\winrt -I C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17134.0\\cppwinrt -I C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.7.2\\Include\\um"
} }
], ],
"files": { "files": {
......
This diff is collapsed.
This diff is collapsed.
# Copyright(c) 2019 spdlog authors
# Distributed under the MIT License (http://opensource.org/licenses/MIT)
find_package(Threads REQUIRED)
set(SPDLOG_FMT_EXTERNAL OFF)
set(config_targets_file spdlogConfigTargets.cmake)
if(SPDLOG_FMT_EXTERNAL)
include(CMakeFindDependencyMacro)
find_dependency(fmt CONFIG)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/${config_targets_file}")
# This is a basic version file for the Config-mode of find_package().
# It is used by write_basic_package_version_file() as input file for configure_file()
# to create a version-file which can be installed along a config.cmake file.
#
# The created file sets PACKAGE_VERSION_EXACT if the current version string and
# the requested version string are exactly the same and it sets
# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version,
# but only if the requested major version is the same as the current one.
# The variable CVF_VERSION must be set before calling configure_file().
set(PACKAGE_VERSION "1.4.0")
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
if("1.4.0" MATCHES "^([0-9]+)\\.")
set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
else()
set(CVF_VERSION_MAJOR "1.4.0")
endif()
if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR)
set(PACKAGE_VERSION_COMPATIBLE TRUE)
else()
set(PACKAGE_VERSION_COMPATIBLE FALSE)
endif()
if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
# if the installed project requested no architecture check, don't perform the check
if("FALSE")
return()
endif()
# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "")
return()
endif()
# check that the installed version has the same 32/64bit-ness as the one which is currently searching:
if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8")
math(EXPR installedBits "8 * 8")
set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
set(PACKAGE_VERSION_UNSUITABLE TRUE)
endif()
# CMake generated Testfile for
# Source directory: E:/devel/spdlog/tests
# Build directory: E:/devel/spdlog/win64-release/tests
#
# This file includes the relevant testing commands required for
# testing this directory and lists subdirectories to be tested as well.
if("${CTEST_CONFIGURATION_TYPE}" MATCHES "^([Dd][Ee][Bb][Uu][Gg])$")
add_test(spdlog-utests "E:/devel/spdlog/win64-release/tests/Debug/spdlog-utests.exe")
set_tests_properties(spdlog-utests PROPERTIES _BACKTRACE_TRIPLES "E:/devel/spdlog/tests/CMakeLists.txt;48;add_test;E:/devel/spdlog/tests/CMakeLists.txt;0;")
elseif("${CTEST_CONFIGURATION_TYPE}" MATCHES "^([Rr][Ee][Ll][Ee][Aa][Ss][Ee])$")
add_test(spdlog-utests "E:/devel/spdlog/win64-release/tests/Release/spdlog-utests.exe")
set_tests_properties(spdlog-utests PROPERTIES _BACKTRACE_TRIPLES "E:/devel/spdlog/tests/CMakeLists.txt;48;add_test;E:/devel/spdlog/tests/CMakeLists.txt;0;")
elseif("${CTEST_CONFIGURATION_TYPE}" MATCHES "^([Mm][Ii][Nn][Ss][Ii][Zz][Ee][Rr][Ee][Ll])$")
add_test(spdlog-utests "E:/devel/spdlog/win64-release/tests/MinSizeRel/spdlog-utests.exe")
set_tests_properties(spdlog-utests PROPERTIES _BACKTRACE_TRIPLES "E:/devel/spdlog/tests/CMakeLists.txt;48;add_test;E:/devel/spdlog/tests/CMakeLists.txt;0;")
elseif("${CTEST_CONFIGURATION_TYPE}" MATCHES "^([Rr][Ee][Ll][Ww][Ii][Tt][Hh][Dd][Ee][Bb][Ii][Nn][Ff][Oo])$")
add_test(spdlog-utests "E:/devel/spdlog/win64-release/tests/RelWithDebInfo/spdlog-utests.exe")
set_tests_properties(spdlog-utests PROPERTIES _BACKTRACE_TRIPLES "E:/devel/spdlog/tests/CMakeLists.txt;48;add_test;E:/devel/spdlog/tests/CMakeLists.txt;0;")
else()
add_test(spdlog-utests NOT_AVAILABLE)
endif()
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