digitalmars.D.learn - Extremely funny behavior .. could be a bug?
- seany (44/44) Sep 12 2014 consider the following :
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (10/35) Sep 12 2014 There are multiple problems with the code. Is that really what you are
- seany (43/43) Sep 12 2014 On Friday, 12 September 2014 at 15:26:34 UTC, Ali Çehreli wrote:
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (12/14) Sep 12 2014 Maybe others can figure it out by reading the code but a working code
consider the following : in file a.d module a; class class_a { struct RESULT{ string[] raw; void* res; } RESULT r; void dothing() { r = new RESULT; string aa = "string"; r.raw ~= aa; r.res = cast(void*) aa; } } in file b.d import a; // import path is okey class class_b; { void doThings(class_a * ptr_a) { class_a A = &ptr_a; writeln(A.r.raw[0]); // prints aa; writeln(A.r.res); // fails : core.exception.OutOfMemoryError (0) // but if i do comment the line : // writeln(A.r.raw[0]); out, then works } } in file c.d import a; import b; void main() { clsa = new class_a; clsb = new class_b; clsa.dothing(); clsa.doThings( & clsa); } I can not find a reason why accessing A.r.raw will erase (invoke the garbage collector) to remove A.r.res. Please help.
Sep 12 2014
There are multiple problems with the code. Is that really what you are using? On 09/12/2014 06:35 AM, seany wrote:consider the following : in file a.d module a; class class_a { struct RESULT{ string[] raw; void* res; } RESULT r; void dothing() { r = new RESULT;Error: cannot implicitly convert expression (new RESULT) of type RESULT* to RESULTstring aa = "string"; r.raw ~= aa; r.res = cast(void*) aa; } } in file b.d import a; // import path is okey class class_b;That semicolon should not be there?{ void doThings(class_a * ptr_a) { class_a A = &ptr_a;Error: cannot implicitly convert expression (& ptr_a) of type class_a** to a.class_a [...] Ali
Sep 12 2014
On Friday, 12 September 2014 at 15:26:34 UTC, Ali Çehreli wrote: you are right, it was a reduced form, of a very complex software. in file a.d module a; class class_a { struct RESULT{ string[] raw; void* res; } RESULT * r; void dothing() { r = new RESULT; string aa = "string"; r.raw ~= aa; r.res = cast(void*) aa; } } in file b.d import a; // import path is okey class class_b { void doThings(class_a * ptr_a) { class_a A = *ptr_a; writeln(A.r.raw[0]); // prints aa; writeln(A.r.res); // fails : core.exception.OutOfMemoryError (0) // but if i do comment the line : // writeln(A.r.raw[0]); out, then works } } in file c.d import a; import b; void main() { clsa = new class_a; clsb = new class_b; clsa.dothing(); clsa.doThings( & clsa); }
Sep 12 2014
On 09/12/2014 12:16 PM, seany wrote:On Friday, 12 September 2014 at 15:26:34 UTC, Ali Çehreli wrote: you are right, it was a reduced form, of a very complex software.Maybe others can figure it out by reading the code but a working code that reproduces the problem is very important for me. :) I still had to do three modifications: 1) In b.d, add 'import std.stdio;' 2) In c.d, use 'auto' when constructing clsa and clsb 3) In c.d, call doThings() on clsb, not clsa Unfortunately, there were no errors for me with a very recent dmd git head and I got the following output: string 4293D0 Ali
Sep 12 2014