1 /*
2 * Copyright (c) 2018-2020 Ivan Maidanski
3 *
4 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
6 *
7 * Permission is hereby granted to use or copy this program
8 * for any purpose, provided the above notices are retained on all copies.
9 * Permission to modify the code and to distribute modified code is granted,
10 * provided the above notices are retained, and a notice that the code was
11 * modified is included with the above copyright notice.
12 *
13 */
14 15 // This file provides the implementation of `GC_throw_bad_alloc()` which
16 // is invoked by the collector operator `new` in case of an out-of-memory
17 // event.
18 19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #endif
22 23 #ifndef GC_BUILD
24 # define GC_BUILD
25 #endif
26 27 #define GC_DONT_INCL_WINDOWS_H
28 #include "gc/gc.h"
29 30 #include <new> /*< for `bad_alloc`, precedes include of `gc_cpp.h` file */
31 32 #if defined(GC_NEW_ABORTS_ON_OOM) || defined(_LIBCPP_NO_EXCEPTIONS)
33 # define GC_ALLOCATOR_THROW_OR_ABORT() GC_abort_on_oom()
34 #else
35 # define GC_ALLOCATOR_THROW_OR_ABORT() throw std::bad_alloc()
36 #endif
37 38 GC_API GC_OOM_ABORT_THROW_ATTRIBUTE void GC_CALL
39 GC_throw_bad_alloc()
40 {
41 GC_ALLOCATOR_THROW_OR_ABORT();
42 }
43