Fix SWIG syntax error on maps#589
Open
emiliocuestaf wants to merge 1 commit into
Open
Conversation
Signed-off-by: Emilio Cuesta <emiliocuesta@eprosima.com>
richiware
requested changes
Jul 13, 2026
richiware
left a comment
Member
There was a problem hiding this comment.
Please, add a regression test in dds-types-test repository
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
Description
When generating Python (SWIG) bindings for an IDL struct member of type
map<K, V>,fastddsgenbuilds the%template(...)instantiation name by concatenating the key type's fully-qualified C++ typename with the value type's unqualified name. If the key type's C++ name contains a scope-resolution operator (::) — whichstringalways does, since it maps tostd::string— the generated identifier is invalid SWIG syntax and SWIG fails to parse the file.Root cause
src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg,rule
member_getters, map branch:The value type correctly calls .noScopedCppTypename (namespace
stripped). The key type uses plain .cppTypename (fully qualified) —
that's the bug. Every other collection/composite branch in this same file
(sequences, arrays, optionals, fixed strings, the RPC template family)
consistently uses a sanitized name (noScopedCppTypename or
formatedCppTypename); this is the only branch that doesn't.
Reproduction
Given an IDL like:
fastddsgen -python generates, in the corresponding .i file:
Compiling this with SWIG fails:
SWIG parses :: as C++ scope resolution, so std::string_SomeipServiceEntry_map
is not a valid template-instantiation identifier.
Fix
Using
instead of
produces a clean identifier:
which SWIG parses without error.
Why this only affects map, not sequence/array
Sequences and arrays only ever need a name for their single content type, and both branches already use noScopedCppTypename for it. map is the only collection type with a second, independent type parameter (the key), and it was the one spot where the unqualified variant wasn't used. Any map whose key type has a qualified C++ name — string (→ std::string), or an enum key — triggers this; maps keyed by a plain scalar (int32, etc.) don't hit it, since those types have no :: in their C++ name to begin with.
Contributor Checklist
Reviewer Checklist
Contributor Checklist
Reviewer Checklist