This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/2] [asan] Allow creating/deleting hash table entries with new/delete


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]