Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
February 12, 2013 [Issue 9500] New: Interfaces - shared static this | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=9500 Summary: Interfaces - shared static this Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: admin@dav1d.de --- Comment #0 from David <admin@dav1d.de> 2013-02-12 14:54:00 PST --- This segfaults: --------- interface IFace { void log(); } class Multi : IFace { IFace[] faces; this(IFace[] faces...) { this.faces = faces; } override void log() { foreach(face; faces) { if(face !is null) { face.log(); } } } } class Bla : IFace { override void log() {} } /+__gshared+/ Multi m; shared static this() { m = new Multi(new Bla()); } void main() { m.log(); } --------- Fixed if: * shared static this -> static this * or shared static this is changed to: shared static this() { IFace i = new Bla(); m = new Multi([i]); } (passing an array explicitly) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 12, 2013 [Issue 9500] Interfaces - shared static this | ||||
---|---|---|---|---|
| ||||
Posted in reply to David | http://d.puremagic.com/issues/show_bug.cgi?id=9500 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrej.mitrovich@gmail.com --- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-02-12 15:14:22 PST --- > * or shared static this is changed to: > > shared static this() { > IFace i = new Bla(); > m = new Multi([i]); > } Simpler: m = new Multi([new Bla()]); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 12, 2013 [Issue 9500] Regression (2.061): Interfaces - shared static this | ||||
---|---|---|---|---|
| ||||
Posted in reply to David | http://d.puremagic.com/issues/show_bug.cgi?id=9500 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Interfaces - shared static |Regression (2.061): |this |Interfaces - shared static | |this Severity|normal |regression --- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-02-12 15:15:41 PST --- Introduced in 2.061. 2.060 works. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 12, 2013 [Issue 9500] Interfaces - shared static this | ||||
---|---|---|---|---|
| ||||
Posted in reply to David | http://d.puremagic.com/issues/show_bug.cgi?id=9500 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Regression (2.061): |Interfaces - shared static |Interfaces - shared static |this |this | Severity|regression |normal --- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-02-12 15:35:27 PST --- Not a regression, I've read the wrong status.(In reply to comment #2) > Introduced in 2.061. 2.060 works. Not a regression, I've read the wrong status. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 17, 2013 [Issue 9500] Interfaces - shared static this | ||||
---|---|---|---|---|
| ||||
Posted in reply to David | http://d.puremagic.com/issues/show_bug.cgi?id=9500 Maxim Fomin <maxim@maxim-fomin.ru> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maxim@maxim-fomin.ru --- Comment #4 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-02-17 04:33:27 PST --- Dmd 2.062 beta, linux, git head. No segfault for original code, but valgrind still complains. Removing shared from module constructor makes error explicit and passing array explicitly fixes program. I guess something is wrong with vararg function here. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 17, 2013 [Issue 9500] Interfaces - shared static this | ||||
---|---|---|---|---|
| ||||
Posted in reply to David | http://d.puremagic.com/issues/show_bug.cgi?id=9500 --- Comment #5 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-02-17 07:25:43 PST --- import core.stdc.stdio : printf; interface IFace { void log(); } class Multi : IFace { IFace[] faces; this(IFace[] faces...) { this.faces = faces; print(this); } override void log() { print(m); foreach(face; faces) { if(face !is null) { face.log(); } } } } class Bla : IFace { override void log() {} } Multi m; void print(Multi m) { printf("m=%p\n", cast(void*)m); printf("\tm.faces=%p\n", cast(void*)m.faces); printf("\t\tm.faces[0]=%p\n", cast(void*) m.faces[0]); } static this() { m = new Multi(new Bla()); print(m); } void main() { print(m); m.log(); } Example of output: m=0x7fe9f4b2ffc0 m.faces=0x7fff9ca7c070 m.faces[0]=0x7fe9f4b30ff0 m=0x7fe9f4b2ffc0 m.faces=0x7fff9ca7c070 m.faces[0]=0x7fe9f4b30ff0 m=0x7fe9f4b2ffc0 m.faces=0x7fff9ca7c070 m.faces[0]=0x7fff9ca7c290 m=0x7fe9f4b2ffc0 m.faces=0x7fff9ca7c070 m.faces[0]=0x7fff9ca7c290 Depending on compiler switches and whether shared is appended to module ctor, output of third m.faces[0] (in main) can vary. The fourth m.faces[0] may decay to function pointer, first two would be correct and same. Addresses of higher positions are equal in any case. I guess the problem is that array of Ifaces is not allocated when constructed, hence its content varies thought runtime. I also guess that variardic function should not save its array of arguments in general case. This explains way passing actual array fixed program (because it was properly allocated) and why playing around with module ctor didn't help. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 17, 2013 [Issue 9500] Interfaces - shared static this | ||||
---|---|---|---|---|
| ||||
Posted in reply to David | http://d.puremagic.com/issues/show_bug.cgi?id=9500 Maxim Fomin <maxim@maxim-fomin.ru> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID --- Comment #6 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-02-17 07:46:39 PST --- See issue 9527 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation