From 6b316e64bebfd60d95171c6700f1c2bf9f4ea3e0 Mon Sep 17 00:00:00 2001 From: "Mads R. B. Kristensen" Date: Wed, 5 Feb 2025 12:48:46 +0100 Subject: [PATCH] Use std::string (#617) Minor maintenance Authors: - Mads R. B. Kristensen (https://github.com/madsbk) Approvers: - https://github.com/jakirkham URL: https://github.com/rapidsai/kvikio/pull/617 --- cpp/include/kvikio/shim/utils.hpp | 9 +++++---- cpp/src/shim/utils.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/cpp/include/kvikio/shim/utils.hpp b/cpp/include/kvikio/shim/utils.hpp index 52dfea42e8..1824d61ce4 100644 --- a/cpp/include/kvikio/shim/utils.hpp +++ b/cpp/include/kvikio/shim/utils.hpp @@ -17,6 +17,7 @@ #include #include +#include #include namespace kvikio { @@ -44,7 +45,7 @@ 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 @@ -52,7 +53,7 @@ void* load_library(const char* name, int mode = RTLD_LAZY | RTLD_LOCAL | RTLD_NO * @param names Vector of names to try when loading shared library. * @return The library handle. */ -void* load_library(const std::vector& names, +void* load_library(std::vector const& names, int mode = RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE); /** @@ -64,11 +65,11 @@ void* load_library(const std::vector& names, * @param name Name of the symbol/function to load. */ template -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(::dlsym(lib, name)); + handle = reinterpret_cast(::dlsym(lib, name.c_str())); const char* err = ::dlerror(); if (err != nullptr) { throw std::runtime_error(err); } } diff --git a/cpp/src/shim/utils.cpp b/cpp/src/shim/utils.cpp index de7ec6a875..066b4259d8 100644 --- a/cpp/src/shim/utils.cpp +++ b/cpp/src/shim/utils.cpp @@ -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& names, int mode) +void* load_library(std::vector 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);