diff --git a/src/dmd/frontend.d b/src/dmd/frontend.d index 2bfc3d0d9fa0..58eea3bdbc01 100644 --- a/src/dmd/frontend.d +++ b/src/dmd/frontend.d @@ -27,6 +27,7 @@ This needs to be done $(I before) calling any function. */ void initDMD() { + import std.concurrency : initOnce; import dmd.builtin : builtin_init; import dmd.dmodule : Module; import dmd.expression : Expression; @@ -37,16 +38,21 @@ void initDMD() import dmd.objc : Objc; import dmd.target : Target; - global._init(); - addDefaultVersionIdentifiers(); - - Type._init(); - Id.initialize(); - Module._init(); - Target._init(); - Expression._init(); - Objc._init(); - builtin_init(); + static shared bool initialized; + initOnce!initialized((){ + global._init(); + addDefaultVersionIdentifiers(); + + Type._init(); + Id.initialize(); + Module._init(); + Target._init(); + Expression._init(); + Objc._init(); + builtin_init(); + + return true; + }()); } /** @@ -60,6 +66,8 @@ void addImport(string path) import dmd.arraytypes : Strings; import std.string : toStringz; + initDMD; + if (global.path is null) global.path = new Strings(); @@ -79,6 +87,8 @@ string findDMDConfig(string dmdFilePath) import dmd.dinifile : findConfFile; import std.string : fromStringz, toStringz; + initDMD; + auto f = findConfFile(dmdFilePath.toStringz, "dmd.conf"); if (f is null) return null; @@ -227,6 +237,8 @@ Module parseModule(string fileName, string code = null) import dmd.tokens : TOK; import std.string : toStringz; + initDMD; + auto parse(Module m, string code) { scope p = new Parser!ASTCodegen(m, code, false); diff --git a/test/dub_package/frontend.d b/test/dub_package/frontend.d index c21bb9bdde9c..33f0448651fa 100755 --- a/test/dub_package/frontend.d +++ b/test/dub_package/frontend.d @@ -10,7 +10,6 @@ void main() import dmd.frontend; import std.algorithm : each; - initDMD; findImportPaths.each!addImport; auto m = parseModule("test.d", q{ diff --git a/test/dub_package/frontend_file.d b/test/dub_package/frontend_file.d index 76cba133f39e..59f5c3e29af4 100755 --- a/test/dub_package/frontend_file.d +++ b/test/dub_package/frontend_file.d @@ -12,7 +12,6 @@ void main() import std.file : remove, tempDir, fwrite = write; import std.path : buildPath; - initDMD; findImportPaths.each!addImport; auto fileName = tempDir.buildPath("d_frontend_test.d");