2 * Exception allocation, cloning, and release compiler support routines.
4 * Copyright: Copyright (c) 2017 by D Language Foundation
5 * License: Distributed under the
6 * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
7 * (See accompanying file LICENSE)
8 * Authors: Walter Bright
9 * Source: $(DRUNTIMESRC rt/_ehalloc.d)
18 import core.stdc.stdio;
22 /********************************************
23 * Delete exception instance `t` from the exception pool.
24 * Must have been allocated with `_d_newThrowable()`.
25 * This is meant to be called at the close of a catch block.
26 * It's nothrow because otherwise any function with a catch block could
32 nothrow extern (C) void _d_delThrowable(Throwable t)
36 debug(PRINTF) printf("_d_delThrowable(%p)\n", t);
38 /* If allocated by the GC, don't free it.
39 * Let the GC handle it.
40 * Supporting this is necessary while transitioning
41 * to this new scheme for allocating exceptions.
43 auto refcount = t.refcount();
45 return; // it was allocated by the GC
48 assert(0); // no zombie objects
50 t.refcount() = --refcount;
54 TypeInfo_Class **pc = cast(TypeInfo_Class **)t;
57 TypeInfo_Class ci = **pc;
59 if (!(ci.m_flags & TypeInfo_Class.ClassFlags.noPointers))
61 // Inform the GC about the pointers in the object instance
62 import core.memory : GC;
63 GC.removeRange(cast(void*) t);
69 import rt.lifetime : rt_finalize;
70 rt_finalize(cast(void*) t);
74 assert(0); // should never happen since Throwable.~this() is nothrow
76 import core.stdc.stdlib : free;
77 debug(PRINTF) printf("free(%p)\n", t);