From ed727b2279dd36e2fbf1ab6956270cbd487b1a01 Mon Sep 17 00:00:00 2001
From: Mikhail Maltsev <maltsevm@gmail.com>
Date: Sun, 4 Oct 2015 22:50:40 +0300
Subject: [PATCH 5/9] Allocators
---
gcc/alloc-pool.h | 45 ++++++++++++++++++++++-----------------------
1 file changed, 22 insertions(+), 23 deletions(-)
@@ -275,15 +275,16 @@ base_pool_allocator <TBlockAllocator>::initialize ()
m_elts_per_block = (TBlockAllocator::block_size - header_size) / size;
gcc_checking_assert (m_elts_per_block != 0);
-#ifdef ENABLE_CHECKING
- /* Increase the last used ID and use it for this pool.
- ID == 0 is used for free elements of pool so skip it. */
- last_id++;
- if (last_id == 0)
- last_id++;
-
- m_id = last_id;
-#endif
+ if (CHECKING_P)
+ {
+ /* Increase the last used ID and use it for this pool.
+ ID == 0 is used for free elements of pool so skip it. */
+ last_id++;
+ if (last_id == 0)
+ last_id++;
+
+ m_id = last_id;
+ }
}
/* Free all memory allocated for the given memory pool. */
@@ -387,10 +388,9 @@ base_pool_allocator <TBlockAllocator>::allocate ()
block = m_virgin_free_list;
header = (allocation_pool_list*) allocation_object::get_data (block);
header->next = NULL;
-#ifdef ENABLE_CHECKING
- /* Mark the element to be free. */
- ((allocation_object*) block)->id = 0;
-#endif
+ if (CHECKING_P)
+ /* Mark the element to be free. */
+ ((allocation_object*) block)->id = 0;
VALGRIND_DISCARD (VALGRIND_MAKE_MEM_NOACCESS (header,size));
m_returned_free_list = header;
m_virgin_free_list += m_elt_size;
@@ -404,10 +404,9 @@ base_pool_allocator <TBlockAllocator>::allocate ()
m_returned_free_list = header->next;
m_elts_free--;
-#ifdef ENABLE_CHECKING
/* Set the ID for element. */
- allocation_object::get_instance (header)->id = m_id;
-#endif
+ if (CHECKING_P)
+ allocation_object::get_instance (header)->id = m_id;
VALGRIND_DISCARD (VALGRIND_MAKE_MEM_UNDEFINED (header, size));
return (void *)(header);
@@ -424,18 +423,18 @@ base_pool_allocator <TBlockAllocator>::remove (void *object)
int size ATTRIBUTE_UNUSED;
size = m_elt_size - offsetof (allocation_object, u.data);
-#ifdef ENABLE_CHECKING
- gcc_assert (object
+ gcc_checking_assert (object
/* Check if we free more than we allocated, which is Bad (TM). */
&& m_elts_free < m_elts_allocated
/* Check whether the PTR was allocated from POOL. */
&& m_id == allocation_object::get_instance (object)->id);
- memset (object, 0xaf, size);
-
- /* Mark the element to be free. */
- allocation_object::get_instance (object)->id = 0;
-#endif
+ if (CHECKING_P)
+ {
+ memset (object, 0xaf, size);
+ /* Mark the element to be free. */
+ allocation_object::get_instance (object)->id = 0;
+ }
header = (allocation_pool_list*) object;
header->next = m_returned_free_list;
--
2.1.4