Re: Preventing nested struct destructor accessing stack frame

2022-12-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/16/22 7:17 AM, Nick Treleaven wrote: This code segfaults when the GC calls the dtor after the unittest succeeds: ```d unittest {     int i;     struct S     {     ~this() { i++; }     }     (*new S).destroy; } ``` It seems destroy clears the context pointer. Is there a way to te

Re: Preventing nested struct destructor accessing stack frame

2022-12-23 Thread Nick Treleaven via Digitalmars-d-learn
On Tuesday, 20 December 2022 at 06:31:09 UTC, ag0aep6g wrote: On 16.12.22 14:07, Nick Treleaven wrote: This seems to work:     ~this() @trusted { if (&i > cast(void*)1024) i++; } It would be better if there was a struct property to get the context pointer though. A quick test suggests

Re: Preventing nested struct destructor accessing stack frame

2022-12-19 Thread ag0aep6g via Digitalmars-d-learn
On 16.12.22 14:07, Nick Treleaven wrote: This seems to work:     ~this() @trusted { if (&i > cast(void*)1024) i++; } It would be better if there was a struct property to get the context pointer though. A quick test suggests that the context pointer is the last item in `tupleof`. So thi

Re: Preventing nested struct destructor accessing stack frame

2022-12-18 Thread j via Digitalmars-d-learn
On Friday, 16 December 2022 at 12:17:40 UTC, Nick Treleaven wrote: This code segfaults when the GC calls the dtor after the unittest succeeds: ```d unittest { int i; struct S { ~this() { i++; } } (*new S).destroy; } ``` It seems destroy clears the context pointer. I

Re: Preventing nested struct destructor accessing stack frame

2022-12-16 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 16 December 2022 at 12:17:40 UTC, Nick Treleaven wrote: It seems destroy clears the context pointer. Is there a way to test if the context pointer is null in the dtor, to prevent the increment? This seems to work: ~this() @trusted { if (&i > cast(void*)1024) i++; } It woul

Preventing nested struct destructor accessing stack frame

2022-12-16 Thread Nick Treleaven via Digitalmars-d-learn
This code segfaults when the GC calls the dtor after the unittest succeeds: ```d unittest { int i; struct S { ~this() { i++; } } (*new S).destroy; } ``` It seems destroy clears the context pointer. Is there a way to test if the context pointer is null in the dtor, t