Skip to content

Commit b3278d0

Browse files
committed
Handle mangled type name collisions
1 parent 52058dc commit b3278d0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/c.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,18 @@ function mangle_c!(typedict::Dict{Int, String}, type_id::Int, typeinfo::OrderedD
129129
elseif type isa StructDesc
130130
mangled = sanitize_for_c(type.name)
131131
end
132-
# FIXME: this function should check for name collisions at this stage (which can happen due to
133-
# sanitization or name ambiguity in the printing from Julia) and gensym a unique suffix
134-
# if necessary
132+
133+
# Check for any name collision and unique the symbol, if necessary.
134+
if mangled in values(typedict)
135+
suffix = type_id
136+
extended = mangled * "_" * string(suffix)
137+
while extended in values(typedict)
138+
suffix += 1
139+
extended = mangled * "_" * string(suffix)
140+
end
141+
mangled = extended
142+
end
143+
135144
typedict[type_id] = mangled
136145
return mangled
137146
end

0 commit comments

Comments
 (0)