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

[singlejar] Use Win32 API directly in OutputJar::AppendFile #6021

Closed
wants to merge 2 commits into from

Conversation

rongjiecomputer
Copy link
Contributor

pread is only used by OutputJar::AppendFile. Implementing OutputJar::AppendFile directly with Win32 API means better performance and no worry about whether pread polyfill follows POSIX spec correctly.

Also remove unused pread polyfill.

See #2241

Also remove unused pread implementation
@rongjiecomputer
Copy link
Contributor Author

rongjiecomputer commented Aug 29, 2018

@laszlocsomor With this PR, singlejar can run on Windows. //src/tools/singlejar:output_jar_bash_test and //src/tools/singlejar:zip64_test also pass now.

while (static_cast<size_t>(total_written) < count) {
ssize_t len = std::min(kBufferSize, count - total_written);
DWORD n_read;
if (!::ReadFile(hFile, buffer.get(), len, &n_read, NULL))
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Please always use { and }, even for single statements. Omitting them is error-prone -- imagine the single statement in the if's body were a multi-statement macro.

Also in next two if-bodies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -911,6 +918,20 @@ ssize_t OutputJar::AppendFile(int in_fd, off64_t offset, size_t count) {
}
ssize_t total_written = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is total_written signed? Can you make it unsigned (size_t)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will have to ask the original author. This function return total_written at the end and even the return type of this function is ssize_t.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks.

(I guess the reason is error reporting when count = 0. IMO, ReadFile()'s approach would be better -- i.e. return a boolean, report written amount to an argument.)

@@ -911,6 +918,20 @@ ssize_t OutputJar::AppendFile(int in_fd, off64_t offset, size_t count) {
}
ssize_t total_written = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks.

(I guess the reason is error reporting when count = 0. IMO, ReadFile()'s approach would be better -- i.e. return a boolean, report written amount to an argument.)

@bazel-io bazel-io closed this in 1655933 Aug 29, 2018
@rongjiecomputer rongjiecomputer deleted the pread branch August 29, 2018 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants