Update to LibConf system, added loading of dynamic libraries (only Linux for now) and some more fixes.
This commit is contained in:
parent
da781b87f2
commit
920e83d4da
29
LibConf
Normal file
29
LibConf
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
Import('env')
|
||||||
|
|
||||||
|
mijin_sources = Split("""
|
||||||
|
source/mijin/async/coroutine.cpp
|
||||||
|
source/mijin/debug/symbol_info.cpp
|
||||||
|
source/mijin/io/stream.cpp
|
||||||
|
source/mijin/memory/data_pool.cpp
|
||||||
|
source/mijin/util/os.cpp
|
||||||
|
source/mijin/types/name.cpp
|
||||||
|
source/mijin/virtual_filesystem/filesystem.cpp
|
||||||
|
source/mijin/virtual_filesystem/stacked.cpp
|
||||||
|
""")
|
||||||
|
|
||||||
|
env.UnityStaticLibrary(
|
||||||
|
target = env['LIB_DIR'] + '/mijin_sekiei',
|
||||||
|
source = mijin_sources
|
||||||
|
)
|
||||||
|
|
||||||
|
LIB_CONFIG = {
|
||||||
|
'CPPPATH': [env.Dir('source')],
|
||||||
|
'CPPDEFINES': [],
|
||||||
|
'LIBS': ['mijin_sekiei']
|
||||||
|
}
|
||||||
|
|
||||||
|
if env['BUILD_TYPE'] == 'debug':
|
||||||
|
LIB_CONFIG['CPPDEFINES'].extend(['MIJIN_DEBUG=1', 'MIJIN_CHECKED_ITERATORS=1'])
|
||||||
|
|
||||||
|
Return('LIB_CONFIG')
|
@ -1,24 +0,0 @@
|
|||||||
|
|
||||||
Import('env')
|
|
||||||
|
|
||||||
mijin_sources = Split("""
|
|
||||||
async/coroutine.cpp
|
|
||||||
debug/symbol_info.cpp
|
|
||||||
io/stream.cpp
|
|
||||||
memory/data_pool.cpp
|
|
||||||
util/os.cpp
|
|
||||||
types/name.cpp
|
|
||||||
virtual_filesystem/filesystem.cpp
|
|
||||||
virtual_filesystem/stacked.cpp
|
|
||||||
""")
|
|
||||||
|
|
||||||
env.UnityStaticLibrary(
|
|
||||||
target = env['LIB_DIR'] + '/mijin_sekiei',
|
|
||||||
source = mijin_sources
|
|
||||||
)
|
|
||||||
|
|
||||||
LIB_CONFIG = {
|
|
||||||
'LIBS': ['mijin_sekiei']
|
|
||||||
}
|
|
||||||
|
|
||||||
Return('LIB_CONFIG')
|
|
@ -110,7 +110,7 @@ inline void Signal<TArgs...>::emit(TArgs&&... args) noexcept
|
|||||||
// invoke all handlers
|
// invoke all handlers
|
||||||
for (RegisteredHandler& handler : handlers_)
|
for (RegisteredHandler& handler : handlers_)
|
||||||
{
|
{
|
||||||
handler.callable(forward<TArgs>(args)...);
|
handler.callable(std::forward<TArgs>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove any oneshot
|
// remove any oneshot
|
||||||
|
@ -52,7 +52,7 @@ public:
|
|||||||
#if MIJIN_BOXED_OBJECT_DEBUG
|
#if MIJIN_BOXED_OBJECT_DEBUG
|
||||||
~BoxedObject()
|
~BoxedObject()
|
||||||
{
|
{
|
||||||
MIJIN_ASSERT(!constructed, "BoxedObject::~BoxedObject(): Object has not been destroy prior to destructor!")
|
MIJIN_ASSERT(!constructed, "BoxedObject::~BoxedObject(): Object has not been destroyed prior to destructor!")
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ template<typename T>
|
|||||||
T& BoxedObjectIterator<T>::operator*() const
|
T& BoxedObjectIterator<T>::operator*() const
|
||||||
{
|
{
|
||||||
#if MIJIN_CHECKED_ITERATORS
|
#if MIJIN_CHECKED_ITERATORS
|
||||||
MIJIN_ASSERT(box_ >= start_ && box < end_, "BoxedObjectIterator::operator->(): Attempt to dereference out-of-range iterator.");
|
MIJIN_ASSERT(box_ >= start_ && box_ < end_, "BoxedObjectIterator::operator->(): Attempt to dereference out-of-range iterator.");
|
||||||
#endif
|
#endif
|
||||||
return box_->get();
|
return box_->get();
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,7 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <source_location>
|
||||||
namespace mijin
|
|
||||||
{
|
|
||||||
|
|
||||||
//
|
|
||||||
// public defines
|
|
||||||
//
|
|
||||||
|
|
||||||
#if MIJIN_DEBUG
|
#if MIJIN_DEBUG
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -25,23 +19,33 @@ extern "C" __declspec(dllimport) void __stdcall DebugBreak();
|
|||||||
#define MIJIN_TRAP() raise(SIGTRAP)
|
#define MIJIN_TRAP() raise(SIGTRAP)
|
||||||
#define MIJIN_FUNC() "" // TODO: __PRETTY_FUNCTION__ is not working for some reason -.-
|
#define MIJIN_FUNC() "" // TODO: __PRETTY_FUNCTION__ is not working for some reason -.-
|
||||||
#endif // !_WIN32
|
#endif // !_WIN32
|
||||||
|
#endif // MIJIN_DEBUG
|
||||||
|
|
||||||
#define MIJIN_DO_RAISE_ERROR(msg, func, file, line) \
|
namespace mijin
|
||||||
switch (mijin::handleError(msg, func, file, line)) \
|
{
|
||||||
{ \
|
|
||||||
case mijin::ErrorHandling::CONTINUE: \
|
//
|
||||||
break; \
|
// public defines
|
||||||
case mijin::ErrorHandling::TRAP: \
|
//
|
||||||
MIJIN_TRAP(); \
|
|
||||||
[[fallthrough]]; \
|
#if MIJIN_DEBUG
|
||||||
default: /* ABORT */ \
|
|
||||||
std::abort(); \
|
#define MIJIN_DO_RAISE_ERROR(msg, source_loc) \
|
||||||
|
switch (mijin::handleError(msg, source_loc)) \
|
||||||
|
{ \
|
||||||
|
case mijin::ErrorHandling::CONTINUE: \
|
||||||
|
break; \
|
||||||
|
case mijin::ErrorHandling::TRAP: \
|
||||||
|
MIJIN_TRAP(); \
|
||||||
|
[[fallthrough]]; \
|
||||||
|
default: /* ABORT */ \
|
||||||
|
std::abort(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MIJIN_RAISE_ERROR(msg, func, file, line) MIJIN_DO_RAISE_ERROR(msg, func, file, line)
|
#define MIJIN_RAISE_ERROR(msg, func, file, line) MIJIN_DO_RAISE_ERROR(msg, func, file, line)
|
||||||
|
|
||||||
#define MIJIN_ERROR(msg) \
|
#define MIJIN_ERROR(msg) \
|
||||||
MIJIN_RAISE_ERROR(msg, MIJIN_FUNC(), __FILE__, __LINE__)
|
MIJIN_DO_RAISE_ERROR(msg, std::source_location::current())
|
||||||
|
|
||||||
#define MIJIN_FATAL(msg) \
|
#define MIJIN_FATAL(msg) \
|
||||||
MIJIN_ERROR(msg) \
|
MIJIN_ERROR(msg) \
|
||||||
@ -129,13 +133,11 @@ constexpr AssertionResult handleAssert(const char* /* condition */,
|
|||||||
ErrorHandling handleError(const char* message, const char* function,
|
ErrorHandling handleError(const char* message, const char* function,
|
||||||
const char* file, int line) noexcept;
|
const char* file, int line) noexcept;
|
||||||
#else
|
#else
|
||||||
inline ErrorHandling handleError(const char* message, const char* function,
|
inline ErrorHandling handleError(const char* message, const std::source_location& location) noexcept
|
||||||
const char* file, int line) noexcept
|
|
||||||
{
|
{
|
||||||
std::puts(message);
|
std::puts(message);
|
||||||
std::printf("Function: %s\n", function);
|
std::printf("Function: %s\n", location.function_name());
|
||||||
std::printf("File: %s\n", file);
|
std::printf("Location: %s:%d:%d\n", location.file_name(), location.line(), location.column());
|
||||||
std::printf("Line: %d\n", line);
|
|
||||||
(void) std::fflush(stdout);
|
(void) std::fflush(stdout);
|
||||||
return ErrorHandling::TRAP;
|
return ErrorHandling::TRAP;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
|
|
||||||
#include "os.hpp"
|
#include "os.hpp"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
#include "../detect.hpp"
|
#include "../detect.hpp"
|
||||||
|
|
||||||
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||||
|
#include <dlfcn.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||||
// TODO
|
// TODO
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
namespace mijin
|
namespace mijin
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -36,7 +40,24 @@ namespace mijin
|
|||||||
// public functions
|
// public functions
|
||||||
//
|
//
|
||||||
|
|
||||||
void setCurrentThreadName(const char* threadName)
|
LibraryHandle openSharedLibrary(std::string_view libraryFile) noexcept
|
||||||
|
{
|
||||||
|
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||||
|
const fs::path libraryPath = fs::absolute(libraryFile);
|
||||||
|
return {.data = dlopen(libraryPath.c_str(), RTLD_NOW)};
|
||||||
|
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) noexcept
|
||||||
|
{
|
||||||
|
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||||
|
return dlsym(library.data, symbolName);
|
||||||
|
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCurrentThreadName(const char* threadName) noexcept
|
||||||
{
|
{
|
||||||
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||||
pthread_setname_np(pthread_self(), threadName);
|
pthread_setname_np(pthread_self(), threadName);
|
||||||
@ -44,4 +65,15 @@ void setCurrentThreadName(const char* threadName)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] std::string makeLibraryFilename(std::string_view libraryName) noexcept
|
||||||
|
{
|
||||||
|
#if MIJIN_TARGET_OS == MIJIN_OS_LINUX
|
||||||
|
return "lib" + std::string(libraryName) + ".so";
|
||||||
|
#elif MIJIN_TARGET_OS == MIJIN_OS_WINDOWS
|
||||||
|
return std::string(libraryName) + ".dll";
|
||||||
|
#else
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mijin
|
} // namespace mijin
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
#if !defined(MIJIN_UTIL_OS_HPP_INCLUDED)
|
#if !defined(MIJIN_UTIL_OS_HPP_INCLUDED)
|
||||||
#define MIJIN_UTIL_OS_HPP_INCLUDED 1
|
#define MIJIN_UTIL_OS_HPP_INCLUDED 1
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
namespace mijin
|
namespace mijin
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -19,11 +22,23 @@ namespace mijin
|
|||||||
// public types
|
// public types
|
||||||
//
|
//
|
||||||
|
|
||||||
|
struct LibraryHandle
|
||||||
|
{
|
||||||
|
void* data = nullptr;
|
||||||
|
|
||||||
|
constexpr operator bool() const noexcept { return data != nullptr; }
|
||||||
|
constexpr bool operator!() const noexcept { return data == nullptr; }
|
||||||
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// public functions
|
// public functions
|
||||||
//
|
//
|
||||||
|
|
||||||
void setCurrentThreadName(const char* threadName);
|
[[nodiscard]] LibraryHandle openSharedLibrary(std::string_view libraryFile) noexcept;
|
||||||
|
[[nodiscard]] void* loadSymbolFromLibrary(const LibraryHandle library, const char* symbolName) noexcept;
|
||||||
|
void setCurrentThreadName(const char* threadName) noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]] std::string makeLibraryFilename(std::string_view libraryName) noexcept;
|
||||||
|
|
||||||
} // namespace mijin
|
} // namespace mijin
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user