D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9661 - LockingTextWriter should increment file handle reference count
Summary: LockingTextWriter should increment file handle reference count
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 minor
Assignee: alex.jercaianu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-07 08:44 UTC by Artem Tarasov
Modified: 2017-12-18 22:55 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Artem Tarasov 2013-03-07 08:44:25 UTC
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 Justin Whear 2014-08-13 16:14:11 UTC
+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 github-bugzilla 2017-11-14 17:14:12 UTC
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/cb67c5d50f3898300e2b314f9f8695ba0fe6b850
Fix Issue 9661 - LockingTextWriter should increment file handle reference count

test for locking binary writer

https://github.com/dlang/phobos/commit/99002c366bfd57104e943b74cf28adea0721612d
Merge pull request #5792 from jercaianu/lockingtextwriter

Fix Issue 9661 - LockingTextWriter should increment file handle reference count
merged-on-behalf-of: Andrei Alexandrescu <andralex@users.noreply.github.com>
Comment 3 github-bugzilla 2017-12-18 22:55:21 UTC
Commits pushed to stable at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/cb67c5d50f3898300e2b314f9f8695ba0fe6b850
Fix Issue 9661 - LockingTextWriter should increment file handle reference count

https://github.com/dlang/phobos/commit/99002c366bfd57104e943b74cf28adea0721612d
Merge pull request #5792 from jercaianu/lockingtextwriter