forked from osmocom/wireshark
wmem: Remove dependency on wsutil
This allows wsutil to depend on wmem without introducing a circular dependency. Although wmem is included in epan it is in many ways an independent library and it should remain so.
This commit is contained in:
parent
6498f1fce5
commit
2dee8a3a29
|
@ -19,8 +19,6 @@
|
|||
#include "wmem_allocator.h"
|
||||
#include "wmem_allocator_simple.h"
|
||||
|
||||
#include <wsutil/ws_assert.h>
|
||||
|
||||
#define DEFAULT_ALLOCS 8192
|
||||
|
||||
typedef struct _wmem_simple_allocator_t {
|
||||
|
@ -65,7 +63,7 @@ wmem_simple_free(void *private_data, void *ptr)
|
|||
}
|
||||
}
|
||||
|
||||
ws_assert_not_reached();
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
static void *
|
||||
|
@ -82,7 +80,9 @@ wmem_simple_realloc(void *private_data, void *ptr, const size_t size)
|
|||
}
|
||||
}
|
||||
|
||||
ws_assert_not_reached();
|
||||
g_assert_not_reached();
|
||||
/* not reached */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
#include "wmem_core.h"
|
||||
#include "wmem_array.h"
|
||||
|
||||
#include <wsutil/ws_assert.h>
|
||||
|
||||
/* Holds a wmem-allocated array.
|
||||
* elem_len is the size of each element
|
||||
* elem_count is the number of used elements
|
||||
|
@ -129,7 +127,7 @@ wmem_array_append(wmem_array_t *array, const void *in, guint count)
|
|||
void *
|
||||
wmem_array_index(wmem_array_t *array, guint array_index)
|
||||
{
|
||||
ws_abort_if_fail(array_index < array->elem_count);
|
||||
g_assert(array_index < array->elem_count);
|
||||
return &array->buf[array_index * array->elem_size];
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#define WS_LOG_DOMAIN "wmem"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
|
@ -25,9 +23,6 @@
|
|||
#include "wmem_allocator_block_fast.h"
|
||||
#include "wmem_allocator_strict.h"
|
||||
|
||||
#include <wsutil/ws_assert.h>
|
||||
#include <wsutil/wslog.h>
|
||||
|
||||
/* Set according to the WIRESHARK_DEBUG_WMEM_OVERRIDE environment variable in
|
||||
* wmem_init. Should not be set again. */
|
||||
static gboolean do_override = FALSE;
|
||||
|
@ -40,7 +35,7 @@ wmem_alloc(wmem_allocator_t *allocator, const size_t size)
|
|||
return g_malloc(size);
|
||||
}
|
||||
|
||||
ws_assert(allocator->in_scope);
|
||||
g_assert(allocator->in_scope);
|
||||
|
||||
if (size == 0) {
|
||||
return NULL;
|
||||
|
@ -71,7 +66,7 @@ wmem_free(wmem_allocator_t *allocator, void *ptr)
|
|||
return;
|
||||
}
|
||||
|
||||
ws_assert(allocator->in_scope);
|
||||
g_assert(allocator->in_scope);
|
||||
|
||||
if (ptr == NULL) {
|
||||
return;
|
||||
|
@ -96,7 +91,7 @@ wmem_realloc(wmem_allocator_t *allocator, void *ptr, const size_t size)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ws_assert(allocator->in_scope);
|
||||
g_assert(allocator->in_scope);
|
||||
|
||||
return allocator->wrealloc(allocator->private_data, ptr, size);
|
||||
}
|
||||
|
@ -162,7 +157,7 @@ wmem_allocator_new(const wmem_allocator_type_t type)
|
|||
wmem_strict_allocator_init(allocator);
|
||||
break;
|
||||
default:
|
||||
ws_assert_not_reached();
|
||||
g_assert_not_reached();
|
||||
break;
|
||||
};
|
||||
|
||||
|
@ -198,7 +193,7 @@ wmem_init(void)
|
|||
override_type = WMEM_ALLOCATOR_BLOCK_FAST;
|
||||
}
|
||||
else {
|
||||
ws_warning("Unrecognized wmem override");
|
||||
g_warning("Unrecognized wmem override");
|
||||
do_override = FALSE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
#include "wmem_interval_tree.h"
|
||||
#include "wmem_user_cb.h"
|
||||
|
||||
#include <wsutil/ws_assert.h>
|
||||
|
||||
|
||||
static void
|
||||
print_range(const void *value)
|
||||
|
@ -122,7 +120,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);
|
||||
|
||||
ws_assert(low <= high);
|
||||
g_assert(low <= high);
|
||||
range->low = low;
|
||||
range->high = high;
|
||||
range->max_edge = 0;
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
#include "wmem_scopes.h"
|
||||
#include "wmem_allocator.h"
|
||||
|
||||
#include <wsutil/ws_assert.h>
|
||||
|
||||
/* One of the supposed benefits of wmem over the old emem was going to be that
|
||||
* the scoping of the various memory pools would be obvious, since they would
|
||||
* no longer be global. Instead, the pools would be managed as variables scoped
|
||||
|
@ -47,7 +45,7 @@ static wmem_allocator_t *epan_scope = NULL;
|
|||
wmem_allocator_t *
|
||||
wmem_packet_scope(void)
|
||||
{
|
||||
ws_assert(packet_scope);
|
||||
g_assert(packet_scope);
|
||||
|
||||
return packet_scope;
|
||||
}
|
||||
|
@ -55,9 +53,9 @@ wmem_packet_scope(void)
|
|||
void
|
||||
wmem_enter_packet_scope(void)
|
||||
{
|
||||
ws_assert(packet_scope);
|
||||
ws_assert(file_scope->in_scope);
|
||||
ws_assert(!packet_scope->in_scope);
|
||||
g_assert(packet_scope);
|
||||
g_assert(file_scope->in_scope);
|
||||
g_assert(!packet_scope->in_scope);
|
||||
|
||||
packet_scope->in_scope = TRUE;
|
||||
}
|
||||
|
@ -65,8 +63,8 @@ wmem_enter_packet_scope(void)
|
|||
void
|
||||
wmem_leave_packet_scope(void)
|
||||
{
|
||||
ws_assert(packet_scope);
|
||||
ws_assert(packet_scope->in_scope);
|
||||
g_assert(packet_scope);
|
||||
g_assert(packet_scope->in_scope);
|
||||
|
||||
wmem_free_all(packet_scope);
|
||||
packet_scope->in_scope = FALSE;
|
||||
|
@ -77,7 +75,7 @@ wmem_leave_packet_scope(void)
|
|||
wmem_allocator_t *
|
||||
wmem_file_scope(void)
|
||||
{
|
||||
ws_assert(file_scope);
|
||||
g_assert(file_scope);
|
||||
|
||||
return file_scope;
|
||||
}
|
||||
|
@ -85,8 +83,8 @@ wmem_file_scope(void)
|
|||
void
|
||||
wmem_enter_file_scope(void)
|
||||
{
|
||||
ws_assert(file_scope);
|
||||
ws_assert(!file_scope->in_scope);
|
||||
g_assert(file_scope);
|
||||
g_assert(!file_scope->in_scope);
|
||||
|
||||
file_scope->in_scope = TRUE;
|
||||
}
|
||||
|
@ -94,9 +92,9 @@ wmem_enter_file_scope(void)
|
|||
void
|
||||
wmem_leave_file_scope(void)
|
||||
{
|
||||
ws_assert(file_scope);
|
||||
ws_assert(file_scope->in_scope);
|
||||
ws_assert(!packet_scope->in_scope);
|
||||
g_assert(file_scope);
|
||||
g_assert(file_scope->in_scope);
|
||||
g_assert(!packet_scope->in_scope);
|
||||
|
||||
wmem_free_all(file_scope);
|
||||
file_scope->in_scope = FALSE;
|
||||
|
@ -111,7 +109,7 @@ wmem_leave_file_scope(void)
|
|||
wmem_allocator_t *
|
||||
wmem_epan_scope(void)
|
||||
{
|
||||
ws_assert(epan_scope);
|
||||
g_assert(epan_scope);
|
||||
|
||||
return epan_scope;
|
||||
}
|
||||
|
@ -121,9 +119,9 @@ wmem_epan_scope(void)
|
|||
void
|
||||
wmem_init_scopes(void)
|
||||
{
|
||||
ws_assert(packet_scope == NULL);
|
||||
ws_assert(file_scope == NULL);
|
||||
ws_assert(epan_scope == NULL);
|
||||
g_assert(packet_scope == NULL);
|
||||
g_assert(file_scope == NULL);
|
||||
g_assert(epan_scope == NULL);
|
||||
|
||||
packet_scope = wmem_allocator_new(WMEM_ALLOCATOR_BLOCK_FAST);
|
||||
file_scope = wmem_allocator_new(WMEM_ALLOCATOR_BLOCK);
|
||||
|
@ -137,12 +135,12 @@ wmem_init_scopes(void)
|
|||
void
|
||||
wmem_cleanup_scopes(void)
|
||||
{
|
||||
ws_assert(packet_scope);
|
||||
ws_assert(file_scope);
|
||||
ws_assert(epan_scope);
|
||||
g_assert(packet_scope);
|
||||
g_assert(file_scope);
|
||||
g_assert(epan_scope);
|
||||
|
||||
ws_assert(packet_scope->in_scope == FALSE);
|
||||
ws_assert(file_scope->in_scope == FALSE);
|
||||
g_assert(packet_scope->in_scope == FALSE);
|
||||
g_assert(file_scope->in_scope == FALSE);
|
||||
|
||||
wmem_destroy_allocator(packet_scope);
|
||||
wmem_destroy_allocator(file_scope);
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
#include "wmem_stack.h"
|
||||
#include "wmem_list.h"
|
||||
|
||||
#include <wsutil/ws_assert.h>
|
||||
|
||||
/* Wmem stack is implemented as a simple wrapper over Wmem list */
|
||||
|
||||
void *
|
||||
|
@ -27,7 +25,7 @@ wmem_stack_peek(const wmem_stack_t *stack)
|
|||
|
||||
frame = wmem_list_head(stack);
|
||||
|
||||
ws_assert(frame);
|
||||
g_assert(frame);
|
||||
|
||||
return wmem_list_frame_data(frame);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
*/
|
||||
|
||||
#include "config.h"
|
||||
#define WS_LOG_DOMAIN "wmem"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
@ -20,9 +19,6 @@
|
|||
#include "wmem_core.h"
|
||||
#include "wmem_strbuf.h"
|
||||
|
||||
#include <wsutil/ws_assert.h>
|
||||
#include <wsutil/wslog.h>
|
||||
|
||||
#define DEFAULT_MINIMUM_LEN 16
|
||||
|
||||
/* Holds a wmem-allocated string-buffer.
|
||||
|
@ -56,7 +52,7 @@ wmem_strbuf_sized_new(wmem_allocator_t *allocator,
|
|||
{
|
||||
wmem_strbuf_t *strbuf;
|
||||
|
||||
ws_assert((max_len == 0) || (alloc_len <= max_len));
|
||||
g_assert((max_len == 0) || (alloc_len <= max_len));
|
||||
|
||||
strbuf = wmem_new(allocator, wmem_strbuf_t);
|
||||
|
||||
|
@ -179,7 +175,7 @@ int _strbuf_vsnprintf(wmem_strbuf_t *strbuf, const char *format, va_list ap, gbo
|
|||
want_len = vsnprintf(buffer, buffer_size, format, ap);
|
||||
if (want_len < 0) {
|
||||
/* Error. */
|
||||
ws_warning("%s: vsnprintf (%d): %s", G_STRFUNC, want_len, g_strerror(errno));
|
||||
g_warning("%s: vsnprintf: (%d) %s", G_STRFUNC, want_len, g_strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if ((size_t)want_len < buffer_size) {
|
||||
|
@ -194,7 +190,7 @@ int _strbuf_vsnprintf(wmem_strbuf_t *strbuf, const char *format, va_list ap, gbo
|
|||
}
|
||||
else {
|
||||
strbuf->len += buffer_size - 1; /* Append. */
|
||||
ws_assert(strbuf->len == strbuf->alloc_len - 1);
|
||||
g_assert(strbuf->len == strbuf->alloc_len - 1);
|
||||
}
|
||||
|
||||
return want_len; /* Length (not including terminating null) that would be written
|
||||
|
|
|
@ -22,9 +22,6 @@
|
|||
#include "wmem_tree-int.h"
|
||||
#include "wmem_user_cb.h"
|
||||
|
||||
#include <wsutil/ws_assert.h>
|
||||
|
||||
|
||||
|
||||
static wmem_tree_node_t *
|
||||
node_uncle(wmem_tree_node_t *node)
|
||||
|
@ -662,7 +659,7 @@ wmem_tree_insert32_array(wmem_tree_t *tree, wmem_tree_key_t *key, void *data)
|
|||
}
|
||||
}
|
||||
|
||||
ws_assert(insert_tree);
|
||||
g_assert(insert_tree);
|
||||
|
||||
wmem_tree_insert32(insert_tree, insert_key32, data);
|
||||
}
|
||||
|
@ -697,7 +694,7 @@ wmem_tree_lookup32_array_helper(wmem_tree_t *tree, wmem_tree_key_t *key,
|
|||
}
|
||||
|
||||
/* Assert if we didn't get any valid keys */
|
||||
ws_assert(lookup_tree);
|
||||
g_assert(lookup_tree);
|
||||
|
||||
return (*helper)(lookup_tree, lookup_key32);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue