GC.calloc

Rainer Schuetze r.sagitario at gmx.de
Sat Jul 20 05:07:32 PDT 2013



On 18.07.2013 16:09, Daniel Murphy wrote:
> "David" <d at dav1d.de> wrote in message news:ks8lcs$184p$1 at digitalmars.com...
>> Am 18.07.2013 13:49, schrieb Daniel Murphy:
>>> "David" <d at dav1d.de> wrote in message
>>> news:ks6m33$o9b$1 at digitalmars.com...
>>>> Why doesn't GC.calloc follow the function signature of stdc.calloc?
>>>>
>>>> calloc(num, size_per_element)
>>>>
>>>> I think this should be changed, if no reason speaks against it, I can
>>>> look into changing this.
>>>> Of course this will break backwards compatability, but I think this is
>>>> worth it?
>>>
>>> YES.  This is the memory corruption bug that I've been stuck on for the
>>> last
>>> week in the DDMD port.
>>>
>>> Thankyou so much for bringing this up, otherwise I'd still be stuck.
>>>
>>>
>>
>> Haha, glad I could help you! Looks like I am not the only one with this
>> problem.
>
> Then I found this:
>
>
> import core.memory;
>
> extern(C) int printf(const char *, ...);
>
> void main()
> {
>      auto data = cast(int*)GC.realloc(null, 1024 * 4);
>      printf("was %d\n", GC.sizeOf(data));
>      data = cast(int*)GC.realloc(data, 1025 * 4);
>      printf("is %d\n", GC.sizeOf(data));
> }
>
> prints:
> was 4096
> is 4096
>
> Now I'm really worried.
>

This is a bad interaction of realloc and sizeOf. A related bug:

http://d.puremagic.com/issues/show_bug.cgi?id=6372

and here is a pull request:

https://github.com/D-Programming-Language/druntime/pull/547



More information about the Digitalmars-d mailing list