]> granicus.if.org Git - gc/commit
Never return null by C++ GC allocators
authorIvan Maidanski <ivmai@mail.ru>
Wed, 6 Jun 2018 22:08:07 +0000 (01:08 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 6 Jun 2018 22:08:07 +0000 (01:08 +0300)
commitc89559ba82563f00de01f5fb5573320ef2eb80ec
treea26eeb25e765570dd9f7211b336169660d6e57df
parente95f456d24127749a19fa18387e915de9f59e677
Never return null by C++ GC allocators

Now, in case of the allocation failure, the allocators (defined in
gc_allocator.h or new_gc_alloc.h) throw bad_alloc (or abort the
application if compiled without exceptions support).

* include/gc_allocator.h (GC_ALLOCATOR_THROW_OR_ABORT): New macro
(either throws bad_alloc or calls GC_abort_on_oom).
* include/gc_allocator.h (GC_selective_alloc,
traceable_allocator::allocate): Call GC_ALLOCATOR_THROW_OR_ABORT() if
the allocation failed.
* include/new_gc_alloc.h (GC_ALLOCATOR_THROW_OR_ABORT): New macro
(redirected to GC_abort_on_oom).
* include/new_gc_alloc.h (GC_out_of_line_malloc,
single_client_gc_alloc_template::allocate,
single_client_gc_alloc_template::ptr_free_allocate,
single_client_traceable_alloc_template::allocate,
single_client_traceable_alloc_template::ptr_free_allocate,
gc_alloc_template::allocate, gc_alloc_template::ptr_free_allocate,
traceable_alloc_template::allocate,
traceable_alloc_template::ptr_free_allocate): Call
GC_ALLOCATOR_THROW_OR_ABORT() instead of returning 0.
* include/new_gc_alloc.h (simple_alloc::allocate): If n is 0 then
allocate 1 byte.
* include/new_gc_alloc.h (simple_alloc::deallocate): If n is 0 then
call ptr_free_deallocate for 1-byte object.
include/gc_allocator.h
include/new_gc_alloc.h