Page MenuHomePhabricator

[SystemZ][z/OS][Windows] Add new functions that set Text/Binary mode for Stdin and Stdout based on OpenFlags
ClosedPublic

Authored by abhina.sreeskantharajan on Thu, Apr 8, 11:04 AM.

Details

Summary

On Windows, we want to open a file in Binary mode if OF_CRLF bit is not set. On z/OS, we want to open a file in Binary mode if the OF_Text bit is not set.

This patch creates two new functions called ChangeStdinMode and ChangeStdoutMode which will take OpenFlags as an arg to determine which mode to set stdin and stdout to. This will enable patches like https://reviews.llvm.org/D100056 to not affect Windows when setting the OF_Text flag for raw_fd_streams.

Diff Detail

Event Timeline

abhina.sreeskantharajan requested review of this revision.Thu, Apr 8, 11:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptThu, Apr 8, 11:04 AM
abhina.sreeskantharajan retitled this revision from Set Text/Binary mode for Stdin and Stdout based on OpenFlags to [SystemZ][z/OS][Windows] Add new functions that set Text/Binary mode for Stdin and Stdout based on OpenFlags.Fri, Apr 9, 5:29 AM
abhina.sreeskantharajan edited the summary of this revision. (Show Details)
anirudhp added inline comments.Fri, Apr 9, 10:58 AM
llvm/lib/Support/raw_ostream.cpp
578

We are foregoing the check for the code returned by here. Is this okay? Should we be complete and assign it to EC? On unix this shouldn't matter because it just returns std::error_code (which is already what EC is). However, Windows seems to be different.

llvm/lib/Support/raw_ostream.cpp
578

I think it's ok, we didn't check the return code in the old version either.

llvm/lib/Support/MemoryBuffer.cpp
514–515

This will no longer call _setmode(_fileno(stdin), _O_BINARY); on Windows. Is that expected?

llvm/lib/Support/MemoryBuffer.cpp
514–515

Some background info about the flags: I changed the behaviour of the Flags here https://reviews.llvm.org/D99426 and this patch is an extension of that.

On Windows, we only want to open a file in text mode if the OF_CRLF bit is set with OF_TextWithCRLF. If you see in Windows/Program.inc, we only check the OF_CRLF bit to determine whether to open the file as binary/text. In Unix/Program.inc, we use OF_Text bit to determine whether to open the file as binary/text.

ping :)
Is there any concerns about this change on Windows? I think this should be NFC on Windows because we updated all the OF_Text to OF_TextWithCRLF in a previous commit.

rnk accepted this revision.Thu, Apr 15, 1:14 PM

lgtm

This revision is now accepted and ready to land.Thu, Apr 15, 1:14 PM
This revision was landed with ongoing or failed builds.Fri, Apr 16, 5:09 AM
This revision was automatically updated to reflect the committed changes.