Skip to content

Commit f9c6346

Browse files
committed
Merge pull request #587 from dawgfoto/refactorMain
reuse rt_init/rt_term in main
2 parents 02b8a19 + e00f772 commit f9c6346

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

src/rt/dmain2.d

+5-25
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ extern (C) bool rt_init(ExceptionHandler dg = null)
243243
initStaticDataGC();
244244
rt_moduleCtor();
245245
rt_moduleTlsCtor();
246-
runModuleUnitTests();
247246
return true;
248247
}
249248
catch (Throwable e)
@@ -375,9 +374,6 @@ extern (C) int _d_run_main(int argc, char **argv, MainFunc mainFunc)
375374
}
376375
}
377376

378-
_STI_monitor_staticctor();
379-
_STI_critical_init();
380-
381377
// Allocate args[] on the stack
382378
char[][] args = (cast(char[]*) alloca(argc * (char[]).sizeof))[0 .. argc];
383379

@@ -552,35 +548,19 @@ extern (C) int _d_run_main(int argc, char **argv, MainFunc mainFunc)
552548
// the user's main function. If main terminates with an exception,
553549
// the exception is handled and then cleanup begins. An exception
554550
// thrown during cleanup, however, will abort the cleanup process.
555-
556-
void runMain()
557-
{
558-
result = mainFunc(args);
559-
}
560-
561551
void runAll()
562552
{
563-
initSections();
564-
gc_init();
565-
initStaticDataGC();
566-
rt_moduleCtor();
567-
rt_moduleTlsCtor();
568-
if (runModuleUnitTests())
569-
tryExec(&runMain);
553+
if (rt_init() && runModuleUnitTests())
554+
tryExec({ result = mainFunc(args); });
570555
else
571556
result = EXIT_FAILURE;
572-
rt_moduleTlsDtor();
573-
thread_joinAll();
574-
rt_moduleDtor();
575-
gc_term();
576-
finiSections();
557+
558+
if (!rt_term())
559+
result = (result == EXIT_SUCCESS) ? EXIT_FAILURE : result;
577560
}
578561

579562
tryExec(&runAll);
580563

581-
_STD_critical_term();
582-
_STD_monitor_staticdtor();
583-
584564
// Issue 10344: flush stdout and return nonzero on failure
585565
if (.fflush(.stdout) != 0)
586566
{

0 commit comments

Comments
 (0)