digitalmars.D.bugs - [Issue 7220] New: Bad initialization when using mixin to generate a static field in a -lib'rary
- d-bugmail puremagic.com (87/87) Jan 04 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7220
- d-bugmail puremagic.com (10/10) Apr 19 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7220
- d-bugmail puremagic.com (14/14) Nov 12 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7220
- d-bugmail puremagic.com (48/48) Nov 12 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7220
- d-bugmail puremagic.com (9/9) Nov 12 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7220
- d-bugmail puremagic.com (9/9) Nov 12 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7220
- d-bugmail puremagic.com (9/9) Nov 16 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7220
http://d.puremagic.com/issues/show_bug.cgi?id=7220 Summary: Bad initialization when using mixin to generate a static field in a -lib'rary Product: D Version: D2 Platform: x86 OS/Version: Windows Status: NEW Severity: critical Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: xtzgzorex gmail.com --- Comment #0 from Alex Rønne Petersen <xtzgzorex gmail.com> 2012-01-04 10:17:29 PST --- main.d: module main; import std.stdio, faulty; static this() { writefln("Faulty.instance: %s", Faulty.instance); } private int main(string[] args) { writeln("Main"); return 0; } faulty.d: module faulty; import std.stdio; private mixin template DefineCoreType(string type) { mixin("public final class " ~ type ~ "{" ~ " private static " ~ type ~ " _instance;" ~ "" ~ " property public static " ~ type ~ " instance()" ~ " {" ~ " writeln(\"accessing " ~ type ~ ".instance()\");"~ " return _instance; " ~ " }" ~ "" ~ " static this()" ~ " {" ~ " writeln(\"initializing " ~ type ~"._instance\");"~ " _instance = new " ~ type ~ "();" ~ " }" ~ "" ~ "}"); } mixin DefineCoreType!("Faulty"); Compile with: dmd -lib faulty.d dmd main.d faulty.lib Run the resulting main.exe, and you'll see this output: accessing Faulty.instance() Faulty.instance: null initializing Faulty._instance Main but the expected output is: initializing Faulty._instance accessing Faulty.instance() Faulty.instance: faulty.DefineCoreType!("Faulty").Faulty Main The error does not occur if faulty.d is not compiled as a -lib'rary (i.e. compiled directly into the executable), or if you unroll the mixin so faulty.d becomes like so: module faulty; import std.stdio; // this works properly! public final class Faulty { private static Faulty _instance; property public static Faulty instance() { writeln("accessing Faulty.instance()"); return _instance; } static this() { writeln("initializing Faulty._instance"); _instance = new Faulty(); } } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 04 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7220 SomeDude <lovelydear mailmetrash.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |lovelydear mailmetrash.com --- Comment #1 from SomeDude <lovelydear mailmetrash.com> 2012-04-19 12:52:30 PDT --- Confirmed with 2.059 on win32 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 19 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7220 Manu <turkeyman gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |turkeyman gmail.com --- Comment #2 from Manu <turkeyman gmail.com> 2012-11-12 05:53:16 PST --- I'm seeing symptoms that look like this bug. I have a mixin template introducing shared static this() into many of my modules, and only some of them are called on startup. Many of them are simply not called, and I crash on uninitialised data. Latest DMD - Win64, building a DLL. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 12 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7220 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bugzilla digitalmars.com --- Comment #3 from Walter Bright <bugzilla digitalmars.com> 2012-11-12 20:24:17 PST --- This gets quite a bit simpler: ---------- faulty.d ------------- module faulty; import core.stdc.stdio; mixin template DefineCoreType(string type) { class Faulty { static int x; static void instance() { printf("Faulty.instance()\n"); x = 3; } static this() { printf("Faulty.static this\n"); } } } mixin DefineCoreType!("Faulty"); ---------- bar.d ------------------------- import core.stdc.stdio, faulty; static this() { Faulty.instance(); assert(Faulty.x == 3); printf("bar.static this\n"); } private int main(string[] args) { printf("Main\n"); return 0; } ------------------------------------------ dmd -lib faulty dmd bar faulty.lib bar -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 12 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7220 --- Comment #4 from github-bugzilla puremagic.com 2012-11-12 23:43:47 PST --- Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/af887b44f3bd592973037a2dc8f5ec91cc8b2626 fix Issue 7220 - Bad initialization when using mixin to generate a static field in a -lib'rary -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 12 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7220 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 12 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7220 --- Comment #5 from github-bugzilla puremagic.com 2012-11-16 13:49:29 PST --- Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/0cb89561a45edd46440d51e5807e4e1434735d24 fix Issue 7220 - Bad initialization when using mixin to generate a static field in a -lib'rary -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 16 2012