Bug 6761 – Strange behavior of RedBlackTree causeing a dangling pointer

Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-10-03T08:35:00Z
Last change time
2011-10-03T10:14:56Z
Assigned to
schveiguy
Creator
tbolsh

Attachments

IDFilenameSummaryContent-TypeSize
1033RedBlackTree_bug2_1.dModule where 2 classes are defined, initialization of RBT is done in inner class constrcutortext/x-dsrc358
1034RedBlackTree_bug2_2.dModule where I try to use that classes and RBTtext/x-dsrc243

Comments

Comment #0 by tbolsh — 2011-10-03T08:35:32Z
Created attachment 1033 Module where 2 classes are defined, initialization of RBT is done in inner class constrcutor That error I was trying to comprehend for a lot time and I still do not understand its causes. To see it one need to compile first module and to compile the second one with -unittest and run those unittests, like that: >dmd -c RedBlackTree_bug2_1.d >dmd -unittest RedBlackTree_bug2_2.d RedBlackTree_bug2_1.o -ofrbt_bug2 >./rbt_bug2 0 3076390832 Not only length is damaged - everything is. In real life program dies with core dumped. I can't tell for sure, but the behavior looks like a dangling pointer. That code was working (with slight modification, because RBT is a struct there instead of class) in version 2.052. That prevent me from switching to newer versions of dmd and I consider this bug to be a blocking bug for me. This error was present in version 2.053 as well, but back then I was not able to extract it into small example.
Comment #1 by tbolsh — 2011-10-03T08:35:52Z
Created attachment 1034 Module where I try to use that classes and RBT
Comment #2 by tbolsh — 2011-10-03T08:37:16Z
So, that bug blocks me from switching to any dmd version past 2.052 (new RedBlackTree implementation).
Comment #3 by schveiguy — 2011-10-03T09:04:47Z
If you compile both modules without -unittest, the code works properly. If you compile the second file with unittest (even if the test code is in main()), the code fails. The reason is because the unit test version of RBT unintentionally has an extra entry in the vtable when compared to the non-unittest version. This was my error, and I will submit a pull request to fix it. The reason it didn't show up when RedBlackTree was a struct is because structs don't have virtual functions. In order to get your code working, put final in front of the function "arrayEqual". i.e.: final bool arrayEqual(T[] arr) I'll close the bug when the pull request is implemented.
Comment #4 by schveiguy — 2011-10-03T10:14:56Z