Skip to content

Use PyCapsule names - #129

Merged
sloretz merged 12 commits into
masterfrom
rclpy_named_capsules
Oct 25, 2017
Merged

sloretz merged 12 commits into
masterfrom
rclpy_named_capsules

Conversation

@sloretz

@sloretz sloretz commented Oct 18, 2017 •

Copy link
Copy Markdown
Contributor

Naming capsules prevents calling the wrong kind of cleanup on a pointer. This also removes the string parameter from rclpy_destroy_entity and rclpy_destroy_node_entity since it can be figured out from the capsule name.

If a non-capsule or a capsule of the wrong type is specified, the functions let PyCapsule_GetPointer raise.

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

@sloretz sloretz added the in review Waiting for review (Kanban column) label Oct 18, 2017
@sloretz sloretz self-assigned this Oct 18, 2017
Comment thread rclpy/rclpy/node.py Outdated
if not class_ or class_.__name__ != 'PyCapsule':
raise ValueError('The node handle must be a PyCapsule')
for sub in self.subscriptions:
_rclpy.rclpy_destroy_node_entity(sub.subscription_handle, self.handle)

@dirk-thomas dirk-thomas Oct 18, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The return value is not being considered anymore?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is intentional. Currently rclpy_destroy_node_entity returns True on success or raises a RuntimeError on failure, so I got rid of the return value altogether.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see. If the return value of the function doesn't have any purpose anymore I would suggest to return None instead (like any Python function without a return statement).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe that is what this PR is doing, raising and returning NULL on failure otherwise returning None:
https://github.com/ros2/rclpy/pull/129/files#diff-80dda03110b5be606b823d6b0558b5c2R1567

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the noise. I don't know what I was looking at.

@sloretz sloretz mentioned this pull request Oct 19, 2017

@mikaelarguedas mikaelarguedas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

code change looks good to me, a few comment regarding docblock consistency throughout the PR

Comment thread rclpy/src/rclpy/_rclpy.c
/// Trigger a general purpose guard condition
/**
* Raises ValueError if the guard condition is not a capsule of the correcttype
* Raises RuntimeError if the guard condition could not be triggered

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Several other places do raise runtime error on this type of failure, maybe we should take advantage of this PR to update them all

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I updated all the ones I found in 451a072

Comment thread rclpy/src/rclpy/_rclpy.c
* provided as pymsg_type to send messages over the wire.
*
* A ValueError is raised (and NULL returned) when the topic name is invalid.
* Raises ValueError if the capsules are not the correct types

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you rephrase the sentence above to match this one as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done 451a072

Comment thread rclpy/src/rclpy/_rclpy.c Outdated

/// Returns the period of the timer in nanoseconds
/**
* Raise ValueError if capsule is not a timer capsule

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

typo: Raises for consistency with other docblocks added in this PR
Can you also move the Raise RuntimeError on rcl error here? (same for the other functions)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed 451a072

Naming capsules prevents calling the wrong kind of cleanup on a pointer
@sloretz
sloretz force-pushed the rclpy_named_capsules branch from 7841e73 to 0840184 Compare October 24, 2017 15:21
Comment thread rclpy/rclpy/node.py
self.services = []
self.clients = []
self.publishers = []
self.guards = []

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nitpick: maybe use the same order as above for the loops? That allows easier comparison that the same variables are used in both.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

pub, sub, cli, srv, tmr, gc 1561483

Comment thread rclpy/src/rclpy/_rclpy.c
rcl_guard_condition_t * gc = (rcl_guard_condition_t *)PyCapsule_GetPointer(
pygc, "rcl_guard_condition_t");
if (!gc) {
return NULL;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the expectation here? It should only return NULL when an error is set, right? But PyCapsule_GetPointer shouldn't set an error. Should a specific error message be set or should this return Py_RETURN_NONE instead (which would be a silent failure, probably not?)?

Same below for various other pointers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

PyCapsule_GetPointer will raise an exception if the Capsule is not a valid capsule with a matching name. I think the assumption here is that the only reason for gc to be NULL is if PyCapsule_GetPointer fails and thus an exception is already being set so we need to return NULL.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You are right, it does set an error when returning NULL. Sorry for the noise - should have checked the docs before.

@dirk-thomas dirk-thomas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@mikaelarguedas

Copy link
Copy Markdown
Member

I found a few bugs in this PR, please hold before merging

@mikaelarguedas mikaelarguedas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm, it would be great to rerun CI to make sure we didnt break anything along the way

@sloretz

sloretz commented Oct 25, 2017 •

Copy link
Copy Markdown
Contributor Author

@mikaelarguedas CI in progress

edit: started again with d4048f6

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

@sloretz

sloretz commented Oct 25, 2017

Copy link
Copy Markdown
Contributor Author

CI green. squash/merging.

@sloretz
sloretz merged commit 7298020 into master Oct 25, 2017
@sloretz sloretz removed the in review Waiting for review (Kanban column) label Oct 25, 2017
@sloretz
sloretz deleted the rclpy_named_capsules branch October 25, 2017 19:52
Comment thread rclpy/src/rclpy/_rclpy.c
}
PyErr_Format(PyExc_RuntimeError,
"Failed to create service: %s", rcl_get_error_string_safe());
Py_DECREF(service);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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