Skip to content

Commit

Permalink
Fix up C functions to never throw.
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <[email protected]>
  • Loading branch information
hidmic committed Sep 29, 2020
1 parent 488698f commit 6ad410c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
20 changes: 13 additions & 7 deletions rmw_implementation/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ get_library()
}

void *
lookup_symbol(std::shared_ptr<rcpputils::SharedLibrary> lib, const char * symbol_name)
lookup_symbol(std::shared_ptr<rcpputils::SharedLibrary> lib, const std::string & symbol_name)
{
if (!lib) {
if (!rmw_error_is_set()) {
Expand All @@ -110,22 +110,28 @@ lookup_symbol(std::shared_ptr<rcpputils::SharedLibrary> lib, const char * symbol
std::string library_path = lib->get_library_path();
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING(
"failed to resolve symbol '%s' in shared library '%s'",
symbol_name, library_path.c_str());
} catch (const std::runtime_error &) {
symbol_name.c_str(), library_path.c_str());
} catch (const std::exception & e) {
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING(
"failed to resolve symbol '%s' in shared library",
symbol_name);
"failed to resolve symbol '%s' in shared library due to %s",
symbol_name.c_str(), e.what());
}
return nullptr;
}

return lib->get_symbol(symbol_name);
}

void *
get_symbol(const char * symbol_name)
{
return lookup_symbol(get_library(), symbol_name);
try {
return lookup_symbol(get_library(), symbol_name);
} catch (const std::exception & e) {
RMW_SET_ERROR_MSG_WITH_FORMAT_STRING(
"failed to get symbol '%s' due to %s",
symbol_name, e.what());
return nullptr;
}
}

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion rmw_implementation/src/functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RMW_IMPLEMENTATION_DEFAULT_VISIBILITY
std::shared_ptr<rcpputils::SharedLibrary> load_library();

RMW_IMPLEMENTATION_DEFAULT_VISIBILITY
void * lookup_symbol(std::shared_ptr<rcpputils::SharedLibrary> lib, const char * symbol_name);
void * lookup_symbol(std::shared_ptr<rcpputils::SharedLibrary> lib, const std::string & symbol_name);

#ifdef __cplusplus
extern "C"
Expand Down

0 comments on commit 6ad410c

Please sign in to comment.