@@ -104,7 +104,7 @@ template <> struct is_handle<${th.make_type_name(n, tags, obj)}> : std::true_typ
104
104
%endfor
105
105
template <typename T >
106
106
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);
108
108
template <typename T > inline void serializeFlag(std::ostream &os, uint32_t flag);
109
109
template <typename T > inline void serializeTagged(std::ostream &os, const void *ptr, T value, size_t size);
110
110
@@ -192,7 +192,11 @@ template <typename T> inline void serializeTagged(std::ostream &os, const void *
192
192
case ${ ename} : {
193
193
% if th.value_traits.is_array(vtype):
194
194
<% atype = th.value_traits.get_array_name(vtype) %>
195
+ % if ' void' in atype:
196
+ const ${ atype} const *tptr = (const ${ atype} const*)ptr;
197
+ % else :
195
198
const ${ atype} *tptr = (const ${ atype} *)ptr;
199
+ %endif
196
200
% if " char" in atype: # # print char* arrays as simple NULL-terminated strings
197
201
serializePtr(os, tptr);
198
202
% else :
@@ -209,12 +213,16 @@ template <typename T> inline void serializeTagged(std::ostream &os, const void *
209
213
os << "}";
210
214
%endif
211
215
% else :
216
+ % if ' void' in vtype:
217
+ const ${ vtype} const *tptr = (const ${ vtype} const *)ptr;
218
+ % else :
212
219
const ${ vtype} *tptr = (const ${ vtype} *)ptr;
220
+ %endif
213
221
if (sizeof(${ vtype} ) > size) {
214
222
os << "invalid size (is: " << size << ", expected: >=" << sizeof(${ vtype} ) << ")";
215
223
return;
216
224
}
217
- os << (void *)(tptr) << " (";
225
+ os << (const void *)(tptr) << " (";
218
226
<%call expr = "member(tptr, vtype, False )">
219
227
*tptr
220
228
</%call >
@@ -237,7 +245,7 @@ template <typename T> inline void serializeTagged(std::ostream &os, const void *
237
245
}
238
246
239
247
## 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;
241
249
switch (*value) {
242
250
% for n, item in enumerate (obj[' etors' ]):
243
251
<%
@@ -362,21 +370,21 @@ inline std::ostream &operator<<(std::ostream &os, const struct ${th.make_pfncb_p
362
370
363
371
namespace ${ x} _params {
364
372
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) {
366
374
if (ptr == nullptr) {
367
375
os << "nullptr";
368
376
} else if constexpr (std::is_pointer_v<T >) {
369
- os << (void *)(ptr) << " (";
377
+ os << (const void *)(ptr) << " (";
370
378
serializePtr(os, *ptr);
371
379
os << ")";
372
380
} else if constexpr (std::is_void_v<T > || is_handle_v<T * >) {
373
- os << (void *)ptr;
381
+ os << (const void *)ptr;
374
382
} else if constexpr (std::is_same_v<std::remove _cv_t < T >, char>) {
375
- os << (void *)(ptr) << " (";
383
+ os << (const void *)(ptr) << " (";
376
384
os << ptr;
377
385
os << ")";
378
386
} else {
379
- os << (void *)(ptr) << " (";
387
+ os << (const void *)(ptr) << " (";
380
388
os << *ptr;
381
389
os << ")";
382
390
}
0 commit comments