New class allocate_on_obstack

This patch adds a new class allocate_on_obstack, and let dwarf2_per_objfile
inherit it, so that dwarf2_per_objfile is automatically allocated on
obstack, and "delete dwarf2_per_objfile" doesn't de-allocate any space.

gdb:

2018-02-16  Yao Qi  <yao.qi@linaro.org>

	* block.c (block_namespace_info): Inherit allocate_on_obstack.
	(block_initialize_namespace): Use new.
	* dwarf2read.c (dwarf2_per_objfile): Inherit allocate_on_obstack.
	(dwarf2_free_objfile): Use delete.
	* gdbtypes.c (type_pair): Inherit allocate_on_obstack.
	(copy_type_recursive): Use new.
	* gdb_obstack.h (allocate_on_obstack): New.
This commit is contained in:
Yao Qi 2018-02-16 16:20:58 +00:00
parent 75cdede099
commit fd90ace4c1
5 changed files with 50 additions and 24 deletions

View file

@ -78,4 +78,24 @@ struct auto_obstack : obstack
{ obstack_free (this, obstack_base (this)); }
};
/* Objects are allocated on obstack instead of heap. */
struct allocate_on_obstack
{
allocate_on_obstack () = default;
void* operator new (size_t size, struct obstack *obstack)
{
return obstack_alloc (obstack, size);
}
void* operator new[] (size_t size, struct obstack *obstack)
{
return obstack_alloc (obstack, size);
}
void operator delete (void *memory) {}
void operator delete[] (void *memory) {}
};
#endif