Skip to content

Commit ee0a4b8

Browse files
authored
Merge pull request #827 from aarongreig/aaron/keepQualifierCastParams
Avoid dropping const qualifiers when casting in ur_params.hpp
2 parents f12e1fb + 986f8a8 commit ee0a4b8

File tree

2 files changed

+218
-209
lines changed

2 files changed

+218
-209
lines changed

scripts/templates/params.hpp.mako

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ template <> struct is_handle<${th.make_type_name(n, tags, obj)}> : std::true_typ
104104
%endfor
105105
template <typename T>
106106
inline constexpr bool is_handle_v = is_handle<T>::value;
107-
template <typename T> inline void serializePtr(std::ostream &os, T *ptr);
107+
template <typename T> inline void serializePtr(std::ostream &os, const T *ptr);
108108
template <typename T> inline void serializeFlag(std::ostream &os, uint32_t flag);
109109
template <typename T> inline void serializeTagged(std::ostream &os, const void *ptr, T value, size_t size);
110110

@@ -192,7 +192,11 @@ template <typename T> inline void serializeTagged(std::ostream &os, const void *
192192
case ${ename}: {
193193
%if th.value_traits.is_array(vtype):
194194
<% atype = th.value_traits.get_array_name(vtype) %>
195+
%if 'void' in atype:
196+
const ${atype} const *tptr = (const ${atype} const*)ptr;
197+
%else:
195198
const ${atype} *tptr = (const ${atype} *)ptr;
199+
%endif
196200
%if "char" in atype: ## print char* arrays as simple NULL-terminated strings
197201
serializePtr(os, tptr);
198202
%else:
@@ -209,12 +213,16 @@ template <typename T> inline void serializeTagged(std::ostream &os, const void *
209213
os << "}";
210214
%endif
211215
%else:
216+
%if 'void' in vtype:
217+
const ${vtype} const *tptr = (const ${vtype} const *)ptr;
218+
%else:
212219
const ${vtype} *tptr = (const ${vtype} *)ptr;
220+
%endif
213221
if (sizeof(${vtype}) > size) {
214222
os << "invalid size (is: " << size << ", expected: >=" << sizeof(${vtype}) << ")";
215223
return;
216224
}
217-
os << (void *)(tptr) << " (";
225+
os << (const void *)(tptr) << " (";
218226
<%call expr="member(tptr, vtype, False)">
219227
*tptr
220228
</%call>
@@ -237,7 +245,7 @@ template <typename T> inline void serializeTagged(std::ostream &os, const void *
237245
}
238246

239247
## structure type enum value must be first
240-
enum ${th.make_enum_name(n, tags, obj)} *value = (enum ${th.make_enum_name(n, tags, obj)} *)ptr;
248+
const enum ${th.make_enum_name(n, tags, obj)} *value = (const enum ${th.make_enum_name(n, tags, obj)} *)ptr;
241249
switch (*value) {
242250
%for n, item in enumerate(obj['etors']):
243251
<%
@@ -362,21 +370,21 @@ inline std::ostream &operator<<(std::ostream &os, const struct ${th.make_pfncb_p
362370

363371
namespace ${x}_params {
364372

365-
template <typename T> inline void serializePtr(std::ostream &os, T *ptr) {
373+
template <typename T> inline void serializePtr(std::ostream &os, const T *ptr) {
366374
if (ptr == nullptr) {
367375
os << "nullptr";
368376
} else if constexpr (std::is_pointer_v<T>) {
369-
os << (void *)(ptr) << " (";
377+
os << (const void *)(ptr) << " (";
370378
serializePtr(os, *ptr);
371379
os << ")";
372380
} else if constexpr (std::is_void_v<T> || is_handle_v<T *>) {
373-
os << (void *)ptr;
381+
os << (const void *)ptr;
374382
} else if constexpr (std::is_same_v<std::remove_cv_t< T >, char>) {
375-
os << (void *)(ptr) << " (";
383+
os << (const void *)(ptr) << " (";
376384
os << ptr;
377385
os << ")";
378386
} else {
379-
os << (void *)(ptr) << " (";
387+
os << (const void *)(ptr) << " (";
380388
os << *ptr;
381389
os << ")";
382390
}

0 commit comments

Comments
 (0)