Bug 11357 – Weird behavior of appender with File as the element... do not know exactly where the bug resides.

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2013-10-25T13:19:00Z
Last change time
2014-06-25T07:34:50Z
Assigned to
nobody
Creator
maidenphil

Attachments

IDFilenameSummaryContent-TypeSize
1284appenderOrFileBug.dRun this and it crashesapplication/octet-stream252

Comments

Comment #0 by maidenphil — 2013-10-25T13:19:55Z
So I just found some weird behavior while using std.array.Appender in conjunction with std.stdio.File. The attachment shows it best but, simply put: auto app = appender!( File[] )(); foreach( i = 0; i < dontMatter; ++i ) { app.put( stdout ); } Crashes. Of course, my real life needs did not include copying stdout, but rather filling an array with files using the appender. Phil
Comment #1 by maidenphil — 2013-10-25T13:22:04Z
Version of dmd is 2.063.2
Comment #2 by maidenphil — 2013-10-25T13:23:38Z
Created attachment 1284 Run this and it crashes
Comment #3 by monarchdodra — 2013-10-25T14:16:41Z
Issue is in appender, that doesn't properlly construct objects when inserting them, it merely assign them. There is an existing pull that already fixes this: https://github.com/D-Programming-Language/phobos/pull/1529 That said, putting things with destructors (such as File) is a *terrible* idea, as things put inside dynamic arrays are never "finalized" (destroyed). So basically, you'll never close your files. Prefer using std.container.Array: Not only does this correctly construct your objects, it will also deterministically manage their lifecycle. TY for filing the issue.
Comment #4 by maidenphil — 2013-10-25T16:21:01Z
(In reply to comment #3) > Issue is in appender, that doesn't properlly construct objects when inserting > them, it merely assign them. > > There is an existing pull that already fixes this: > https://github.com/D-Programming-Language/phobos/pull/1529 > > That said, putting things with destructors (such as File) is a *terrible* idea, > as things put inside dynamic arrays are never "finalized" (destroyed). So > basically, you'll never close your files. > > Prefer using std.container.Array: Not only does this correctly construct your > objects, it will also deterministically manage their lifecycle. > > TY for filing the issue. Good to know regarding the never finalized objects/structs. I am thankful for this information. I will give std.container.Array a try, thank you! Phil
Comment #5 by sludwig — 2014-06-25T07:34:50Z
The original issue has been resolved for DMD 2.065. *** This issue has been marked as a duplicate of issue 10690 ***