Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer path resolution of rosidl typesupport libraries to dynamic linker. #98

Merged
merged 1 commit into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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