[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r9946: Apparently some compilers think that anonymous unions are ba (in tor/trunk: . src/common)



Author: nickm
Date: 2007-04-11 15:58:51 -0400 (Wed, 11 Apr 2007)
New Revision: 9946

Modified:
   tor/trunk/
   tor/trunk/src/common/mempool.c
Log:
 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.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r12353] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/common/mempool.c
===================================================================
--- tor/trunk/src/common/mempool.c	2007-04-11 16:28:44 UTC (rev 9945)
+++ tor/trunk/src/common/mempool.c	2007-04-11 19:58:51 UTC (rev 9946)
@@ -116,7 +116,7 @@
     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 @@
 
 /** 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 @@
   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 @@
     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 @@
   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 @@
 
   /* 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(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)