Skip to content

Commit

Permalink
fix: Generate correct code for nested arrays of own type
Browse files Browse the repository at this point in the history
This fixes the code generation for the case that you have a message A :
A[] arrayOfA
  • Loading branch information
Janosch Machowinski authored and Janosch Machowinski committed Jun 2, 2023
1 parent a57baea commit b345117
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
8 changes: 8 additions & 0 deletions rosidl_generator_c/resource/full__description.c.em
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,16 @@ static const rosidl_type_hash_t @(c_typename)__EXPECTED_HASH = @(type_hash_to_c_

@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@# Names for all types
@{
added_itype_names = set()
}@
@[for itype_description in all_type_descriptions]@
@[ if itype_description['type_name'] not in added_itype_names]@
static char @(typename_to_c(itype_description['type_name']))__TYPE_NAME[] = "@(itype_description['type_name'])";
@{
added_itype_names.add(itype_description['type_name'])
}@
@[ end if]@
@[end for]@
@#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Expand Down
23 changes: 13 additions & 10 deletions rosidl_generator_c/resource/msg__struct.h.em
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ enum
@[end if]@
@#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// forward declare type
struct @(idl_structure_type_to_c_typename(message.structure.namespaced_type));
// Struct for a sequence of @(idl_structure_type_to_c_typename(message.structure.namespaced_type)).
typedef struct @(idl_structure_type_sequence_to_c_typename(message.structure.namespaced_type))
{
struct @(idl_structure_type_to_c_typename(message.structure.namespaced_type)) * data;
/// The number of valid items in data
size_t size;
/// The number of allocated items in data
size_t capacity;
} @(idl_structure_type_sequence_to_c_typename(message.structure.namespaced_type));
@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
/// Struct defined in @(interface_path_to_string(interface_path)) in the package @(package_name).
@{comments = message.structure.get_comment_lines()}@
Expand Down Expand Up @@ -179,13 +192,3 @@ typedef struct @(idl_structure_type_to_c_typename(message.structure.namespaced_t
} @(idl_structure_type_to_c_typename(message.structure.namespaced_type));
@#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// Struct for a sequence of @(idl_structure_type_to_c_typename(message.structure.namespaced_type)).
typedef struct @(idl_structure_type_sequence_to_c_typename(message.structure.namespaced_type))
{
@(idl_structure_type_to_c_typename(message.structure.namespaced_type)) * data;
/// The number of valid items in data
size_t size;
/// The number of allocated items in data
size_t capacity;
} @(idl_structure_type_sequence_to_c_typename(message.structure.namespaced_type));
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ def calculate_type_hash(serialized_type_description):
del field['default_value']
for referenced_td in hashable_dict['referenced_type_descriptions']:
for field in referenced_td['fields']:
del field['default_value']
if 'default_value' in field:
del field['default_value']

hashable_repr = json.dumps(
hashable_dict,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ header_files = [
@[ end if]@
#include "@(header_file)"
@[end for]@


namespace rosidl_typesupport_introspection_cpp
{

template<>
ROSIDL_TYPESUPPORT_INTROSPECTION_CPP_PUBLIC
const rosidl_message_type_support_t *
get_message_type_support_handle<@('::'.join([package_name] + list(interface_path.parents[0].parts) + [message.structure.namespaced_type.name]))>();

} // namespace rosidl_typesupport_introspection_cpp

@[for ns in message.structure.namespaced_type.namespaces]@

namespace @(ns)
Expand Down

0 comments on commit b345117

Please sign in to comment.