Reintroduce wmem_allocator_force_new

We now have to call wmem_init in order to randomly seed the values for wmem_map.
This means we can no longer rely on the lack of override, so we have to force
the right allocator type when testing/timing the allocators themselves.

Change-Id: I005034465b0a98f19876899b96ef65b3e4b1d759
Reviewed-on: https://code.wireshark.org/review/1468
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Evan Huus 2014-05-02 10:09:13 -04:00 committed by Anders Broman
parent f181756640
commit abc387934b

View file

@ -38,6 +38,40 @@
typedef void (*wmem_verify_func)(wmem_allocator_t *allocator);
/* A local copy of wmem_allocator_new that ignores the
* WIRESHARK_DEBUG_WMEM_OVERRIDE variable so that test functions are
* guaranteed to actually get the allocator type they asked for */
static wmem_allocator_t *
wmem_allocator_force_new(const wmem_allocator_type_t type)
{
wmem_allocator_t *allocator;
allocator = wmem_new(NULL, wmem_allocator_t);
allocator->type = type;
allocator->callbacks = NULL;
allocator->in_scope = TRUE;
switch (type) {
case WMEM_ALLOCATOR_SIMPLE:
wmem_simple_allocator_init(allocator);
break;
case WMEM_ALLOCATOR_BLOCK:
wmem_block_allocator_init(allocator);
break;
case WMEM_ALLOCATOR_STRICT:
wmem_strict_allocator_init(allocator);
break;
default:
g_assert_not_reached();
/* This is necessary to squelch MSVC errors; is there
any way to tell it that g_assert_not_reached()
never returns? */
return NULL;
};
return allocator;
}
/* A helper for generating pseudo-random strings. Just uses glib's random number
* functions to generate 'numbers' in the printable character range. */
static gchar *
@ -200,9 +234,7 @@ wmem_test_allocator(wmem_allocator_type_t type, wmem_verify_func verify)
char *ptrs[MAX_SIMULTANEOUS_ALLOCS];
wmem_allocator_t *allocator;
/* We never run wmem_init so we don't have to worry about overrides giving
* us the wrong type. */
allocator = wmem_allocator_new(type);
allocator = wmem_allocator_force_new(type);
if (verify) (*verify)(allocator);
@ -303,7 +335,7 @@ wmem_time_allocator(wmem_allocator_type_t type)
int i, j;
wmem_allocator_t *allocator;
allocator = wmem_allocator_new(type);
allocator = wmem_allocator_force_new(type);
for (j=0; j<128; j++) {
for (i=0; i<MAX_SIMULTANEOUS_ALLOCS; i++) {