This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 1/2] [asan] Allow creating/deleting hash table entries with new/delete
- From: Dodji Seketeli <dodji at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Jakub Jelinek <jakub at redhat dot com>, Kostya Serebryany <kcc at google dot com>, Dmitry Vyukov <dvyukov at google dot com>, Diego Novillo <dnovillo at google dot com>, Lawrence Crowl <crowl at googlers dot com>
- Date: Mon, 28 Jan 2013 22:30:08 +0100
- Subject: [PATCH 1/2] [asan] Allow creating/deleting hash table entries with new/delete
- References: <87mwvtxalf.fsf@redhat.com>
Hello,
The hash table type can handle creation and removal of entries with
malloc/free. This patchlet adds support for using new/delete. It's
useful for hash table entry types that have constructors (and/or
destructors), to prevent the user from having to type boilerplate code
to initialize them over and over again. This is used by the patch that
follows this one.
gcc/
* hash-table.h (struct typed_delete_remove): New type.
(typed_delete_remove::remove): Implement this using the delete
operator.
---
gcc/hash-table.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/gcc/hash-table.h b/gcc/hash-table.h
index 206423d..884840c 100644
--- a/gcc/hash-table.h
+++ b/gcc/hash-table.h
@@ -235,6 +235,22 @@ typed_free_remove <Type>::remove (Type *p)
free (p);
}
+/* Helpful type for removing entries with the delete operator. */
+
+template <typename Type>
+struct typed_delete_remove
+{
+ static inline void remove (Type *p);
+};
+
+/* Remove with delete. */
+
+template <typename Type>
+inline void
+typed_delete_remove <Type>::remove (Type *p)
+{
+ delete p;
+}
/* Helpful type for a no-op remove. */
--
1.7.11.7
--
Dodji