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

return NULL when conversion fails for any reason #226

Merged
merged 1 commit into from
Jun 29, 2017

Conversation

dirk-thomas
Copy link
Member

WIthout the patch the conversion function continue after setting a Python error. With the patch it return NULL instead.

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

Ready for review.

@dirk-thomas dirk-thomas added the in review Waiting for review (Kanban column) label Jun 28, 2017
@dirk-thomas dirk-thomas self-assigned this Jun 28, 2017
Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

lgtm

@mikaelarguedas
Copy link
Member

would it make sense to do the same (returning a NULL pointig PyObject) when the conversion fails the other way around?
Don't know if it's a problem you faced and wanted to address in this fix or if you're tidying up error management in general.

this is just a question, the patch looks good to me as is

@dirk-thomas
Copy link
Member Author

would it make sense to do the same (returning a NULL pointing PyObject) when the conversion fails the other way around?

I don't understand what you mean with "the other way around" and why "return a NULL pointing PyObject". Can you please clarify.

Don't know if it's a problem you faced and wanted to address in this fix or if you're tidying up error management in general.

I found this while debugging the case in ros2/rclpy#95 and tried to fix the error handling.

@mikaelarguedas
Copy link
Member

Oh I miss that related PR.

I don't understand what you mean with "the other way around" and why "return a NULL pointing PyObject". Can you please clarify.

By "the other way around" I meant when we fail to convert from C to Python.

In several places we assert that the result is valid (including in this function for the other types without error checking, e.g. PyFloat_AS_DOUBLE). These asserts would disappear in the Release builds and the code will keep going resulting on crashes down the road. I haven't experienced any crashes related to this so have been delaying rewriting the error management in this file.

But that's totally unrelated to this PR I was just wondering what would be the good way to handle this in the future when we decide to focus effort on fixing the error handling.

@dirk-thomas
Copy link
Member Author

By "the other way around" I meant when we fail to convert from C to Python.

Good point. I updated the patch to handle that direction too.

In several places we assert that the result is valid (including in this function for the other types without error checking, e.g. PyFloat_AS_DOUBLE). These asserts would disappear in the Release builds and the code will keep going resulting on crashes down the road. I haven't experienced any crashes related to this so have been delaying rewriting the error management in this file.

I think the assert's are onlty there as a sanity check. The field setter should already prevent wrong types to sneak in. Therefore I think that is ok as-is.

@dirk-thomas
Copy link
Member Author

See ros2/rclpy#96 for checking for a valid return value.

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

@dirk-thomas dirk-thomas merged commit bdefe18 into master Jun 29, 2017
@dirk-thomas dirk-thomas removed the in review Waiting for review (Kanban column) label Jun 29, 2017
@dirk-thomas dirk-thomas deleted the return_error_code branch June 29, 2017 06:18
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.

3 participants