www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10967] New: static array assignement is not exception safe.

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

           Summary: static array assignement is not exception safe.
           Product: D
           Version: D2
          Platform: All
               URL: http://d.puremagic.com/issues/show_bug.cgi?id=10966
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: monarchdodra gmail.com


--- Comment #0 from monarchdodra gmail.com 2013-09-05 00:34:24 PDT ---
So first: http://d.puremagic.com/issues/show_bug.cgi?id=10966

When doing static array assignment (either 1-to-N or N-to-N), then the basic
behavior is:

run "postblit assignment" on each item 1 by 1.

Where "postblit assignement" means:
1. Copy "this" elsewhere ("copy").
2. Copy source over "this".
3. Call postblit on "this".
4: If succeeded: Destroy the "copy".
4: If failed: copy "copy" back over "this", and propagate.

The problem with this approach is that it has weak exception safety.

If one of the postblit fails, then the array will be left in an inconsistent
sate, with *some* of the assignments done, and others not done.

Furthermore, this scheme is inconsistent with the basic behavior of postblit
that is expected for a type.

The correct behavior should be:
1. Copy *the entire array* "this" elsewhere ("copy").
2. Copy *the entire* source over "this".
3. Call *the array* postblit on "this".
4: If succeeded: Destroy the "copy" [1].
4: If failed: copy "copy" back over "this", and propagate.

This method is not more complicated, and preserves the state of the array in
one of two states "fully assigned/not assigned".

[1]: 10966: If the postblit fails, then it is the function call "postblit"
itself that should deconstruct the "sor far constructed" items. So there
*should* be no "destructor leak".

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