From 1676160fbebe08f568f8758837345c52bf4ff84f Mon Sep 17 00:00:00 2001 From: David Rebbe <1187684+ic3man5@users.noreply.github.com> Date: Wed, 3 Jul 2024 00:32:41 -0400 Subject: [PATCH] Fixed compiler warnings and linux ordinal values. --- CMakeLists.txt | 8 ++++++++ include/ice/ice_function.h | 16 ++++------------ include/ice/ice_library.h | 2 +- include/ice/ice_library_name.h | 6 +++--- src/ice_library.cpp | 3 +-- src/ice_library_name.cpp | 8 +++++--- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7921eab..a6ba0bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,14 @@ project(ice VERSION 1.1.0 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +if (MSVC) + # warning level 4 + add_compile_options(/W4) +else() + # additional warnings + add_compile_options(-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wfloat-equal) +endif() + add_library(ice STATIC src/ice_library.cpp src/ice_library_manager.cpp diff --git a/include/ice/ice_function.h b/include/ice/ice_function.h index 2bac1b3..ef78c6b 100644 --- a/include/ice/ice_function.h +++ b/include/ice/ice_function.h @@ -43,11 +43,6 @@ template class ice::Function { Function(ice::Library *library, unsigned int ordinal) : m_name(__ordinalToString(ordinal)) { - /* - std::stringstream temp; - temp << "Ordinal " << ordinal; - m_name = temp.str().c_str(); - */ // Make sure the ordinal fits inside the lower word (16-bit) if (ordinal > 0xFFFF) { std::stringstream ss; @@ -70,13 +65,10 @@ template class ice::Function { throw ice::Exception(err.str()); } #else - m_func = reinterpret_cast(dlsym(library->_library(), (const char *)ordinal)); - if (m_func == NULL) { - std::stringstream err; - err << "Failed to Retrieve address of function '" << m_name << "': " << dlerror() << " for library '" - << library->name() << "'"; - throw ice::Exception(err.str()); - } + std::stringstream err; + err << "Ordinal values are not supported on linux for library '" + << library->name() << "'"; + throw ice::Exception(err.str()); #endif } operator Signature *() const diff --git a/include/ice/ice_library.h b/include/ice/ice_library.h index 5ad3e02..e21f7cf 100644 --- a/include/ice/ice_library.h +++ b/include/ice/ice_library.h @@ -33,7 +33,7 @@ class ice::Library { std::string name() const { return m_name; } std::string getPath(bool *okay = NULL); - const bool hasError() const; + bool hasError() const; const std::string getLastError() const; HMODULE const &_library() const; diff --git a/include/ice/ice_library_name.h b/include/ice/ice_library_name.h index 262e5c5..c0a190e 100644 --- a/include/ice/ice_library_name.h +++ b/include/ice/ice_library_name.h @@ -45,14 +45,14 @@ class ice::LibraryName // Adds the "lib" prefix to the library name for dlopen/LoadLibrary calls LibraryName& setLibPrefix(LibPrefix lib_prefix); - const LibPrefix getLibPrefix() const; + LibPrefix getLibPrefix() const; // Prepends "${ORIGIN}/" or "@loader_path/" prefix LibraryName& setPathPrefix(PathPrefix path_prefix); - const PathPrefix getPathPrefix() const; + PathPrefix getPathPrefix() const; LibraryName& setExtensionEnabled(bool use_extension); - const bool getExtensionEnabled() const; + bool getExtensionEnabled() const; LibraryName& setExtension(const std::string extension); LibraryName& setDefaultExtension(); const std::string getExtension() const; diff --git a/src/ice_library.cpp b/src/ice_library.cpp index 7f10436..d714e39 100644 --- a/src/ice_library.cpp +++ b/src/ice_library.cpp @@ -154,7 +154,6 @@ std::string Library::getPath(bool* okay) } #else link_map* lm; - char path[PATH_MAX + 1] = {}; bool success = dlinfo(m_lib, RTLD_DI_LINKMAP, &lm) != -1; if (okay) { *okay = success; @@ -173,7 +172,7 @@ std::string Library::getPath(bool* okay) return m_name; } -const bool Library::hasError() const +bool Library::hasError() const { return m_has_error; } diff --git a/src/ice_library_name.cpp b/src/ice_library_name.cpp index acca0ec..9a689fb 100644 --- a/src/ice_library_name.cpp +++ b/src/ice_library_name.cpp @@ -19,20 +19,22 @@ std::string LibraryName::name() const LibraryName& LibraryName::setLibPrefix(LibPrefix lib_prefix) { + m_lib_prefix = lib_prefix; return *this; } -const LibPrefix LibraryName::getLibPrefix() const +LibPrefix LibraryName::getLibPrefix() const { return m_lib_prefix; } LibraryName& LibraryName::setPathPrefix(PathPrefix path_prefix) { + m_path_prefix = path_prefix; return *this; } -const PathPrefix LibraryName::getPathPrefix() const +PathPrefix LibraryName::getPathPrefix() const { return m_path_prefix; } @@ -55,7 +57,7 @@ LibraryName& LibraryName::setDefaultExtension() return *this; } -const bool LibraryName::getExtensionEnabled() const +bool LibraryName::getExtensionEnabled() const { return m_use_extension; }