Added support for completely disabling noexcept using MIJIN_TEST_NO_NOEXCEPT (for testing).

This commit is contained in:
2024-08-29 00:01:23 +02:00
parent a43f92fb58
commit 9ba097fc2f
41 changed files with 643 additions and 564 deletions

View File

@@ -9,6 +9,7 @@
#include <string_view>
#include <utility>
#include "../detect.hpp"
#include "../internal/common.hpp"
#include "../types/result.hpp"
namespace mijin
@@ -39,8 +40,8 @@ struct LibraryHandle
{
void* data = nullptr;
constexpr operator bool() const noexcept { return data != nullptr; }
constexpr bool operator!() const noexcept { return data == nullptr; }
constexpr operator bool() const MIJIN_NOEXCEPT { return data != nullptr; }
constexpr bool operator!() const MIJIN_NOEXCEPT { return data == nullptr; }
};
class SharedLibrary
@@ -48,43 +49,43 @@ class SharedLibrary
private:
LibraryHandle mHandle;
public:
SharedLibrary() noexcept = default;
SharedLibrary() MIJIN_NOEXCEPT = default;
SharedLibrary(const SharedLibrary&) = delete;
SharedLibrary(SharedLibrary&& other) noexcept : mHandle(std::exchange(other.mHandle, {})) {}
inline ~SharedLibrary() noexcept;
SharedLibrary(SharedLibrary&& other) MIJIN_NOEXCEPT : mHandle(std::exchange(other.mHandle, {})) {}
inline ~SharedLibrary() MIJIN_NOEXCEPT;
SharedLibrary& operator=(const SharedLibrary&) = delete;
SharedLibrary& operator=(SharedLibrary&& other) noexcept
SharedLibrary& operator=(SharedLibrary&& other) MIJIN_NOEXCEPT
{
mHandle = std::exchange(other.mHandle, {});
return *this;
}
constexpr operator bool() const noexcept { return static_cast<bool>(mHandle); }
constexpr bool operator!() const noexcept { return !mHandle; }
constexpr operator bool() const MIJIN_NOEXCEPT { return static_cast<bool>(mHandle); }
constexpr bool operator!() const MIJIN_NOEXCEPT { return !mHandle; }
[[nodiscard]] inline Result<bool> open(std::string_view libraryFile) noexcept;
inline bool close() noexcept;
[[nodiscard]] inline void* loadSymbol(const char* symbolName) noexcept;
[[nodiscard]] inline Result<bool> open(std::string_view libraryFile) MIJIN_NOEXCEPT;
inline bool close() MIJIN_NOEXCEPT;
[[nodiscard]] inline void* loadSymbol(const char* symbolName) MIJIN_NOEXCEPT;
};
//
// public functions
//
[[nodiscard]] Result<LibraryHandle> openSharedLibrary(std::string_view libraryFile) noexcept;
bool closeSharedLibrary(const LibraryHandle library) noexcept;
[[nodiscard]] void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) noexcept;
void setCurrentThreadName(const char* threadName) noexcept;
[[nodiscard]] Result<LibraryHandle> openSharedLibrary(std::string_view libraryFile) MIJIN_NOEXCEPT;
bool closeSharedLibrary(const LibraryHandle library) MIJIN_NOEXCEPT;
[[nodiscard]] void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) MIJIN_NOEXCEPT;
void setCurrentThreadName(const char* threadName) MIJIN_NOEXCEPT;
[[nodiscard]] std::string makeLibraryFilename(std::string_view libraryName) noexcept;
[[nodiscard]] std::string makeLibraryFilename(std::string_view libraryName) MIJIN_NOEXCEPT;
SharedLibrary::~SharedLibrary() noexcept
SharedLibrary::~SharedLibrary() MIJIN_NOEXCEPT
{
close();
}
Result<bool> SharedLibrary::open(std::string_view libraryFile) noexcept
Result<bool> SharedLibrary::open(std::string_view libraryFile) MIJIN_NOEXCEPT
{
close();
Result<LibraryHandle> openResult = openSharedLibrary(libraryFile);
@@ -96,7 +97,7 @@ Result<bool> SharedLibrary::open(std::string_view libraryFile) noexcept
return ResultError(openResult.getError());
}
bool SharedLibrary::close() noexcept
bool SharedLibrary::close() MIJIN_NOEXCEPT
{
if (mHandle)
{
@@ -105,7 +106,7 @@ bool SharedLibrary::close() noexcept
return false;
}
void* SharedLibrary::loadSymbol(const char* symbolName) noexcept
void* SharedLibrary::loadSymbol(const char* symbolName) MIJIN_NOEXCEPT
{
return loadSymbolFromLibrary(mHandle, symbolName);
}