From e865d86a8111dd23196928142ae6cbadac888fc6 Mon Sep 17 00:00:00 2001 From: Shamim Date: Mon, 15 Apr 2024 04:10:04 +0200 Subject: [PATCH] avoid implicit pointer conv for c++ support --- include/fixed-containers/K_to_V_hashtable.h | 6 +++--- include/fixed-containers/T_queue.h | 2 +- include/fixed-containers/T_stack.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/fixed-containers/K_to_V_hashtable.h b/include/fixed-containers/K_to_V_hashtable.h index 55db8534..f9bc0ddb 100644 --- a/include/fixed-containers/K_to_V_hashtable.h +++ b/include/fixed-containers/K_to_V_hashtable.h @@ -121,7 +121,8 @@ static inline bool JOIN(K_to_V_hashtable, init_internal)(K_to_V_hashtable_type** if (pow2_capacity > (SIZE_MAX - offsetof(K_to_V_hashtable_type, arr)) / sizeof(K_to_V_hashtable_slot_type)) { return false; } - *hashtable_pp = malloc(offsetof(K_to_V_hashtable_type, arr) + sizeof(K_to_V_hashtable_slot_type) * pow2_capacity); + *hashtable_pp = + (K_to_V_hashtable_type*)malloc(offsetof(K_to_V_hashtable_type, arr) + sizeof(K_to_V_hashtable_slot_type) * pow2_capacity); if ((*hashtable_pp) == NULL) { return false; } @@ -248,14 +249,13 @@ static inline VALUE_TYPE* JOIN(K_to_V_hashtable, get_mut)(K_to_V_hashtable_type* } static inline VALUE_TYPE JOIN(K_to_V_hashtable, get)(K_to_V_hashtable_type* hashtable_p, const KEY_TYPE key, - const VALUE_TYPE default_value) { + const VALUE_TYPE default_value) { assert(hashtable_p != NULL); VALUE_TYPE* value_p = JOIN(K_to_V_hashtable, get_mut)(hashtable_p, key); return value_p != NULL ? *value_p : default_value; } - static inline void JOIN(K_to_V_hashtable, set)(K_to_V_hashtable_type* hashtable_p, const KEY_TYPE key, const VALUE_TYPE value) { assert(hashtable_p != NULL); #define K_to_V_hashtable_is_full JOIN(K_to_V_hashtable, is_full) diff --git a/include/fixed-containers/T_queue.h b/include/fixed-containers/T_queue.h index 515705f0..ddca2667 100644 --- a/include/fixed-containers/T_queue.h +++ b/include/fixed-containers/T_queue.h @@ -82,7 +82,7 @@ static inline bool JOIN(T_queue, init_internal)(T_queue_type** queue_pp, size_t if (pow2_capacity > (SIZE_MAX - offsetof(T_queue_type, arr)) / sizeof(VALUE_TYPE)) { return false; } - *queue_pp = malloc(offsetof(T_queue_type, arr) + sizeof(VALUE_TYPE) * pow2_capacity); + *queue_pp = (T_queue_type*)malloc(offsetof(T_queue_type, arr) + sizeof(VALUE_TYPE) * pow2_capacity); if ((*queue_pp) == NULL) { return false; } diff --git a/include/fixed-containers/T_stack.h b/include/fixed-containers/T_stack.h index 1ee5d898..b4d653a6 100644 --- a/include/fixed-containers/T_stack.h +++ b/include/fixed-containers/T_stack.h @@ -39,7 +39,7 @@ #include // size_t, NULL, aligned_alloc, free #include // memcpy -#define T_stack_for_each(stack_p, index_plus_one, value) \ +#define T_stack_for_each(stack_p, index_plus_one, value) \ for ((index_plus_one) = (stack_p)->count; ((index_plus_one) > 0 && ((value) = (stack_p)->arr[(index_plus_one)-1], true)); \ (index_plus_one)--) @@ -74,7 +74,7 @@ static inline bool JOIN(T_stack, init)(T_stack_type** stack_pp, size_t capacity) if (capacity == 0 || capacity > (SIZE_MAX - offsetof(T_stack_type, arr)) / sizeof(VALUE_TYPE)) { return false; } - *stack_pp = malloc(offsetof(T_stack_type, arr) + sizeof(VALUE_TYPE) * capacity); + *stack_pp = (T_stack_type*)malloc(offsetof(T_stack_type, arr) + sizeof(VALUE_TYPE) * capacity); if ((*stack_pp) == NULL) { return false; }