Add type hash to names_and_types (#356)#421
Open
tisomi wants to merge 1 commit into
Open
Conversation
Extends rmw_names_and_types_t with a type_hashes parallel array so the graph query APIs expose the type hash of each name/type pair, alongside the existing names and types arrays. `type_hashes[i][j]` corresponds to `types[i].data[j]`. rmw_names_and_types_init now enforces the documented zero-initialized precondition on its output argument and returns RMW_RET_INVALID_ARGUMENT otherwise. Adds fault-injection tests for the new field and pins down that the output struct is restored to zero state after a BAD_ALLOC, so the caller can re-init without leaks. Updates the doxygen across the affected headers so the descriptive prose says "names, types, and type hashes" instead of repeating the snake_case identifier outside code references, and documents the no-op-on-zero behavior of the unconditional cleanup in rmw_names_and_types_fini (which now correctly cleans up partially-initialized structs that the previous code leaked). Note: this extends a public struct and is therefore an ABI break. Signed-off-by: tisomi <[email protected]>
|
Tick the box to add this pull request to the merge queue (same as
|
This was referenced Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR extends
rmw_names_and_types_twith atype_hashesparallel array, so theROS graph query APIs (
rmw_get_topic_names_and_types,rmw_get_service_names_and_types,and the per-node variants) can expose the type hash of each name/type pair alongside the
existing
namesandtypesarrays. The new array is indexed in lockstep with the others:type_hashes[i][j]corresponds totypes[i].data[j].Alongside the struct change, the lifecycle helpers were updated and hardened:
rmw_names_and_types_initnow enforces the documented zero-initialized precondition onits output argument, returning
RMW_RET_INVALID_ARGUMENTwhen it is not zero-initialized.Previously the precondition was documented but unchecked, so passing a populated struct
would silently leak. It also allocates and unwinds the new
type_hashesarray, restoringthe struct to the zero state on any allocation failure so the caller can re-init without
leaking.
rmw_names_and_types_fininow cleans up thetype_hashesarray and finalizes partially-initialized structs — e.g. one left by a middlewarepopulate that inits the full struct then fails mid-fill — freeing the new
type_hashesarray row-by-row (skipping rows still NULL) instead of leaking it. The unconditional
names cleanup is a no-op on a zero-initialized names array.
Updated the doxygen across the affected headers to mention type hashes.
New fault-injection tests cover the
type_hashesallocation-failure path and assert theoutput struct is restored to the zero state after
RMW_RET_BAD_ALLOC, so the caller canre-init without leaks.
Note: this extends a public struct and is therefore an ABI break.
This is the interface half of the change; populating the field is handled in the companion
middleware PRs (see Additional Information).
Related: Issue #356
Is this user-facing behavior change?
Yes.
rmw_names_and_types_tgains atype_hashesmember — an ABI break; downstream consumersmust be rebuilt against the new layout.
name/type pair.
rmw_names_and_types_initnow rejects a non-zero-initialized output argument withRMW_RET_INVALID_ARGUMENT. Callers that already follow the documented contract (passing astruct from
rmw_get_zero_initialized_names_and_types()) are unaffected; callers thatrelied on the previous unchecked behavior get an explicit error instead of a silent leak.
Did you use Generative AI?
Yes. Claude (claude-sonnet-4-6) via GitHub Copilot was used to explore the codebase and
create an initial prototype.
Additional Information
rmw_dds_common #89: "Populate type hashes in graph cache names_and_types"rmw_zenoh #1004: "Populate type hashes in zenoh graph cache"rosidl_runtime_c/type_hash.h) needs no packaging change:rosidl_runtime_cis already a build/build_export dependency of this package.Testing
container; all pass.
type-hash path through the graph query APIs.
This is a SIEMENS activity and was initialized by @gramss