GC seems to crash my C-code function
bauss
jj_1337 at live.dk
Thu Sep 16 10:48:19 UTC 2021
On Thursday, 16 September 2021 at 10:28:37 UTC, frame wrote:
> I have C-code translated in D that acts sometimes incorrect if
> the GC has made some collect. I would like to know why.
>
> - Code runs correct if the GC collections are off
> - There are no allocations within the C-translated-code except
> `throw new` (but they are not called)
> - All allocations made in C-translated-code are still
> calloc/malloc `ed
> - Even if I disable the GC before calling the function and just
> enable it after there will be an incorrect result
> - Data passed to the function belongs to a struct and the
> function is called in a member function and is always correct
>
> The main public function accepts a char* and returns a char*.
> Signature is like this:
> ```d
> char* fun(ref int, ref int, size_t, const char*, out int, out
> int, out int, uint);
> ```
> Input paramter gets the pointer from char[] `.ptr` property
> (and length must be supplied too).
>
>
> I didn't want to change the code much so I have some piece like
> that:
> ```d
> // const char *s2 = "!\"#$%&'()*+,-./:;<=>?@[\\]^_";
> char* s2 = "!\"#$%&'()*+,-./:;<=>?@[\\]^_".dup.ptr;
> ```
> Could this cause the issue? But the pointer is not used outside
> the function where it's created.
Use toStringz and not .ptr.
Or append \0 to your string.
More information about the Digitalmars-d-learn
mailing list