Skip to content

Commit

Permalink
symbols: m_fd is now only needed on macos
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Olivier <[email protected]>
  • Loading branch information
martin-olivier committed Jan 6, 2025
1 parent 6e9ca66 commit 4d09beb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/dylib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class library {

protected:
native_handle_type m_handle{nullptr};
#if !defined(_WIN32)
#if defined(__APPLE__)
int m_fd{-1};
#endif
};
Expand Down
10 changes: 5 additions & 5 deletions src/dylib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ static std::string get_error_description() noexcept {

library::library(library &&other) noexcept {
std::swap(m_handle, other.m_handle);
#if !defined(_WIN32)
#if defined(__APPLE__)
std::swap(m_fd, other.m_fd);
#endif
}

library &library::operator=(library &&other) noexcept {
if (this != &other) {
std::swap(m_handle, other.m_handle);
#if !defined(_WIN32)
#if defined(__APPLE__)
std::swap(m_fd, other.m_fd);
#endif
}
Expand Down Expand Up @@ -120,7 +120,7 @@ library::library(const char *lib_path, dylib::decorations decorations) {
if (!m_handle)
throw load_error("Could not load library '" + lib + "'\n" + get_error_description());

#if !defined(_WIN32)
#if defined(__APPLE__)
m_fd = open(lib.c_str(), O_RDONLY);
if (m_fd < 0)
throw load_error("Could not open file '" + lib + "': " + strerror(errno));
Expand All @@ -138,7 +138,7 @@ library::library(const std::filesystem::path &lib_path, decorations decorations)
library::~library() {
if (m_handle)
close_lib(m_handle);
#if !defined(_WIN32)
#if defined(__APPLE__)
if (m_fd > -1)
close(m_fd);
#endif
Expand Down Expand Up @@ -213,7 +213,7 @@ std::vector<std::string> library::symbols(symbol_params params) const {
try {
return get_symbols(
m_handle,
DYLIB_WIN_OTHER(-1, m_fd),
DYLIB_WIN_MAC_OTHER(-1, m_fd, -1),
params.demangle,
params.loadable
);
Expand Down
4 changes: 3 additions & 1 deletion src/symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ std::vector<std::string> get_symbols(HMODULE handle, int fd, bool demangle, bool
#include <mach-o/nlist.h>
#include <mach-o/fat.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <unistd.h>
#include <utility>

Expand Down Expand Up @@ -243,6 +242,9 @@ std::vector<std::string> get_symbols(void *handle, int fd, bool demangle, bool l
symentries = section->d_un.d_val;
}

if (!symtab || !strtab || symentries == 0)
return result;

size = strtab - (char *)symtab;

for (int i = 0; i < size / symentries; ++i) {
Expand Down

0 comments on commit 4d09beb

Please sign in to comment.