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

Remove rethrow in extern c code #82

Merged
merged 2 commits into from
Aug 19, 2020
Merged

Conversation

brawner
Copy link
Contributor

@brawner brawner commented Aug 14, 2020

rosidl_typesupport_c code had some rethrown exceptions which were inside extern c functions. I believe, but not entirely sure, this is not recommended since there is no way for the C code to handle them and they would otherwise be fatal errors. MSVC's optimizer was also treating this code strangely when I tried to catch the exception from a c++ test and would get different results by adding unrelated changes.

Example failure with fault injection test:

  • Windows Build Status

Signed-off-by: Stephen Brawner brawner@gmail.com

@brawner
Copy link
Contributor Author

brawner commented Aug 14, 2020

Testing --packages-select rosidl_typesupport_c. These tests would not reproduce the failure since they don't include the fault injection test.

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@brawner brawner requested a review from ahcorde August 14, 2020 00:23
Signed-off-by: Stephen Brawner <brawner@gmail.com>

squash! Remove rethrow in extern c code
@brawner
Copy link
Contributor Author

brawner commented Aug 14, 2020

Err, fprintf requires const char *

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Builds with fault injection:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@dirk-thomas
Copy link
Member

dirk-thomas commented Aug 14, 2020

@ros-pull-request-builder retest this please (using custom job config from ros-infrastructure/ros_buildfarm#828)

@brawner
Copy link
Contributor Author

brawner commented Aug 14, 2020

Windows build warning on fault injection jobs is unrelated to this PR (rcl_action).

throw std::runtime_error(
"Could not load library " + library_path + ": " +
std::string(e.what()));
fprintf(stderr, "Could not load library %s: %s\n", library_path.c_str(), e.what());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to set the error message with something like RCUTILS_SET_ERROR_MSG?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makes sense. It does add a direct dependency to rcutils, but it already indirectly depended on rcutils anyway. I converted these fprintf statements, converted one previously existing one and added an error message for the other nullptr case. This causes the API to diverge a small amount from the rosidl_typesupport_cpp version, so if you like this change I can create a similar PR for that package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes the API to diverge a small amount from the rosidl_typesupport_cpp version

Since the C++ API can leverage exceptions for this kind of error reporting I would think it could stay as it is.

Does any existing code need to be updated to check / reset the error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not that familiar with the use of this package, so you might have to give me a couple of pointers. The only location this function is used in this package is in the .em files. (https://github.com/ros2/rosidl_typesupport/blob/master/rosidl_typesupport_c/resource/msg__type_support.cpp.em#L98), but I'm not sure where that function is called in ROS 2 as I can only find other instances inside .em files.

Is there something better I can be searching for to answer that question?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any specific location in mind. Just searching for code which calls the API would be the only suggestion I have.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked through the code, searching for:

  • rosidl_typesupport_c__get_message_typesupport_handle_function
  • ROSIDL_TYPESUPPORT_INTERFACE__MESSAGE_SYMBOL_NAME
  • ROSIDL_GET_MSG_TYPE_SUPPORT
  • ROSIDL_GET_SRV_TYPE_SUPPORT

The first two are ultimately just used in the last two macros as far as I can tell. The last two are used extensively, but just in test files where they are checked for a nullptr and expected to succeed. If they don't, generally the test fails immediately, but there might be possibilities that the error message gets overwritten if the nullptr is passed to a subsequent function.

It's possible I may be missing something, but I'll be happy to address issues in followup PRs if they come up.

Signed-off-by: Stephen Brawner <brawner@gmail.com>
@brawner brawner merged commit 8e99477 into master Aug 19, 2020
@brawner brawner deleted the brawner/catch-exceptions-extern-c branch August 19, 2020 21:44
ahcorde pushed a commit that referenced this pull request Oct 2, 2020
* Remove rethrow in extern c code

Signed-off-by: Stephen Brawner <brawner@gmail.com>

squash! Remove rethrow in extern c code

* Convert fprintf to rcutils error msg

Signed-off-by: Stephen Brawner <brawner@gmail.com>
ahcorde pushed a commit that referenced this pull request Oct 8, 2020
* Remove rethrow in extern c code

Signed-off-by: Stephen Brawner <brawner@gmail.com>

squash! Remove rethrow in extern c code

* Convert fprintf to rcutils error msg

Signed-off-by: Stephen Brawner <brawner@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants