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

Make sure to flush when using print. #2640

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/primitive_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ static Object* write_on_std(const uint8* bytes, size_t length, bool is_stdout, b
}
}

FILE* stream = is_stdout ? stdout : stderr;
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure we need this here? I don't like the mixing of win32 and std APIs here. Not sure if FlushFileBuffers would work.

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed it.
I read in some places that FlushFileBuffers wouldn't do anything on stdout/stderr.

fflush(stream);

return process->null_object();
}

Expand All @@ -133,9 +136,8 @@ static Object* write_on_std(const uint8* bytes, size_t length, bool is_stdout, b
fwrite_unlocked(bytes, 1, length, stream);
if (newline) {
fputc_unlocked('\n', stream);
} else {
fflush_unlocked(stream);
}
fflush_unlocked(stream);
funlockfile(stream);
return process->null_object();
}
Expand All @@ -147,9 +149,8 @@ static Object* write_on_std(const uint8* bytes, size_t length, bool is_stdout, b
fwrite(bytes, 1, length, stream);
if (newline) {
fputc('\n', stream);
} else {
fflush(stream);
}
fflush(stream);
return process->null_object();
}

Expand Down
Loading