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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions rosidl_generator_py/resource/_msg.py.em
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ from rosidl_parser.definition import BasicType
from rosidl_parser.definition import BOOLEAN_TYPE
from rosidl_parser.definition import BoundedSequence
from rosidl_parser.definition import CHARACTER_TYPES
from rosidl_parser.definition import EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME
from rosidl_parser.definition import FLOATING_POINT_TYPES
from rosidl_parser.definition import INTEGER_TYPES
from rosidl_parser.definition import NamespacedType
Expand Down Expand Up @@ -187,12 +188,18 @@ class @(message.structure.namespaced_type.name)(metaclass=Metaclass_@(message.st

__slots__ = [
@[for member in message.structure.members]@
@[ if len(message.structure.members) == 1 and member.name == EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME]@
@[ continue]@
@[ end if]@
'_@(member.name)',
@[end for]@
]

_fields_and_field_types = {
@[for member in message.structure.members]@
@[ if len(message.structure.members) == 1 and member.name == EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME]@
@[ continue]@
@[ end if]@
@{
type_ = member.type
if isinstance(type_, AbstractNestedType):
Expand Down Expand Up @@ -233,6 +240,9 @@ string@

SLOT_TYPES = (
@[for member in message.structure.members]@
@[ if len(message.structure.members) == 1 and member.name == EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME]@
@[ continue]@
@[ end if]@
@{
type_ = member.type
if isinstance(type_, AbstractNestedType):
Expand Down Expand Up @@ -269,6 +279,9 @@ if isinstance(type_, AbstractNestedType):
'Invalid arguments passed to constructor: %s' % \
', '.join(sorted(k for k in kwargs.keys() if '_' + k not in self.__slots__))
@[for member in message.structure.members]@
@[ if len(message.structure.members) == 1 and member.name == EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME]@
@[ continue]@
@[ end if]@
@{
type_ = member.type
if isinstance(type_, AbstractNestedType):
Expand Down Expand Up @@ -360,6 +373,9 @@ if isinstance(type_, AbstractNestedType):
if not isinstance(other, self.__class__):
return False
@[for member in message.structure.members]@
@[ if len(message.structure.members) == 1 and member.name == EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME]@
@[ continue]@
@[ end if]@
@[ 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]@
Expand All @@ -374,6 +390,9 @@ if isinstance(type_, AbstractNestedType):
from copy import copy
return copy(cls._fields_and_field_types)
@[for member in message.structure.members]@
@[ if len(message.structure.members) == 1 and member.name == EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME]@
@[ continue]@
@[ end if]@

@{
type_ = member.type
Expand Down
12 changes: 12 additions & 0 deletions rosidl_generator_py/resource/_msg_support.c.em
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ from rosidl_parser.definition import AbstractString
from rosidl_parser.definition import AbstractWString
from rosidl_parser.definition import Array
from rosidl_parser.definition import BasicType
from rosidl_parser.definition import EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME
from rosidl_parser.definition import NamespacedType


Expand Down Expand Up @@ -182,6 +183,10 @@ full_classname = '%s.%s.%s' % ('.'.join(message.structure.namespaced_type.namesp
}
@(msg_typename) * ros_message = _ros_message;
@[for member in message.structure.members]@
@[ if len(message.structure.members) == 1 and member.name == EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME]@
ros_message->@(member.name) = 0;
@[ continue]@
@[ end if]@
@{
type_ = member.type
if isinstance(type_, AbstractNestedType):
Expand Down Expand Up @@ -490,8 +495,15 @@ PyObject * @('__'.join(message.structure.namespaced_type.namespaces + [convert_c
return NULL;
}
}
@[if len(message.structure.members) == 1 and member.name == EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME]@
(void)raw_ros_message;
@[else]@
@(msg_typename) * ros_message = (@(msg_typename) *)raw_ros_message;
@[end if]@
@[for member in message.structure.members]@
@[ if len(message.structure.members) == 1 and member.name == EMPTY_STRUCTURE_REQUIRED_MEMBER_NAME]@
@[ continue]@
@[ end if]@
@{
type_ = member.type
if isinstance(type_, AbstractNestedType):
Expand Down