Segfault with std.container.Array but not regular dynamic array
Maxim Fomin
maxim at maxim-fomin.ru
Wed Nov 28 23:59:01 PST 2012
On Wednesday, 28 November 2012 at 22:13:05 UTC, Dan wrote:
> On Wednesday, 28 November 2012 at 20:30:41 UTC, Maxim Fomin
> wrote:
>> On Wednesday, 28 November 2012 at 18:08:59 UTC, Dan wrote:
>>
>> This code with version=bug produces garbage because of
>> opAssign. It seems that opAssign is actually called before
>> accessing map:
>>
>
> Maxim, thanks for looking more at this. This bug is not
> affecting my work in any way - I'm just trying to learn more
> about D and how to debug, and your responses are helpful.
>
> I've now built druntime and phobos with debug to see if I can
> see what is going on more.
>
> For me the relevant assembly of your code looks like below. I
> see the value in the assoc array get created and memset
> initialized to 0 inside aaA.d function _aaGetX with this line:
>
> memset(ptail + aligntsize(keytitsize), 0, valuesize); //
> zero value
>
> Then between +62 and +102 it goes off the rails and upon entry
> to opAssign *this* is likely garbage. I can't be certain
> because the values I see are 0, which would be consistent with
> 0 initialization - but could also just be luck. At this point I
> wish I knew some assembly. Anyway, I don't know if it is a
> problem with associative array code, per se, or the code
> generated by the compiler when opAssign and/or postblit are
> defined for the value type. I do know that if you have no
> postblit and no opAssign there are no issues - even with a
> destructor. This is consistent with the examples you have
> shown, they have postblit and/or opAssign as well as the
> RefCount code which has postblit and dtor. In both your example
> crash and the RefCount crash the actual seg fault is in the
> dtor accessing bogus data because as you pointed out it was not
> correctly initialized.
>
> Thanks
> Dan
>
> <skipped>
This doesn't look like assembly for previous source. Please
provide the source for which you have assembly and tell which dmd
options do you use.
More information about the Digitalmars-d-learn
mailing list