From patchwork Mon Jan 28 21:30:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1/2, asan] Allow creating/deleting hash table entries with new/delete Date: Mon, 28 Jan 2013 11:30:08 -0000 From: Dodji Seketeli X-Patchwork-Id: 216375 Message-Id: <87ip6hxafz.fsf@redhat.com> To: GCC Patches Cc: Jakub Jelinek , Kostya Serebryany , Dmitry Vyukov , Diego Novillo , Lawrence Crowl 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 ::remove (Type *p) free (p); } +/* Helpful type for removing entries with the delete operator. */ + +template +struct typed_delete_remove +{ + static inline void remove (Type *p); +}; + +/* Remove with delete. */ + +template +inline void +typed_delete_remove ::remove (Type *p) +{ + delete p; +} /* Helpful type for a no-op remove. */