Skip to content

Commit

Permalink
Defer path resolution of rosidl typesupport libraries to dynamic link…
Browse files Browse the repository at this point in the history
…er. (#98)

Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic committed Dec 22, 2020
1 parent e513ffb commit 64dd1be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 32 deletions.
25 changes: 9 additions & 16 deletions rosidl_typesupport_c/src/type_support_dispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <stdexcept>
#include <string>

#include "rcpputils/find_library.hpp"
#include "rcpputils/shared_library.hpp"
#include "rcutils/error_handling.h"
#include "rcutils/snprintf.h"
Expand Down Expand Up @@ -54,40 +53,34 @@ get_typesupport_handle_function(
rcpputils::SharedLibrary * lib = nullptr;

if (!map->data[i]) {
char library_name[1024];
char library_basename[1024];
int ret = rcutils_snprintf(
library_name, 1023, "%s__%s",
library_basename, 1023, "%s__%s",
map->package_name, identifier);
if (ret < 0) {
RCUTILS_SET_ERROR_MSG("Failed to format library name");
return nullptr;
}

std::string library_path;
std::string library_name;
try {
library_path = rcpputils::find_library_path(library_name);
library_name = rcpputils::get_platform_library_name(library_basename);
} catch (const std::exception & e) {
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Failed to find library '%s' due to %s",
library_name, e.what());
return nullptr;
}

if (library_path.empty()) {
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Failed to find library '%s'", library_name);
"Failed to compute library name for '%s' due to %s",
library_basename, e.what());
return nullptr;
}

try {
lib = new rcpputils::SharedLibrary(library_path.c_str());
lib = new rcpputils::SharedLibrary(library_name);
} catch (const std::runtime_error & e) {
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Could not load library %s: %s", library_path.c_str(), e.what());
"Could not load library %s: %s", library_name.c_str(), e.what());
return nullptr;
} catch (const std::bad_alloc & e) {
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Could not load library %s: %s", library_path.c_str(), e.what());
"Could not load library %s: %s", library_name.c_str(), e.what());
return nullptr;
}
map->data[i] = lib;
Expand Down
25 changes: 9 additions & 16 deletions rosidl_typesupport_cpp/src/type_support_dispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <stdexcept>
#include <string>

#include "rcpputils/find_library.hpp"
#include "rcpputils/shared_library.hpp"
#include "rcutils/error_handling.h"
#include "rcutils/snprintf.h"
Expand Down Expand Up @@ -52,40 +51,34 @@ get_typesupport_handle_function(
rcpputils::SharedLibrary * lib = nullptr;

if (!map->data[i]) {
char library_name[1024];
char library_basename[1024];
int ret = rcutils_snprintf(
library_name, 1023, "%s__%s",
library_basename, 1023, "%s__%s",
map->package_name, identifier);
if (ret < 0) {
RCUTILS_SET_ERROR_MSG("Failed to format library name");
return nullptr;
}

std::string library_path;
std::string library_name;
try {
library_path = rcpputils::find_library_path(library_name);
library_name = rcpputils::get_platform_library_name(library_basename);
} catch (const std::runtime_error & e) {
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Failed to find library '%s' due to %s",
library_name, e.what());
return nullptr;
}

if (library_path.empty()) {
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Failed to find library '%s'", library_name);
"Failed to compute library name for '%s' due to %s",
library_basename, e.what());
return nullptr;
}

try {
lib = new rcpputils::SharedLibrary(library_path.c_str());
lib = new rcpputils::SharedLibrary(library_name);
} catch (const std::runtime_error & e) {
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Could not load library %s: %s", library_name, e.what());
"Could not load library %s: %s", library_name.c_str(), e.what());
return nullptr;
} catch (const std::bad_alloc & e) {
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(
"Could not load library %s: %s", library_name, e.what());
"Could not load library %s: %s", library_name.c_str(), e.what());
return nullptr;
}
map->data[i] = lib;
Expand Down

0 comments on commit 64dd1be

Please sign in to comment.