[Issue 1886] Inserting into an AA of structs with opAssign results in ArrayBoundsError

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Dec 16 19:10:54 PST 2009


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



--- Comment #4 from Michael Rynn <y0uf00bar at gmail.com> 2009-12-16 19:10:53 PST ---
Sorry to split into 3 bits.  When I press tab the focus goes to the submit
button.

I stepped thru the x86 code generated in the debugger using Visual Studio 
2008 after conversion with cv2pdb -- great tool.

In the noblit case :- 
The code  calls __aaGet

    the arguments are the key, TypeInfo_Aa at __init, and address of the 
map structure.
    An address? is returned in EAX, which is checked for null,
    The value of nval is directly blitted to the returned address.

    __aaGet does the checking if the key points to existing value, 
and allocates memory for new value as required.


In the postblit case the generated code seems to miss the point entirely.

The code initially makes a temporary copy of val. and calls the postblit 
constructor, which calls this(this).  --> @postblit__cpctor --> 
postblit at __postblit.

Why is a prior temporary copy required, when one hopes that its the map 
that is going to provide the final destination?

>From the temporary copy, it then pushes the bits value of the temporary 
(not the address!),
then the key, then TypeInfo_Aa at __init, and address of map.

The code then calls __aaGetRvalue  ( not __aaGet )

__aaGetRvalue gives up very quickly, failing its first check.

     It pushes registers, and then checks the address in [esp+18h].
     This being null, it pop-exits with null as the result in eax.
     Obviously __aaGetRvalue is expecting something else to be setup.


     Presumably if __aaGetRvalue actually worked, it would just reblit 
the value in the temporary to the memory it allocated or found, without 
calling postblit again.

I would like to see ideally.
    No temporary copy made initially.

    The map lookup able to allocate or find memory for the key.
    The address returned.
    The copy made and then post-blit called.    

Failing that , please fix up __aaGetRvalue so it does the right thing.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list