-
Notifications
You must be signed in to change notification settings - Fork 233
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
handle node names which are null #177
Conversation
rclpy/src/rclpy/_rclpy.c
Outdated
@@ -2320,7 +2320,8 @@ rclpy_get_node_names(PyObject * Py_UNUSED(self), PyObject * args) | |||
size_t idx; | |||
for (idx = 0; idx < node_names.size; ++idx) { | |||
PyList_SetItem( | |||
pynode_names, idx, PyUnicode_FromString(node_names.data[idx])); | |||
pynode_names, idx, PyUnicode_FromString( | |||
node_names.data[idx] ? node_names.data[idx] : "")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a difference between a null pointer and an empty string coming from rcl_get_node_names()
? If so, maybe this should return Py_None instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely. Updated the patch to use Py_None
.
6028605
to
f2d08db
Compare
rclpy/src/rclpy/_rclpy.c
Outdated
PyList_SetItem( | ||
pynode_names, idx, PyUnicode_FromString(node_names.data[idx])); | ||
pynode_names, idx, name ? PyUnicode_FromString(name) : Py_None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Py_INCREF(Py_None)
is needed here since PyList_SetItem
steals a reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for catching this (again). Fixed in 9135c1c. Please feel free to point out the third flaw 😉
f2d08db
to
9135c1c
Compare
9135c1c
to
9b60f4e
Compare
9b60f4e
to
e3eace5
Compare
e3eace5
to
fd1221d
Compare
Necessary since each item can potentially contain a
nullptr
.Connect to ros2/ros2#438.