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 the padding member from structs which should be empty #73

Merged
merged 2 commits into from
Jul 19, 2019

Conversation

dirk-thomas
Copy link
Member

IDL and some programming languages like C require a struct to have at least one member. Python though doesn't have that restriction and can define a class without any slots.

Therefore this patch removes the member structure_needs_at_least_one_member only used to "pad" empty structures from the Python data type. As a consequence printing the message won't show the member as well as the user won't see a getter and setter for the member anymore.

In the conversion from Python to C the member variable present in C is just set to 0 in order to not be uninitialized. In the other direction the value in the C struct is just ignored and not transferred to the Python object.

Fixes ros2/ros2cli#297. Requires ros2/rosidl#389.

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
@dirk-thomas dirk-thomas added enhancement New feature or request in review Waiting for review (Kanban column) labels Jul 18, 2019
@dirk-thomas dirk-thomas self-assigned this Jul 18, 2019
@sloretz
Copy link
Contributor

sloretz commented Jul 18, 2019

I think this spot at line 379 in __eq__ might need to be skipped

def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
@[for member in message.structure.members]@
@[ if isinstance(member.type, Array) and isinstance(member.type.value_type, BasicType) and member.type.value_type.typename in SPECIAL_NESTED_BASIC_TYPES]@
if all(self.@(member.name) != other.@(member.name)):
@[ else]@
if self.@(member.name) != other.@(member.name):
@[ end if]@
return False
@[end for]@

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
@dirk-thomas
Copy link
Member Author

dirk-thomas commented Jul 18, 2019

I think this spot at line 379 in __eq__ might need to be skipped

Very good point. Fixed in d97cc46. I am curious if the running CI builds will complain about it 🤔

Update: and the tests did catch this 😥 http://build.ros2.org/view/Eci/job/Eci__overlay_ubuntu_bionic_amd64/23/testReport/junit/rosidl_runtime_py.test.rosidl_runtime_py/test_set_message/test_set_message_fields_none/

@dirk-thomas
Copy link
Member Author

CI build including the second commit: Build Status (same test failures as with master)

@dirk-thomas dirk-thomas requested a review from sloretz July 19, 2019 03:54
@dirk-thomas dirk-thomas merged commit 6ec55cb into master Jul 19, 2019
@delete-merged-branch delete-merged-branch bot deleted the dirk-thomas/empty-struct-member-name branch July 19, 2019 16:19
dirk-thomas added a commit that referenced this pull request Nov 25, 2019
* remove the padding member from structs which should be empty

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>

* update __eq__ logic

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
dirk-thomas added a commit that referenced this pull request Nov 27, 2019
* remove the padding member from structs which should be empty

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>

* update __eq__ logic

Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request in review Waiting for review (Kanban column)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

structure_needs_at_least_one_member Verbosity with std_msgs/msg/Empty
2 participants