Skip to content

Commit

Permalink
context: string_view
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Dec 26, 2024
1 parent fda96ea commit 1e7ff47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion library/public/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class F3D_EXPORT context
* For example, `getSymbol("EGL", "eglGetProcAddress")` looks for the symbol
* `eglGetProcAddress` in the library `libEGL.so` on Linux.
*/
[[nodiscard]] static function getSymbol(const std::string& lib, const std::string& func);
[[nodiscard]] static function getSymbol(std::string_view lib, std::string_view func);

/**
* An exception that can be thrown when the requested library cannot be loaded.
Expand Down
9 changes: 5 additions & 4 deletions library/src/context.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace f3d
{
//----------------------------------------------------------------------------
context::function context::getSymbol(const std::string& lib, const std::string& func)
context::function context::getSymbol(std::string_view lib, std::string_view func)
{
std::string libName = vtksys::DynamicLoader::LibPrefix();
libName += lib;
Expand All @@ -26,16 +26,17 @@ context::function context::getSymbol(const std::string& lib, const std::string&

if (!handle)
{
throw context::loading_exception("Cannot find " + lib + " library");
throw context::loading_exception("Cannot find " + std::string(lib) + " library");
}

using symbol = context::fptr (*)(const char*);

symbol address = reinterpret_cast<symbol>(vtksys::DynamicLoader::GetSymbolAddress(handle, func));
symbol address =
reinterpret_cast<symbol>(vtksys::DynamicLoader::GetSymbolAddress(handle, func.data()));

if (!address)
{
throw context::symbol_exception("Cannot find " + func + " symbol");
throw context::symbol_exception("Cannot find " + std::string(func) + " symbol");
}

return address;
Expand Down

0 comments on commit 1e7ff47

Please sign in to comment.