void* pointers get corrupted: D bug or misunderstanding?

Ali Çehreli acehreli at yahoo.com
Mon Jul 29 05:41:27 UTC 2019

On 07/28/2019 06:46 PM, Exil wrote:
> On Sunday, 28 July 2019 at 18:32:24 UTC, Federico Santamorena wrote:
>> A stupid example can be passing a D object using the void* user_data 
>> GTK argument, passing a extern(C) callback function to GTK, and then 
>> inside that callback calling a extern(D) function that accepts a void*.
>> I already tried using Variant, but pointers to Variant get corrupted 
>> too, so it's useless.
> Where is the "D object" allocated? Haven't seen anyone mention it, but 
> the way the GC works, it has to know about the memory it needs to scan 
> to look for an object.
> So if you pass an object allocated with the GC then pass it to GTK, the 
> GC isn't going to know about the memory GTK has allocate. The kind of 
> problem can happen that you mention, it deallocates the object because 
> it doesn't think it is used anymore.

For completeness, more other valuable information is here:



More information about the Digitalmars-d mailing list