aboutsummaryrefslogtreecommitdiff
path: root/src/common/mempool.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-04-11 19:58:51 +0000
committerNick Mathewson <nickm@torproject.org>2007-04-11 19:58:51 +0000
commit7467c35249836510f3cca0a753855e96af8ecb8d (patch)
treea00be020de54301fd551eba1f4bf4adc76c69358 /src/common/mempool.c
parent795aa1a196630f8b574d69e07ffb353ebeb40ad9 (diff)
downloadtor-7467c35249836510f3cca0a753855e96af8ecb8d.tar
tor-7467c35249836510f3cca0a753855e96af8ecb8d.tar.gz
r12353@catbus: nickm | 2007-04-11 15:58:46 -0400
Apparently some compilers think that anonymous unions are bad C. Technically, they're right, so let's name the union in mempool.c. svn:r9946
Diffstat (limited to 'src/common/mempool.c')
-rw-r--r--src/common/mempool.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/common/mempool.c b/src/common/mempool.c
index ca196530d..673cf21e8 100644
--- a/src/common/mempool.c
+++ b/src/common/mempool.c
@@ -116,7 +116,7 @@ struct mp_allocated_t {
char mem[1];
/** An extra element to the union to insure correct alignment. */
ALIGNMENT_TYPE _dummy;
- };
+ } u;
};
/** 'Magic' value used to detect memory corruption. */
@@ -146,10 +146,10 @@ struct mp_chunk_t {
/** Given a pointer to a mp_allocated_t, return a pointer to the memory
* item it holds. */
-#define A2M(a) (&(a)->mem[0])
+#define A2M(a) (&(a)->u.mem)
/** Given a pointer to a memory_item_t, return a pointer to its enclosing
* mp_allocated_t. */
-#define M2A(p) ( ((char*)p) - STRUCT_OFFSET(mp_allocated_t, mem) )
+#define M2A(p) ( ((char*)p) - STRUCT_OFFSET(mp_allocated_t, u.mem) )
#ifdef ALLOC_CAN_RETURN_NULL
/** If our ALLOC() macro can return NULL, check whether <b>x</b> is NULL,
@@ -230,8 +230,8 @@ mp_pool_get(mp_pool_t *pool)
if (chunk->first_free) {
/* If there's anything on the chunk's freelist, unlink it and use it. */
allocated = chunk->first_free;
- chunk->first_free = allocated->next_free;
- allocated->next_free = NULL; /* For debugging; not really needed. */
+ chunk->first_free = allocated->u.next_free;
+ allocated->u.next_free = NULL; /* For debugging; not really needed. */
ASSERT(allocated->in_chunk == chunk);
} else {
/* Otherwise, the chunk had better have some free space left on it. */
@@ -243,7 +243,7 @@ mp_pool_get(mp_pool_t *pool)
allocated = (void*)chunk->next_mem;
chunk->next_mem += pool->item_alloc_size;
allocated->in_chunk = chunk;
- allocated->next_free = NULL; /* For debugging; not really needed. */
+ allocated->u.next_free = NULL; /* For debugging; not really needed. */
}
++chunk->n_allocated;
@@ -280,7 +280,7 @@ mp_pool_release(void *item)
ASSERT(chunk->magic == MP_CHUNK_MAGIC);
ASSERT(chunk->n_allocated > 0);
- allocated->next_free = chunk->first_free;
+ allocated->u.next_free = chunk->first_free;
chunk->first_free = allocated;
if (PREDICT_UNLIKELY(chunk->n_allocated == chunk->capacity)) {
@@ -344,7 +344,7 @@ mp_pool_new(size_t item_size, size_t chunk_capacity)
/* First, we figure out how much space to allow per item. We'll want to
* use make sure we have enough for the overhead plus the item size. */
- alloc_size = STRUCT_OFFSET(mp_allocated_t, mem) + item_size;
+ alloc_size = STRUCT_OFFSET(mp_allocated_t, u.mem) + item_size;
/* If the item_size is less than sizeof(next_free), we need to make
* the allocation bigger. */
if (alloc_size < sizeof(mp_allocated_t))
@@ -450,7 +450,7 @@ assert_chunks_ok(mp_pool_t *pool, mp_chunk_t *chunk, int empty, int full)
ASSERT(chunk->magic == MP_CHUNK_MAGIC);
ASSERT(chunk->pool == pool);
for (allocated = chunk->first_free; allocated;
- allocated = allocated->next_free) {
+ allocated = allocated->u.next_free) {
ASSERT(allocated->in_chunk == chunk);
}
if (empty)