From a66b5080c38dc9d270e1ecde38c47b3545e761c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Mon, 6 Feb 2023 17:27:44 +0000 Subject: [PATCH] Make wmem and wsutil a single logical library We want to do more sophisticated processing of UTF-8 in wmem and for that we want to use the unicode utility functions in wsutil. We also want to use wmem scoped memory in wsutil unicode utility functions. This introduces a circular dependency. Fix that by making both the same library and removing the sanitary cordon separating them. We still need to be mindful of public header depencies of wmem on wsutil because wmem.h is included in wireshark.h and we want to be parsimonious with the use of global includes. --- wsutil/wmem/wmem-int.h | 7 +------ wsutil/wmem/wmem_core.c | 6 +++--- wsutil/wmem/wmem_interval_tree.c | 2 +- wsutil/wmem/wmem_stack.c | 2 +- wsutil/wmem/wmem_strbuf.c | 6 +++--- wsutil/wmem/wmem_tree.c | 4 ++-- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/wsutil/wmem/wmem-int.h b/wsutil/wmem/wmem-int.h index 8102742d0c..6c4e498594 100644 --- a/wsutil/wmem/wmem-int.h +++ b/wsutil/wmem/wmem-int.h @@ -14,12 +14,7 @@ #define __WMEM_INT_H__ #include - -#ifdef WS_DEBUG -#define ASSERT(...) g_assert(__VA_ARGS__) -#else -#define ASSERT(...) (void)0 -#endif /* WS_DISABLE_DEBUG */ +#include #endif /* __WMEM_INT_H__ */ diff --git a/wsutil/wmem/wmem_core.c b/wsutil/wmem/wmem_core.c index a49730088d..d7f03203d6 100644 --- a/wsutil/wmem/wmem_core.c +++ b/wsutil/wmem/wmem_core.c @@ -35,7 +35,7 @@ wmem_alloc(wmem_allocator_t *allocator, const size_t size) return g_malloc(size); } - ASSERT(allocator->in_scope); + ws_assert(allocator->in_scope); if (size == 0) { return NULL; @@ -66,7 +66,7 @@ wmem_free(wmem_allocator_t *allocator, void *ptr) return; } - ASSERT(allocator->in_scope); + ws_assert(allocator->in_scope); if (ptr == NULL) { return; @@ -91,7 +91,7 @@ wmem_realloc(wmem_allocator_t *allocator, void *ptr, const size_t size) return NULL; } - ASSERT(allocator->in_scope); + ws_assert(allocator->in_scope); return allocator->wrealloc(allocator->private_data, ptr, size); } diff --git a/wsutil/wmem/wmem_interval_tree.c b/wsutil/wmem/wmem_interval_tree.c index b93f94401c..e68c7396dc 100644 --- a/wsutil/wmem/wmem_interval_tree.c +++ b/wsutil/wmem/wmem_interval_tree.c @@ -123,7 +123,7 @@ wmem_itree_insert(wmem_itree_t *tree, const guint64 low, const guint64 high, voi wmem_tree_node_t *node; wmem_range_t *range = (wmem_range_t *)wmem_new(tree->data_allocator, wmem_range_t); - ASSERT(low <= high); + ws_assert(low <= high); range->low = low; range->high = high; range->max_edge = 0; diff --git a/wsutil/wmem/wmem_stack.c b/wsutil/wmem/wmem_stack.c index ae1f695b2a..5123aad1a8 100644 --- a/wsutil/wmem/wmem_stack.c +++ b/wsutil/wmem/wmem_stack.c @@ -26,7 +26,7 @@ wmem_stack_peek(const wmem_stack_t *stack) frame = wmem_list_head(stack); - ASSERT(frame); + ws_assert(frame); return wmem_list_frame_data(frame); } diff --git a/wsutil/wmem/wmem_strbuf.c b/wsutil/wmem/wmem_strbuf.c index f04ecb7058..3b67ab7b38 100644 --- a/wsutil/wmem/wmem_strbuf.c +++ b/wsutil/wmem/wmem_strbuf.c @@ -59,7 +59,7 @@ wmem_strbuf_new_len(wmem_allocator_t *allocator, const gchar *str, size_t len) strbuf = wmem_strbuf_new_sized(allocator, alloc_size); if (str && len > 0) { - ASSERT(strbuf->alloc_size >= len + 1); + ws_assert(strbuf->alloc_size >= len + 1); memcpy(strbuf->str, str, len); strbuf->str[len] = '\0'; strbuf->len = len; @@ -130,7 +130,7 @@ wmem_strbuf_append(wmem_strbuf_t *strbuf, const gchar *str) append_len = strlen(str); wmem_strbuf_grow(strbuf, append_len); - ASSERT(WMEM_STRBUF_RAW_ROOM(strbuf) >= append_len + 1); + ws_assert(WMEM_STRBUF_RAW_ROOM(strbuf) >= append_len + 1); memcpy(&strbuf->str[strbuf->len], str, append_len); strbuf->len += append_len; strbuf->str[strbuf->len] = '\0'; @@ -194,7 +194,7 @@ wmem_strbuf_append_vprintf(wmem_strbuf_t *strbuf, const gchar *fmt, va_list ap) wmem_strbuf_grow(strbuf, want_len); want_len = _strbuf_vsnprintf(strbuf, fmt, ap); /* Second time must succeed or error out. */ - ASSERT(want_len <= 0); + ws_assert(want_len <= 0); } void diff --git a/wsutil/wmem/wmem_tree.c b/wsutil/wmem/wmem_tree.c index 045cb017a8..89c2b1afd2 100644 --- a/wsutil/wmem/wmem_tree.c +++ b/wsutil/wmem/wmem_tree.c @@ -679,7 +679,7 @@ wmem_tree_insert32_array(wmem_tree_t *tree, wmem_tree_key_t *key, void *data) } } - ASSERT(insert_tree); + ws_assert(insert_tree); wmem_tree_insert32(insert_tree, insert_key32, data); } @@ -714,7 +714,7 @@ wmem_tree_lookup32_array_helper(wmem_tree_t *tree, wmem_tree_key_t *key, } /* Assert if we didn't get any valid keys */ - ASSERT(lookup_tree); + ws_assert(lookup_tree); return (*helper)(lookup_tree, lookup_key32); }