Re: toStringz lifetime

2020-11-08 Thread Ali Çehreli via Digitalmars-d-learn
On 11/8/20 6:58 PM, rikki cattermole wrote: > On 09/11/2020 2:58 PM, Ali Çehreli wrote: >> Does the D GC know the complete function call stack of the C program >> all the way up from 'main'? Is there the concept of "bottom of the >> stack" >

Re: toStringz lifetime

2020-11-08 Thread rikki cattermole via Digitalmars-d-learn
On 09/11/2020 2:58 PM, Ali Çehreli wrote: Does the D GC know the complete function call stack of the C program all the way up from 'main'? Is there the concept of "bottom of the stack" or does the D GC can only know the value of the stack pointer at the time rt_init() was called. If the

Re: toStringz lifetime

2020-11-08 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/20 3:19 AM, rikki cattermole wrote: On 25/10/2020 11:03 PM, Ali Çehreli wrote: Does the GC see that local variable 'name' that is on the C side? What I don't know is whether the GC is aware only of the stack frames of D functions or the entire thread, which would include the C

Re: toStringz lifetime

2020-10-25 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 25 October 2020 at 10:03:44 UTC, Ali Çehreli wrote: Is it really safe? Imagine a multi-threaded environment where another D function is executed that triggers a GC collection right before the printf. Does the GC see that local variable 'name' that is on the C side? What I don't

Re: toStringz lifetime

2020-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/20 3:19 AM, rikki cattermole wrote: On 25/10/2020 11:03 PM, Ali Çehreli wrote: Does the GC see that local variable 'name' that is on the C side? What I don't know is whether the GC is aware only of the stack frames of D functions or the entire thread, which would include the C

Re: toStringz lifetime

2020-10-25 Thread rikki cattermole via Digitalmars-d-learn
On 25/10/2020 11:03 PM, Ali Çehreli wrote: Does the GC see that local variable 'name' that is on the C side? What I don't know is whether the GC is aware only of the stack frames of D functions or the entire thread, which would include the C caller's 'name'. The thread stack frame that is

toStringz lifetime

2020-10-25 Thread Ali Çehreli via Digitalmars-d-learn
toStringz documentation is clear on why, when, and how to extend the lifetime of a D string: https://dlang.org/phobos/std_string.html#.toStringz Assume foo is a D library function that passes a "string" result to e.g. C: extern(C) void foo(ref const(char) * name) { name =