Skip to content

Commit 27edac6

Browse files
authored
Deduplicate incoming to_string generation in mako (#490)
For new incoming specs, we may duplicate to_string definitions due to the way the makeo loops over typedefs. This will remove duplication Signed-off-by: Russell McGuire <russell.w.mcguire@intel.com>
1 parent 87a396d commit 27edac6

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

scripts/templates/validation/to_string.h.mako

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,22 @@ inline std::string to_string(${th.make_type_name(n, tags, obj)} handle) {
6060

6161
%endfor
6262
// Callback to_string functions (function pointers)
63+
// Multiple callback typedefs can resolve to the same underlying function-pointer
64+
// type (e.g. void(*)(void*)). Since typedefs are aliases rather than distinct
65+
// types in C++, emit only one to_string overload per unique signature
66+
// (returntype + parameter types) to avoid redefinition errors.
67+
<% seen_cb_sigs = set() %>\
6368
%for obj in th.extract_objs(specs, r"callback"):
69+
<%
70+
cb_sig = (obj.get('returntype'), tuple(p['type'] for p in obj.get('params', [])))
71+
%>\
72+
%if cb_sig not in seen_cb_sigs:
73+
<% seen_cb_sigs.add(cb_sig) %>\
6474
inline std::string to_string(${th.make_type_name(n, tags, obj)} ptr) {
6575
return to_string(reinterpret_cast<const void*>(ptr));
6676
}
6777

78+
%endif
6879
%endfor
6980
%endif
7081
%if n == 'ze':

0 commit comments

Comments
 (0)