void* pointers get corrupted: D bug or misunderstanding?

Jonathan Marler johnnymarler at gmail.com
Mon Jul 29 08:35:20 UTC 2019


On Monday, 29 July 2019 at 08:17:34 UTC, Federico Santamorena 
wrote:
> On Monday, 29 July 2019 at 01:46:27 UTC, Exil wrote:
>> On Sunday, 28 July 2019 at 18:32:24 UTC, Federico Santamorena 
>> wrote:
>>> [...]
>>
>> 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.
>
> I even tried GC.disable().
>
> The void* pointer still gets corrupted

Can you print the raw pointer value of context/userObj at 
different points to see when the corruption occurs?

Print "context" here: 
https://github.com/yatima1460/Drill/blob/576b4b691ea5357e5271115433eb11d4c0beeae7/Source/Frontend/GTK/Main.d#L585

Print "context" here:
https://github.com/yatima1460/Drill/blob/576b4b691ea5357e5271115433eb11d4c0beeae7/Source/Frontend/GTK/Main.d#L384

Print "userObject" here:
https://github.com/yatima1460/Drill/blob/576b4b691ea5357e5271115433eb11d4c0beeae7/Source/Backend/Context.d#L187

Print "userObject" here:
https://github.com/yatima1460/Drill/blob/576b4b691ea5357e5271115433eb11d4c0beeae7/Source/Backend/Context.d#L195

Then print "userObject" here:
https://github.com/yatima1460/Drill/blob/576b4b691ea5357e5271115433eb11d4c0beeae7/Source/Frontend/GTK/Main.d#L304

It looks like you're using printf so "%p" should work to print 
the pointer.


More information about the Digitalmars-d mailing list