2 * The runtime module exposes information specific to the D runtime code.
4 * Copyright: Copyright (c) 2005-2008, The D Runtime Project
5 * License: BSD Style, see LICENSE
13 extern (C) bool rt_isHalting();
15 alias bool function() ModuleUnitTester;
16 alias bool function(Object) CollectHandler;
17 alias Exception.TraceInfo function( void* ptr = null ) TraceHandler;
19 extern (C) void rt_setCollectHandler( CollectHandler h );
20 extern (C) void rt_setTraceHandler( TraceHandler h );
22 alias void delegate( Exception ) ExceptionHandler;
23 extern (C) bool rt_init( ExceptionHandler dg = null );
24 extern (C) bool rt_term( ExceptionHandler dg = null );
28 ///////////////////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////////////////
34 * This struct encapsulates all functionality related to the underlying runtime
35 * module for the calling context.
40 * Initializes the runtime. This call is to be used in instances where the
41 * standard program initialization process is not executed. This is most
42 * often in shared libraries or in libraries linked to a C program.
45 * dg = A delegate which will receive any exception thrown during the
46 * initialization process or null if such exceptions should be
50 * true if initialization succeeds and false if initialization fails.
52 static bool initialize( void delegate( Exception ) dg = null )
59 * Terminates the runtime. This call is to be used in instances where the
60 * standard program termination process will not be not executed. This is
61 * most often in shared libraries or in libraries linked to a C program.
64 * dg = A delegate which will receive any exception thrown during the
65 * termination process or null if such exceptions should be
69 * true if termination succeeds and false if termination fails.
71 static bool terminate( void delegate( Exception ) dg = null )
78 * Returns true if the runtime is halting. Under normal circumstances,
79 * this will be set between the time that normal application code has
80 * exited and before module dtors are called.
83 * true if the runtime is halting.
85 static bool isHalting()
87 return rt_isHalting();
92 * Overrides the default trace mechanism with s user-supplied version. A
93 * trace represents the context from which an exception was thrown, and the
94 * trace handler will be called when this occurs. The pointer supplied to
95 * this routine indicates the base address from which tracing should occur.
96 * If the supplied pointer is null then the trace routine should determine
97 * an appropriate calling context from which to begin the trace.
100 * h = The new trace handler. Set to null to use the default handler.
102 static void traceHandler( TraceHandler h )
104 rt_setTraceHandler( h );
109 * Overrides the default collect hander with a user-supplied version. This
110 * routine will be called for each resource object that is finalized in a
111 * non-deterministic manner--typically during a garbage collection cycle.
112 * If the supplied routine returns true then the object's dtor will called
113 * as normal, but if the routine returns false than the dtor will not be
114 * called. The default behavior is for all object dtors to be called.
117 * h = The new collect handler. Set to null to use the default handler.
119 static void collectHandler( CollectHandler h )
121 rt_setCollectHandler( h );
126 * Overrides the default module unit tester with a user-supplied version.
127 * This routine will be called once on program initialization. The return
128 * value of this routine indicates to the runtime whether the body of the
129 * program will be executed.
132 * h = The new unit tester. Set to null to use the default unit tester.
134 static void moduleUnitTester( ModuleUnitTester h )
136 sm_moduleUnitTester = h;
141 static ModuleUnitTester sm_moduleUnitTester = null;
145 ///////////////////////////////////////////////////////////////////////////////
146 // Overridable Callbacks
147 ///////////////////////////////////////////////////////////////////////////////
151 * This routine is called by the runtime to run module unit tests on startup.
152 * The user-supplied unit tester will be called if one has been supplied,
153 * otherwise all unit tests will be run in sequence.
156 * true if execution should continue after testing is complete and false if
157 * not. Default behavior is to return true.
159 extern (C) bool runModuleUnitTests()
161 if( Runtime.sm_moduleUnitTester is null )
163 foreach( m; ModuleInfo )
170 return Runtime.sm_moduleUnitTester();