Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in byLine() with empty files #375

Merged
merged 2 commits into from Jan 7, 2012
Merged

Fix bug in byLine() with empty files #375

merged 2 commits into from Jan 7, 2012

Conversation

andralex
Copy link
Member

byLine() had a bug (assertion failed) with empty files. This is because opening an empty file does not set the end-of-file indicator. The proposed solution issues a pair of getc/ungetc calls only once just before the very first read. This is unlikely to affect performance. If there are better solutions, please chime in.

@braddr
Copy link
Member

braddr commented Dec 18, 2011

I wonder if file size might be slightly better? Would only involve touching the file metadata rather than contents.

@braddr
Copy link
Member

braddr commented Dec 18, 2011

Oh, also, all those tests that use files without unique names and/or directories are a landmine when it comes to parallel builds/tests. I really want make -j to work reliably. The auto-testers are already doing that since it's critical to throughput.

@andralex
Copy link
Member Author

Good point, hold on.

@andralex
Copy link
Member Author

That won't work with pipes and other special files (there are Unix files that report size 0 yet they have stuff in them). Besides, I'm thinking if someone creates a byLine they're very likely to start actually reading stuff, so warming the buffers seems reasonable.

@braddr
Copy link
Member

braddr commented Dec 19, 2011

Good point. Too bad. Failure on distinguish between unknown and none foils a perfectly reasonable plan once again. Anyway, the hardcoded filenames issues still remain

@andralex
Copy link
Member Author

Hardcoded filenames fixed in the last commit.

std.file.write("deleteme", "1 2 3");
auto f = File("deleteme");
auto deleteme = testFilename();
scope(exit) collectException(std.file.remove(deleteme));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason why this uses collectException and none of the other lines like this do? I guess that that's what it was doing before rather than you doing it now, but it's still odd that this one does it and none of the others do.

@braddr
Copy link
Member

braddr commented Dec 29, 2011

Fails on win32:

http://d.puremagic.com/test-results/pull.ghtml?runid=12297
std\stdio.d(1577): Error: undefined identifier file, did you mean struct File?

@braddr braddr merged commit 893f2b1 into dlang:master Jan 7, 2012
@braddr
Copy link
Member

braddr commented Jan 7, 2012

I pulled your changes down and fixed the stdio.d on windows issues. I didn't address jmdavis' questions. They can be delt with in a separate pull.

@andralex
Copy link
Member Author

andralex commented Jan 8, 2012

Great. Thanks Brad and sorry for moving slow on this!

marler8997 pushed a commit to marler8997/phobos that referenced this pull request Nov 10, 2019
Merge remote-tracking branch 'upstream/stable' into merge_stable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants