Skip to content

Commit

Permalink
Use std::string (#617)
Browse files Browse the repository at this point in the history
Minor maintenance

Authors:
  - Mads R. B. Kristensen (https://github.com/madsbk)

Approvers:
  - https://github.com/jakirkham

URL: #617
  • Loading branch information
madsbk authored Feb 5, 2025
1 parent 74653a3 commit 6b316e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions cpp/include/kvikio/shim/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <dlfcn.h>
#include <sys/utsname.h>
#include <string>
#include <vector>

namespace kvikio {
Expand Down Expand Up @@ -44,15 +45,15 @@ namespace kvikio {
* @param name Name of the library to load.
* @return The library handle.
*/
void* load_library(const char* name, int mode = RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE);
void* load_library(std::string const& name, int mode = RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE);

/**
* @brief Load shared library
*
* @param names Vector of names to try when loading shared library.
* @return The library handle.
*/
void* load_library(const std::vector<const char*>& names,
void* load_library(std::vector<std::string> const& names,
int mode = RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE);

/**
Expand All @@ -64,11 +65,11 @@ void* load_library(const std::vector<const char*>& names,
* @param name Name of the symbol/function to load.
*/
template <typename T>
void get_symbol(T& handle, void* lib, const char* name)
void get_symbol(T& handle, void* lib, std::string const& name)
{
::dlerror(); // Clear old errors
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
handle = reinterpret_cast<T>(::dlsym(lib, name));
handle = reinterpret_cast<T>(::dlsym(lib, name.c_str()));
const char* err = ::dlerror();
if (err != nullptr) { throw std::runtime_error(err); }
}
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/shim/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@

namespace kvikio {

void* load_library(const char* name, int mode)
void* load_library(std::string const& name, int mode)
{
::dlerror(); // Clear old errors
void* ret = ::dlopen(name, mode);
void* ret = ::dlopen(name.c_str(), mode);
if (ret == nullptr) { throw std::runtime_error(::dlerror()); }
return ret;
}

void* load_library(const std::vector<const char*>& names, int mode)
void* load_library(std::vector<std::string> const& names, int mode)
{
std::stringstream ss;
for (const char* name : names) {
for (auto const& name : names) {
ss << name << " ";
try {
return load_library(name, mode);
Expand Down

0 comments on commit 6b316e6

Please sign in to comment.