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

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

Re: unique_ptr | Unique for autoclose handle

2022-12-16 Thread Vitaliy Fadeev via Digitalmars-d-learn
On Thursday, 15 December 2022 at 06:08:32 UTC, Vitaliy Fadeev wrote: On Wednesday, 14 December 2022 at 17:44:05 UTC, Ali Çehreli wrote: On 12/14/22 09:41, Ali Çehreli wrote: > // According to documentation, the handler must be created dynamically: > // We make a unique owner for it:

Re: Unique!struct bug - Re: unique_ptr | Unique for autoclose handle

2022-12-16 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 15 December 2022 at 20:12:12 UTC, Ali Çehreli wrote: I think this is a bug because the documentation clearly talks about destroying the object: OK: https://github.com/dlang/phobos/pull/8651 > do we need to do some kind of deprecation? The behavior is so different from the inten

How to create a API server?

2022-12-16 Thread Dariu Drew via Digitalmars-d-learn
Hi! i need help in can i create a serve API, what library i should use? what documentation i should read?

Re: How to create a API server?

2022-12-16 Thread TTK Ciar via Digitalmars-d-learn
On Friday, 16 December 2022 at 20:57:30 UTC, Dariu Drew wrote: Hi! i need help in can i create a serve API, what library i should use? what documentation i should read? The arsd package includes arsd.http2 which makes it easy to implement API servers with very little code. https://code.dlang

How is this code invalid?

2022-12-16 Thread thebluepandabear via Digitalmars-d-learn
I am reading the fantastic book about D by Ali Çehreli, and he gives the following example when he talks about variadic functions: ```D int[] numbersForLaterUse; void foo(int[] numbers...) { numbersForLaterUse = numbers; } struct S { string[] namesForLaterUse; void foo(string[] names.

Re: How is this code invalid?

2022-12-16 Thread ag0aep6g via Digitalmars-d-learn
On Saturday, 17 December 2022 at 00:23:32 UTC, thebluepandabear wrote: ```D int[] numbersForLaterUse; void foo(int[] numbers...) { numbersForLaterUse = numbers; } struct S { string[] namesForLaterUse; void foo(string[] names...) { namesForLaterUse = names; } } ``` [...] The thin

Re: How is this code invalid?

2022-12-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Dec 17, 2022 at 12:23:32AM +, thebluepandabear via Digitalmars-d-learn wrote: [...] > ```D > int[] numbersForLaterUse; > > void foo(int[] numbers...) { >numbersForLaterUse = numbers; > } > > struct S { > string[] namesForLaterUse; > > void foo(string[] names...) { > nam

Re: How is this code invalid?

2022-12-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Dec 16, 2022 at 05:39:08PM -0800, H. S. Teoh via Digitalmars-d-learn wrote: [...] > If you really want to see what could possibly have gone wrong, try > this version of the code: [...] > The results will likely differ depending on your OS and specific > environment; but on my Linux machine

Re: How is this code invalid?

2022-12-16 Thread thebluepandabear via Digitalmars-d-learn
T Thanks, I've tried to mark it with `@safe` and it did give me a warning. I was also wondering, why is this code valid? ```D int[] numbersForLaterUse; @safe void foo(int[] numbers) { numbersForLaterUse = numbers; } ```

_Symbols _with _leading _underscores

2022-12-16 Thread Paul via Digitalmars-d-learn
I see code like this from time to time. Are the leading underscores significant, in general, in the D language? Is it just programmer preference? Is it a coding practice, in general, that is common...even outside of D? Thanks for any assistance. From: http://dpldocs.info/this-week-in-d/Blo

Re: How is this code invalid?

2022-12-16 Thread Ali Çehreli via Digitalmars-d-learn
On 12/16/22 18:20, H. S. Teoh wrote: > scratch space for computations, called the runtime > stack. I called it "function call stack" where I gave a very simplistic view of it here: https://www.youtube.com/watch?v=NWIU5wn1F1I&t=236s > (2) Use @safe when possible so that the compiler will te

Re: _Symbols _with _leading _underscores

2022-12-16 Thread user1234 via Digitalmars-d-learn
On Saturday, 17 December 2022 at 02:42:22 UTC, Paul wrote: I see code like this from time to time. Are the leading underscores significant, in general, in the D language? Is it just programmer preference? Is it a coding practice, in general, that is common...even outside of D? Thanks for any