forked from osmocom/wireshark
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.
This commit is contained in:
parent
53d51d1421
commit
a66b5080c3
|
@ -14,12 +14,7 @@
|
||||||
#define __WMEM_INT_H__
|
#define __WMEM_INT_H__
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <wsutil/ws_assert.h>
|
||||||
#ifdef WS_DEBUG
|
|
||||||
#define ASSERT(...) g_assert(__VA_ARGS__)
|
|
||||||
#else
|
|
||||||
#define ASSERT(...) (void)0
|
|
||||||
#endif /* WS_DISABLE_DEBUG */
|
|
||||||
|
|
||||||
#endif /* __WMEM_INT_H__ */
|
#endif /* __WMEM_INT_H__ */
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ wmem_alloc(wmem_allocator_t *allocator, const size_t size)
|
||||||
return g_malloc(size);
|
return g_malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(allocator->in_scope);
|
ws_assert(allocator->in_scope);
|
||||||
|
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -66,7 +66,7 @@ wmem_free(wmem_allocator_t *allocator, void *ptr)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(allocator->in_scope);
|
ws_assert(allocator->in_scope);
|
||||||
|
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -91,7 +91,7 @@ wmem_realloc(wmem_allocator_t *allocator, void *ptr, const size_t size)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(allocator->in_scope);
|
ws_assert(allocator->in_scope);
|
||||||
|
|
||||||
return allocator->wrealloc(allocator->private_data, ptr, size);
|
return allocator->wrealloc(allocator->private_data, ptr, size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ wmem_itree_insert(wmem_itree_t *tree, const guint64 low, const guint64 high, voi
|
||||||
wmem_tree_node_t *node;
|
wmem_tree_node_t *node;
|
||||||
wmem_range_t *range = (wmem_range_t *)wmem_new(tree->data_allocator, wmem_range_t);
|
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->low = low;
|
||||||
range->high = high;
|
range->high = high;
|
||||||
range->max_edge = 0;
|
range->max_edge = 0;
|
||||||
|
|
|
@ -26,7 +26,7 @@ wmem_stack_peek(const wmem_stack_t *stack)
|
||||||
|
|
||||||
frame = wmem_list_head(stack);
|
frame = wmem_list_head(stack);
|
||||||
|
|
||||||
ASSERT(frame);
|
ws_assert(frame);
|
||||||
|
|
||||||
return wmem_list_frame_data(frame);
|
return wmem_list_frame_data(frame);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
strbuf = wmem_strbuf_new_sized(allocator, alloc_size);
|
||||||
|
|
||||||
if (str && len > 0) {
|
if (str && len > 0) {
|
||||||
ASSERT(strbuf->alloc_size >= len + 1);
|
ws_assert(strbuf->alloc_size >= len + 1);
|
||||||
memcpy(strbuf->str, str, len);
|
memcpy(strbuf->str, str, len);
|
||||||
strbuf->str[len] = '\0';
|
strbuf->str[len] = '\0';
|
||||||
strbuf->len = len;
|
strbuf->len = len;
|
||||||
|
@ -130,7 +130,7 @@ wmem_strbuf_append(wmem_strbuf_t *strbuf, const gchar *str)
|
||||||
append_len = strlen(str);
|
append_len = strlen(str);
|
||||||
wmem_strbuf_grow(strbuf, append_len);
|
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);
|
memcpy(&strbuf->str[strbuf->len], str, append_len);
|
||||||
strbuf->len += append_len;
|
strbuf->len += append_len;
|
||||||
strbuf->str[strbuf->len] = '\0';
|
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);
|
wmem_strbuf_grow(strbuf, want_len);
|
||||||
want_len = _strbuf_vsnprintf(strbuf, fmt, ap);
|
want_len = _strbuf_vsnprintf(strbuf, fmt, ap);
|
||||||
/* Second time must succeed or error out. */
|
/* Second time must succeed or error out. */
|
||||||
ASSERT(want_len <= 0);
|
ws_assert(want_len <= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -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);
|
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 if we didn't get any valid keys */
|
||||||
ASSERT(lookup_tree);
|
ws_assert(lookup_tree);
|
||||||
|
|
||||||
return (*helper)(lookup_tree, lookup_key32);
|
return (*helper)(lookup_tree, lookup_key32);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue