Bug 10967 – static array assignement is not exception safe.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-05T00:34:24Z
Last change time
2023-03-27T12:35:52Z
Assigned to
No Owner
Creator
monarchdodra

Comments

Comment #0 by monarchdodra — 2013-09-05T00:34:24Z
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".
Comment #1 by razvan.nitu1305 — 2023-03-27T12:35:45Z
Actually all of the assignments get destructed. This should be fine, no?