From 8470daa9621083d091cb52af01eb17f35a0978b6 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Sat, 27 Apr 2019 17:04:45 -0400 Subject: [PATCH] Fix: headers: make static inline upcasts compatible with C++ MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Issue ===== There are many static inline functions which upcast a pointer from its original type to another one known to be a parent. The functions upcast with `(void *)` or `(const void *)`. While this works in C, it does not in C++, which is more strict: In file included from install/include/babeltrace/babeltrace.h:75, from test.cpp:1: install/include/babeltrace/trace-ir/field-class-const.h: In function ‘const bt_field_class_enumeration_mapping* bt_field_class_unsigned_enumeration_mapping_as_mapping_const(const bt_field_class_unsigned_enumeration_mapping*)’: install/include/babeltrace/trace-ir/field-class-const.h:100:9: error: invalid conversion from ‘const void*’ to ‘const bt_field_class_enumeration_mapping*’ [-fpermissive] return (const void *) mapping; Solution ======== Use the new __BT_UPCAST() and __BT_UPCAST_CONST() macros to upcast within headers. Those macros are defined in `babeltrace/types.h`. We use static_cast<>() in C++ with the specific destination type, going through `void *` or `const void *` to keep the same address. Known drawbacks =============== None. Signed-off-by: Philippe Proulx Change-Id: Iaac8e55635eb2f358a546c32bd886a484f5ebfeb Reviewed-on: https://review.gerrithub.io/c/eepp/babeltrace/+/452302 Reviewed-by: Simon Marchi --- include/babeltrace/graph/component-class-filter-const.h | 7 +++++-- include/babeltrace/graph/component-class-filter.h | 4 ++-- include/babeltrace/graph/component-class-sink-const.h | 4 ++-- include/babeltrace/graph/component-class-sink.h | 5 +++-- include/babeltrace/graph/component-class-source-const.h | 7 +++++-- include/babeltrace/graph/component-class-source.h | 5 +++-- include/babeltrace/graph/component-filter-const.h | 7 +++++-- include/babeltrace/graph/component-sink-const.h | 7 +++++-- include/babeltrace/graph/component-source-const.h | 7 +++++-- include/babeltrace/graph/port-input-const.h | 4 ++-- include/babeltrace/graph/port-output-const.h | 4 ++-- include/babeltrace/graph/port-output-message-iterator.h | 4 ++-- include/babeltrace/graph/self-component-class-filter.h | 8 ++++++-- include/babeltrace/graph/self-component-class-sink.h | 7 +++++-- include/babeltrace/graph/self-component-class-source.h | 8 ++++++-- include/babeltrace/graph/self-component-filter.h | 7 ++++--- .../graph/self-component-port-input-message-iterator.h | 5 +++-- include/babeltrace/graph/self-component-port-input.h | 6 +++--- include/babeltrace/graph/self-component-port-output.h | 6 +++--- include/babeltrace/graph/self-component-port.h | 5 +++-- include/babeltrace/graph/self-component-sink.h | 6 +++--- include/babeltrace/graph/self-component-source.h | 6 +++--- include/babeltrace/graph/self-component.h | 4 ++-- include/babeltrace/trace-ir/field-class-const.h | 6 +++--- include/babeltrace/types.h | 9 +++++++++ 25 files changed, 94 insertions(+), 54 deletions(-) diff --git a/include/babeltrace/graph/component-class-filter-const.h b/include/babeltrace/graph/component-class-filter-const.h index 668d326b..7b11819d 100644 --- a/include/babeltrace/graph/component-class-filter-const.h +++ b/include/babeltrace/graph/component-class-filter-const.h @@ -24,7 +24,10 @@ * SOFTWARE. */ -/* For bt_component_class, bt_component_class_filter */ +/* + * For bt_component_class, bt_component_class_filter, + * __BT_UPCAST_CONST + */ #include #ifdef __cplusplus @@ -36,7 +39,7 @@ const bt_component_class * bt_component_class_filter_as_component_class_const( const bt_component_class_filter *comp_cls_filter) { - return (const void *) comp_cls_filter; + return __BT_UPCAST_CONST(bt_component_class, comp_cls_filter); } extern void bt_component_class_filter_get_ref( diff --git a/include/babeltrace/graph/component-class-filter.h b/include/babeltrace/graph/component-class-filter.h index cf001bf8..2e8f472e 100644 --- a/include/babeltrace/graph/component-class-filter.h +++ b/include/babeltrace/graph/component-class-filter.h @@ -43,7 +43,7 @@ * bt_port_output, bt_query_executor, bt_self_component_class_filter, * bt_self_component_filter, bt_self_component_port_input, * bt_self_component_port_output, bt_value, bt_message_array_const, - * bt_bool, bt_self_message_iterator + * bt_bool, bt_self_message_iterator, __BT_UPCAST */ #include @@ -128,7 +128,7 @@ static inline bt_component_class *bt_component_class_filter_as_component_class( bt_component_class_filter *comp_cls_filter) { - return (void *) comp_cls_filter; + return __BT_UPCAST(bt_component_class, comp_cls_filter); } extern diff --git a/include/babeltrace/graph/component-class-sink-const.h b/include/babeltrace/graph/component-class-sink-const.h index ecd0059c..fd49c6df 100644 --- a/include/babeltrace/graph/component-class-sink-const.h +++ b/include/babeltrace/graph/component-class-sink-const.h @@ -24,7 +24,7 @@ * SOFTWARE. */ -/* For bt_component_class, bt_component_class_sink */ +/* For bt_component_class, bt_component_class_sink, __BT_UPCAST_CONST */ #include #ifdef __cplusplus @@ -36,7 +36,7 @@ const bt_component_class * bt_component_class_sink_as_component_class_const( const bt_component_class_sink *comp_cls_sink) { - return (const void *) comp_cls_sink; + return __BT_UPCAST_CONST(bt_component_class, comp_cls_sink); } extern void bt_component_class_sink_get_ref( diff --git a/include/babeltrace/graph/component-class-sink.h b/include/babeltrace/graph/component-class-sink.h index 601974b9..a34dcfd6 100644 --- a/include/babeltrace/graph/component-class-sink.h +++ b/include/babeltrace/graph/component-class-sink.h @@ -38,7 +38,8 @@ /* * For bt_component_class, bt_component_class_sink, bt_port_output, * bt_query_executor, bt_self_component_class_sink, - * bt_self_component_sink, bt_self_component_port_input, bt_value + * bt_self_component_sink, bt_self_component_port_input, bt_value, + * __BT_UPCAST */ #include @@ -83,7 +84,7 @@ static inline bt_component_class *bt_component_class_sink_as_component_class( bt_component_class_sink *comp_cls_sink) { - return (void *) comp_cls_sink; + return __BT_UPCAST(bt_component_class, comp_cls_sink); } extern diff --git a/include/babeltrace/graph/component-class-source-const.h b/include/babeltrace/graph/component-class-source-const.h index 60c2665f..f3c87ff6 100644 --- a/include/babeltrace/graph/component-class-source-const.h +++ b/include/babeltrace/graph/component-class-source-const.h @@ -24,7 +24,10 @@ * SOFTWARE. */ -/* For bt_component_class, bt_component_class_source */ +/* + * For bt_component_class, bt_component_class_source, + * __BT_UPCAST_CONST + */ #include #ifdef __cplusplus @@ -36,7 +39,7 @@ const bt_component_class * bt_component_class_source_as_component_class_const( const bt_component_class_source *comp_cls_source) { - return (const void *) comp_cls_source; + return __BT_UPCAST_CONST(bt_component_class, comp_cls_source); } extern void bt_component_class_source_get_ref( diff --git a/include/babeltrace/graph/component-class-source.h b/include/babeltrace/graph/component-class-source.h index 8697faaa..4a708815 100644 --- a/include/babeltrace/graph/component-class-source.h +++ b/include/babeltrace/graph/component-class-source.h @@ -42,7 +42,8 @@ * For bt_component_class, bt_component_class_source, bt_port_input, * bt_query_executor, bt_self_component_class_source, * bt_self_component_source, bt_self_component_port_output, bt_value, - * bt_message_array_const, bt_bool, bt_self_message_iterator + * bt_message_array_const, bt_bool, bt_self_message_iterator, + * __BT_UPCAST */ #include @@ -114,7 +115,7 @@ static inline bt_component_class *bt_component_class_source_as_component_class( bt_component_class_source *comp_cls_source) { - return (void *) comp_cls_source; + return __BT_UPCAST(bt_component_class, comp_cls_source); } extern diff --git a/include/babeltrace/graph/component-filter-const.h b/include/babeltrace/graph/component-filter-const.h index b5d6947d..546761e3 100644 --- a/include/babeltrace/graph/component-filter-const.h +++ b/include/babeltrace/graph/component-filter-const.h @@ -26,7 +26,10 @@ #include -/* For bt_component, bt_component_filter, bt_port_input, bt_port_output */ +/* + * For bt_component, bt_component_filter, bt_port_input, bt_port_output, + * __BT_UPCAST_CONST + */ #include #ifdef __cplusplus @@ -37,7 +40,7 @@ static inline const bt_component *bt_component_filter_as_component_const( const bt_component_filter *component) { - return (const void *) component; + return __BT_UPCAST_CONST(bt_component, component); } extern uint64_t bt_component_filter_get_input_port_count( diff --git a/include/babeltrace/graph/component-sink-const.h b/include/babeltrace/graph/component-sink-const.h index 0fece9ce..d0bd773d 100644 --- a/include/babeltrace/graph/component-sink-const.h +++ b/include/babeltrace/graph/component-sink-const.h @@ -26,7 +26,10 @@ #include -/* For bt_component, bt_component_filter, bt_port_input */ +/* + * For bt_component, bt_component_filter, bt_port_input, + * __BT_UPCAST_CONST + */ #include #ifdef __cplusplus @@ -37,7 +40,7 @@ static inline const bt_component *bt_component_sink_as_component_const( const bt_component_sink *component) { - return (const void *) component; + return __BT_UPCAST_CONST(bt_component, component); } extern uint64_t bt_component_sink_get_input_port_count( diff --git a/include/babeltrace/graph/component-source-const.h b/include/babeltrace/graph/component-source-const.h index f0d9ee51..628f22db 100644 --- a/include/babeltrace/graph/component-source-const.h +++ b/include/babeltrace/graph/component-source-const.h @@ -26,7 +26,10 @@ #include -/* For bt_component, bt_component_filter, bt_port_output */ +/* + * For bt_component, bt_component_filter, bt_port_output, + * __BT_UPCAST_CONST + */ #include #ifdef __cplusplus @@ -37,7 +40,7 @@ static inline const bt_component *bt_component_source_as_component_const( const bt_component_source *component) { - return (void *) component; + return __BT_UPCAST_CONST(bt_component, component); } extern uint64_t bt_component_source_get_output_port_count( diff --git a/include/babeltrace/graph/port-input-const.h b/include/babeltrace/graph/port-input-const.h index c98972e8..5301769f 100644 --- a/include/babeltrace/graph/port-input-const.h +++ b/include/babeltrace/graph/port-input-const.h @@ -24,7 +24,7 @@ * SOFTWARE. */ -/* For bt_port, bt_port_input */ +/* For bt_port, bt_port_input, __BT_UPCAST_CONST */ #include #include @@ -36,7 +36,7 @@ extern "C" { static inline const bt_port *bt_port_input_as_port_const(const bt_port_input *port_input) { - return (const void *) port_input; + return __BT_UPCAST_CONST(bt_port, port_input); } extern void bt_port_input_get_ref(const bt_port_input *port_input); diff --git a/include/babeltrace/graph/port-output-const.h b/include/babeltrace/graph/port-output-const.h index 19a5db51..0afa640f 100644 --- a/include/babeltrace/graph/port-output-const.h +++ b/include/babeltrace/graph/port-output-const.h @@ -24,7 +24,7 @@ * SOFTWARE. */ -/* For bt_port, bt_port_output */ +/* For bt_port, bt_port_output, __BT_UPCAST_CONST */ #include #include @@ -36,7 +36,7 @@ extern "C" { static inline const bt_port *bt_port_output_as_port_const(const bt_port_output *port_output) { - return (const void *) port_output; + return __BT_UPCAST_CONST(bt_port, port_output); } extern void bt_port_output_get_ref(const bt_port_output *port_output); diff --git a/include/babeltrace/graph/port-output-message-iterator.h b/include/babeltrace/graph/port-output-message-iterator.h index fa1ab274..f7543781 100644 --- a/include/babeltrace/graph/port-output-message-iterator.h +++ b/include/babeltrace/graph/port-output-message-iterator.h @@ -31,7 +31,7 @@ /* * For bt_port, bt_message, bt_message_iterator, * bt_port_output_message_iterator, bt_graph, bt_port_output, - * bt_message_array_const, bt_bool + * bt_message_array_const, bt_bool, __BT_UPCAST */ #include @@ -44,7 +44,7 @@ bt_message_iterator * bt_port_output_message_iterator_as_message_iterator( bt_port_output_message_iterator *iterator) { - return (void *) iterator; + return __BT_UPCAST(bt_message_iterator, iterator); } extern bt_port_output_message_iterator * diff --git a/include/babeltrace/graph/self-component-class-filter.h b/include/babeltrace/graph/self-component-class-filter.h index 2d209ac2..1ff7b391 100644 --- a/include/babeltrace/graph/self-component-class-filter.h +++ b/include/babeltrace/graph/self-component-class-filter.h @@ -24,7 +24,10 @@ * SOFTWARE. */ -/* For bt_component_class_filter, bt_self_component_class_filter */ +/* + * For bt_component_class_filter, bt_self_component_class_filter, + * __BT_UPCAST_CONST + */ #include #ifdef __cplusplus @@ -36,7 +39,8 @@ const bt_component_class_filter * bt_self_component_class_filter_as_component_class_filter( bt_self_component_class_filter *self_comp_cls_filter) { - return (const void *) self_comp_cls_filter; + return __BT_UPCAST_CONST(bt_component_class_filter, + self_comp_cls_filter); } #ifdef __cplusplus diff --git a/include/babeltrace/graph/self-component-class-sink.h b/include/babeltrace/graph/self-component-class-sink.h index 8f40385e..2661e830 100644 --- a/include/babeltrace/graph/self-component-class-sink.h +++ b/include/babeltrace/graph/self-component-class-sink.h @@ -24,7 +24,10 @@ * SOFTWARE. */ -/* For bt_component_class_sink, bt_self_component_class_sink */ +/* + * For bt_component_class_sink, bt_self_component_class_sink, + * __BT_UPCAST_CONST + */ #include #ifdef __cplusplus @@ -36,7 +39,7 @@ const bt_component_class_sink * bt_self_component_class_sink_as_component_class_sink( bt_self_component_class_sink *self_comp_cls_sink) { - return (const void *) self_comp_cls_sink; + return __BT_UPCAST_CONST(bt_component_class_sink, self_comp_cls_sink); } #ifdef __cplusplus diff --git a/include/babeltrace/graph/self-component-class-source.h b/include/babeltrace/graph/self-component-class-source.h index 29bb1aa1..f78b4f78 100644 --- a/include/babeltrace/graph/self-component-class-source.h +++ b/include/babeltrace/graph/self-component-class-source.h @@ -24,7 +24,10 @@ * SOFTWARE. */ -/* For bt_component_class_source, bt_self_component_class_source */ +/* + * For bt_component_class_source, bt_self_component_class_source, + * __BT_UPCAST_CONST + */ #include #ifdef __cplusplus @@ -36,7 +39,8 @@ const bt_component_class_source * bt_self_component_class_source_as_component_class_source( bt_self_component_class_source *self_comp_cls_source) { - return (const void *) self_comp_cls_source; + return __BT_UPCAST_CONST(bt_component_class_source, + self_comp_cls_source); } #ifdef __cplusplus diff --git a/include/babeltrace/graph/self-component-filter.h b/include/babeltrace/graph/self-component-filter.h index 8d12e106..3fec35cf 100644 --- a/include/babeltrace/graph/self-component-filter.h +++ b/include/babeltrace/graph/self-component-filter.h @@ -31,7 +31,8 @@ /* * For bt_component_filter, bt_self_component, bt_self_component_filter, - * bt_self_component_port_input, bt_self_component_port_output + * bt_self_component_port_input, bt_self_component_port_output, + * __BT_UPCAST, __BT_UPCAST_CONST */ #include @@ -43,7 +44,7 @@ static inline bt_self_component *bt_self_component_filter_as_self_component( bt_self_component_filter *self_comp_filter) { - return (void *) self_comp_filter; + return __BT_UPCAST(bt_self_component, self_comp_filter); } static inline @@ -51,7 +52,7 @@ const bt_component_filter * bt_self_component_filter_as_component_filter( bt_self_component_filter *self_comp_filter) { - return (const void *) self_comp_filter; + return __BT_UPCAST_CONST(bt_component_filter, self_comp_filter); } extern bt_self_component_port_output * diff --git a/include/babeltrace/graph/self-component-port-input-message-iterator.h b/include/babeltrace/graph/self-component-port-input-message-iterator.h index 61fd2b21..1efefe13 100644 --- a/include/babeltrace/graph/self-component-port-input-message-iterator.h +++ b/include/babeltrace/graph/self-component-port-input-message-iterator.h @@ -31,7 +31,8 @@ /* * For bt_component, bt_message_iterator, * bt_self_component_port_input_message_iterator, - * bt_self_component_port_input, bt_message_array_const, bt_bool + * bt_self_component_port_input, bt_message_array_const, bt_bool, + * __BT_UPCAST */ #include @@ -44,7 +45,7 @@ bt_message_iterator * bt_self_component_port_input_message_iterator_as_message_iterator( bt_self_component_port_input_message_iterator *iterator) { - return (void *) iterator; + return __BT_UPCAST(bt_message_iterator, iterator); } extern bt_self_component_port_input_message_iterator * diff --git a/include/babeltrace/graph/self-component-port-input.h b/include/babeltrace/graph/self-component-port-input.h index ba3991b2..150499a2 100644 --- a/include/babeltrace/graph/self-component-port-input.h +++ b/include/babeltrace/graph/self-component-port-input.h @@ -25,7 +25,7 @@ /* * For bt_port_input, bt_self_component_port, - * bt_self_component_port_input + * bt_self_component_port_input, __BT_UPCAST, __BT_UPCAST_CONST */ #include @@ -38,14 +38,14 @@ bt_self_component_port * bt_self_component_port_input_as_self_component_port( bt_self_component_port_input *self_component_port) { - return (void *) self_component_port; + return __BT_UPCAST(bt_self_component_port, self_component_port); } static inline const bt_port_input *bt_self_component_port_input_as_port_input( const bt_self_component_port_input *self_component_port) { - return (const void *) self_component_port; + return __BT_UPCAST_CONST(bt_port_input, self_component_port); } #ifdef __cplusplus diff --git a/include/babeltrace/graph/self-component-port-output.h b/include/babeltrace/graph/self-component-port-output.h index 293f705b..fee38aa8 100644 --- a/include/babeltrace/graph/self-component-port-output.h +++ b/include/babeltrace/graph/self-component-port-output.h @@ -25,7 +25,7 @@ /* * For bt_port_output, bt_self_component_port, - * bt_self_component_port_output + * bt_self_component_port_output, __BT_UPCAST, __BT_UPCAST_CONST */ #include @@ -38,14 +38,14 @@ bt_self_component_port * bt_self_component_port_output_as_self_component_port( bt_self_component_port_output *self_component_port) { - return (void *) self_component_port; + return __BT_UPCAST(bt_self_component_port, self_component_port); } static inline const bt_port_output *bt_self_component_port_output_as_port_output( bt_self_component_port_output *self_component_port) { - return (const void *) self_component_port; + return __BT_UPCAST_CONST(bt_port_output, self_component_port); } #ifdef __cplusplus diff --git a/include/babeltrace/graph/self-component-port.h b/include/babeltrace/graph/self-component-port.h index ad5daeb8..c524cac3 100644 --- a/include/babeltrace/graph/self-component-port.h +++ b/include/babeltrace/graph/self-component-port.h @@ -24,7 +24,8 @@ */ /* - * For bt_port, bt_self_component_port, bt_self_component, bt_connection + * For bt_port, bt_self_component_port, bt_self_component, + * bt_connection, __BT_UPCAST_CONST */ #include @@ -40,7 +41,7 @@ static inline const bt_port *bt_self_component_port_as_port( bt_self_component_port *self_port) { - return (const void *) self_port; + return __BT_UPCAST_CONST(bt_port, self_port); } extern bt_self_component *bt_self_component_port_borrow_component( diff --git a/include/babeltrace/graph/self-component-sink.h b/include/babeltrace/graph/self-component-sink.h index 9f2d6bd6..04b8d206 100644 --- a/include/babeltrace/graph/self-component-sink.h +++ b/include/babeltrace/graph/self-component-sink.h @@ -30,7 +30,7 @@ /* * For bt_component_sink, bt_self_component, bt_self_component_sink, - * bt_self_component_port_input + * bt_self_component_port_input, __BT_UPCAST, __BT_UPCAST_CONST */ #include @@ -42,7 +42,7 @@ static inline bt_self_component *bt_self_component_sink_as_self_component( bt_self_component_sink *self_comp_sink) { - return (void *) self_comp_sink; + return __BT_UPCAST(bt_self_component, self_comp_sink); } static inline @@ -50,7 +50,7 @@ const bt_component_sink * bt_self_component_sink_as_component_sink( bt_self_component_sink *self_comp_sink) { - return (const void *) self_comp_sink; + return __BT_UPCAST_CONST(bt_component_sink, self_comp_sink); } extern bt_self_component_port_input * diff --git a/include/babeltrace/graph/self-component-source.h b/include/babeltrace/graph/self-component-source.h index 3b96af1e..5fdee3f3 100644 --- a/include/babeltrace/graph/self-component-source.h +++ b/include/babeltrace/graph/self-component-source.h @@ -30,7 +30,7 @@ /* * For bt_component_source, bt_self_component, bt_self_component_source, - * bt_self_component_port_output + * bt_self_component_port_output, __BT_UPCAST, __BT_UPCAST_CONST */ #include @@ -42,7 +42,7 @@ static inline bt_self_component *bt_self_component_source_as_self_component( bt_self_component_source *self_comp_source) { - return (void *) self_comp_source; + return __BT_UPCAST(bt_self_component, self_comp_source); } static inline @@ -50,7 +50,7 @@ const bt_component_source * bt_self_component_source_as_component_source( bt_self_component_source *self_comp_source) { - return (const void *) self_comp_source; + return __BT_UPCAST_CONST(bt_component_source, self_comp_source); } extern bt_self_component_port_output * diff --git a/include/babeltrace/graph/self-component.h b/include/babeltrace/graph/self-component.h index 65ff2e67..0be09442 100644 --- a/include/babeltrace/graph/self-component.h +++ b/include/babeltrace/graph/self-component.h @@ -23,7 +23,7 @@ * SOFTWARE. */ -/* For bt_component, bt_self_component */ +/* For bt_component, bt_self_component, __BT_UPCAST */ #include #ifdef __cplusplus @@ -43,7 +43,7 @@ static inline const bt_component *bt_self_component_as_component( bt_self_component *self_component) { - return (const void *) self_component; + return __BT_UPCAST(bt_component, self_component); } extern void *bt_self_component_get_data( diff --git a/include/babeltrace/trace-ir/field-class-const.h b/include/babeltrace/trace-ir/field-class-const.h index eb9cb150..9f2f960b 100644 --- a/include/babeltrace/trace-ir/field-class-const.h +++ b/include/babeltrace/trace-ir/field-class-const.h @@ -32,7 +32,7 @@ * bt_field_class_enumeration_mapping, * bt_field_class_unsigned_enumeration_mapping, * bt_field_class_signed_enumeration_mapping, - * bt_field_class_enumeration_mapping_label_array + * bt_field_class_enumeration_mapping_label_array, __BT_UPCAST_CONST */ #include @@ -97,7 +97,7 @@ const bt_field_class_enumeration_mapping * bt_field_class_unsigned_enumeration_mapping_as_mapping_const( const bt_field_class_unsigned_enumeration_mapping *mapping) { - return (const void *) mapping; + return __BT_UPCAST_CONST(bt_field_class_enumeration_mapping, mapping); } static inline @@ -105,7 +105,7 @@ const bt_field_class_enumeration_mapping * bt_field_class_signed_enumeration_mapping_as_mapping_const( const bt_field_class_signed_enumeration_mapping *mapping) { - return (const void *) mapping; + return __BT_UPCAST_CONST(bt_field_class_enumeration_mapping, mapping); } extern const char *bt_field_class_enumeration_mapping_get_label( diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h index 9f71793a..12b35f60 100644 --- a/include/babeltrace/types.h +++ b/include/babeltrace/types.h @@ -25,6 +25,15 @@ #include +/* Internal use */ +#ifdef __cplusplus +# define __BT_UPCAST(_type, _p) static_cast<_type *>(static_cast(_p)) +# define __BT_UPCAST_CONST(_type, _p) static_cast(static_cast(_p)) +#else +# define __BT_UPCAST(_type, _p) ((_type *) (_p)) +# define __BT_UPCAST_CONST(_type, _p) ((const _type *) (_p)) +#endif + #ifdef __cplusplus extern "C" { #endif -- 2.34.1