GC seems to crash my C-code function

frame frame86 at live.com
Thu Sep 16 17:08:30 UTC 2021


On Thursday, 16 September 2021 at 15:34:25 UTC, Steven 
Schveighoffer wrote:

> `dup` is a GC allocation. Are you using that in your C code? 
> the GC might be collecting that string.

The compiler doesn't show that lines with -vgc. Maybe it knows 
that it is only stack allocated?

Technically, the GC could collect that data if it wants - it's 
not longer used after the function returns. At least I control 
that the GC cannot collect it till my data is processed, so there 
should be no problem.

I guess the C-methods did corrupt the memory which the compiler 
has reserved for that function data statically and then the GC 
collect marks it as free or some other UB.

>
> You are better off to cast away the immutable (as long as you 
> are 100% sure the C code isn't writing to it), as the string 
> literal will not be collected.
>
> -Steve

Yes, I changed it to stringz and a cast and the problem is gone 
so far. All char* are read only in the function or passed to 
stdlib functions that should not modify it.




More information about the Digitalmars-d-learn mailing list