Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #587 from dawgfoto/refactorMain
Browse files Browse the repository at this point in the history
reuse rt_init/rt_term in main
  • Loading branch information
Alex Rønne Petersen committed Aug 27, 2013
2 parents c1f8bea + e00f772 commit 2c6c29b
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions src/rt/dmain2.d
Expand Up @@ -243,7 +243,6 @@ extern (C) bool rt_init(ExceptionHandler dg = null)
initStaticDataGC();
rt_moduleCtor();
rt_moduleTlsCtor();
runModuleUnitTests();
return true;
}
catch (Throwable e)
Expand Down Expand Up @@ -375,9 +374,6 @@ extern (C) int _d_run_main(int argc, char **argv, MainFunc mainFunc)
}
}

_STI_monitor_staticctor();
_STI_critical_init();

// Allocate args[] on the stack
char[][] args = (cast(char[]*) alloca(argc * (char[]).sizeof))[0 .. argc];

Expand Down Expand Up @@ -552,35 +548,19 @@ extern (C) int _d_run_main(int argc, char **argv, MainFunc mainFunc)
// the user's main function. If main terminates with an exception,
// the exception is handled and then cleanup begins. An exception
// thrown during cleanup, however, will abort the cleanup process.

void runMain()
{
result = mainFunc(args);
}

void runAll()
{
initSections();
gc_init();
initStaticDataGC();
rt_moduleCtor();
rt_moduleTlsCtor();
if (runModuleUnitTests())
tryExec(&runMain);
if (rt_init() && runModuleUnitTests())
tryExec({ result = mainFunc(args); });
else
result = EXIT_FAILURE;
rt_moduleTlsDtor();
thread_joinAll();
rt_moduleDtor();
gc_term();
finiSections();

if (!rt_term())
result = (result == EXIT_SUCCESS) ? EXIT_FAILURE : result;
}

tryExec(&runAll);

_STD_critical_term();
_STD_monitor_staticdtor();

// Issue 10344: flush stdout and return nonzero on failure
if (.fflush(.stdout) != 0)
{
Expand Down

0 comments on commit 2c6c29b

Please sign in to comment.