Bug 9661 – LockingTextWriter should increment file handle reference count
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-03-07T08:44:25Z
Last change time
2017-12-18T22:55:21Z
Assigned to
alex.jercaianu
Creator
Artem Tarasov
Comments
Comment #0 by lomereiter — 2013-03-07T08:44:25Z
Its behaviour is inconsistent with byLine() and byChunk() - which keep File struct internally instead of FILE* pointer.
Compare:
auto lines = File("/tmp/file.txt").byLine();
writeln(lines); // works
auto writer = File("/tmp/file.txt", "w+").lockingTextWriter;
writer.put("123"); // fails - the file is already closed!
Comment #1 by justin — 2014-08-13T16:14:11Z
+1 I spent an hour in frustration because of a line like this:
auto buf = File("somefile", "w").lockingTextWriter();
Because the File is temporary, it immediately closes and leaves you with a LockingTextWriter with a bad handle. Since the whole point of wrapping FILE* with File is to manage its lifetime, lockingTextWriter really needs to increment and decrement the ref count.
Comment #2 by github-bugzilla — 2017-11-14T17:14:12Z