Skip to content

Commit ae10555

Browse files
committed
refactor AutoConvert.h to remove MVS guard
1 parent cef5a31 commit ae10555

File tree

7 files changed

+43
-26
lines changed

7 files changed

+43
-26
lines changed

clang/tools/c-index-test/c-index-test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5199,13 +5199,13 @@ static void flush_atexit(void) {
51995199
int main(int argc, const char **argv) {
52005200
thread_info client_data;
52015201

5202-
#ifdef __MVS__
5202+
// On z/OS we need to enable auto conversion
52035203
if (enablezOSAutoConversion(fileno(stdout)) == -1)
52045204
fprintf(stderr, "Setting conversion on stdout failed\n");
52055205

5206+
// On z/OS we need to enable auto conversion
52065207
if (enablezOSAutoConversion(fileno(stderr)) == -1)
52075208
fprintf(stderr, "Setting conversion on stderr failed\n");
5208-
#endif
52095209

52105210
atexit(flush_atexit);
52115211

llvm/include/llvm/Support/AutoConvert.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#ifdef __MVS__
1818
#include <_Ccsid.h>
19+
#endif
1920
#ifdef __cplusplus
2021
#include "llvm/Support/ErrorOr.h"
2122
#include <system_error>
@@ -66,6 +67,4 @@ ErrorOr<bool> needzOSConversion(const char *FileName, const int FD = -1);
6667
} /* namespace llvm */
6768
#endif /* __cplusplus */
6869

69-
#endif /* __MVS__ */
70-
7170
#endif /* LLVM_SUPPORT_AUTOCONVERT_H */

llvm/lib/Support/AutoConvert.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#ifdef __MVS__
15-
1614
#include "llvm/Support/AutoConvert.h"
1715
#include "llvm/Support/Error.h"
1816
#include <cassert>
@@ -25,16 +23,23 @@ using namespace llvm;
2523
static int savedStdHandleAutoConversionMode[3] = {-1, -1, -1};
2624

2725
int disablezOSAutoConversion(int FD) {
26+
#ifndef __MVS__
27+
return 0;
28+
#else
2829
static const struct f_cnvrt Convert = {
2930
SETCVTOFF, // cvtcmd
3031
0, // pccsid
3132
0, // fccsid
3233
};
3334

3435
return fcntl(FD, F_CONTROL_CVT, &Convert);
36+
#endif
3537
}
3638

3739
int restorezOSStdHandleAutoConversion(int FD) {
40+
#ifndef __MVS__
41+
return 0;
42+
#else
3843
assert(FD == STDIN_FILENO || FD == STDOUT_FILENO || FD == STDERR_FILENO);
3944
if (savedStdHandleAutoConversionMode[FD] == -1)
4045
return 0;
@@ -44,9 +49,13 @@ int restorezOSStdHandleAutoConversion(int FD) {
4449
0, // fccsid
4550
};
4651
return (fcntl(FD, F_CONTROL_CVT, &Cvt));
52+
#endif
4753
}
4854

4955
int enablezOSAutoConversion(int FD) {
56+
#ifndef __MVS__
57+
return 0;
58+
#else
5059
struct f_cnvrt Query = {
5160
QUERYCVT, // cvtcmd
5261
0, // pccsid
@@ -81,30 +90,35 @@ int enablezOSAutoConversion(int FD) {
8190
// Assume untagged files to be IBM-1047 encoded.
8291
Query.fccsid = (Query.fccsid == FT_UNTAGGED) ? CCSID_IBM_1047 : Query.fccsid;
8392
return fcntl(FD, F_CONTROL_CVT, &Query);
93+
#endif
8494
}
8595

8696
std::error_code llvm::disablezOSAutoConversion(int FD) {
97+
#ifdef __MVS__
8798
if (::disablezOSAutoConversion(FD) == -1)
8899
return errnoAsErrorCode();
89-
100+
#endif
90101
return std::error_code();
91102
}
92103

93104
std::error_code llvm::enablezOSAutoConversion(int FD) {
105+
#ifdef __MVS__
94106
if (::enablezOSAutoConversion(FD) == -1)
95107
return errnoAsErrorCode();
96-
108+
#endif
97109
return std::error_code();
98110
}
99111

100112
std::error_code llvm::restorezOSStdHandleAutoConversion(int FD) {
113+
#ifdef __MVS__
101114
if (::restorezOSStdHandleAutoConversion(FD) == -1)
102115
return errnoAsErrorCode();
103-
116+
#endif
104117
return std::error_code();
105118
}
106119

107120
std::error_code llvm::setzOSFileTag(int FD, int CCSID, bool Text) {
121+
#ifdef __MVS__
108122
assert((!Text || (CCSID != FT_UNTAGGED && CCSID != FT_BINARY)) &&
109123
"FT_UNTAGGED and FT_BINARY are not allowed for text files");
110124
struct file_tag Tag;
@@ -115,6 +129,7 @@ std::error_code llvm::setzOSFileTag(int FD, int CCSID, bool Text) {
115129

116130
if (fcntl(FD, F_SETTAG, &Tag) == -1)
117131
return errnoAsErrorCode();
132+
#endif
118133
return std::error_code();
119134
}
120135

@@ -138,6 +153,9 @@ ErrorOr<__ccsid_t> llvm::getzOSFileTag(const char *FileName, const int FD) {
138153
}
139154

140155
ErrorOr<bool> llvm::needzOSConversion(const char *FileName, const int FD) {
156+
#ifndef __MVS__
157+
return false;
158+
#else
141159
ErrorOr<__ccsid_t> Ccsid = getzOSFileTag(FileName, FD);
142160
if (std::error_code EC = Ccsid.getError())
143161
return EC;
@@ -152,6 +170,5 @@ ErrorOr<bool> llvm::needzOSConversion(const char *FileName, const int FD) {
152170
default:
153171
return true;
154172
}
173+
#endif
155174
}
156-
157-
#endif //__MVS__

llvm/lib/Support/InitLLVM.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#ifdef __MVS__
2222
#include <unistd.h>
23+
#endif
2324

2425
void CleanupStdHandles(void *Cookie) {
2526
llvm::raw_ostream *Outs = &llvm::outs(), *Errs = &llvm::errs();
@@ -29,7 +30,6 @@ void CleanupStdHandles(void *Cookie) {
2930
llvm::restorezOSStdHandleAutoConversion(STDOUT_FILENO);
3031
llvm::restorezOSStdHandleAutoConversion(STDERR_FILENO);
3132
}
32-
#endif
3333

3434
using namespace llvm;
3535
using namespace llvm::sys;
@@ -41,10 +41,10 @@ InitLLVM::InitLLVM(int &Argc, const char **&Argv,
4141
assert(!Initialized && "InitLLVM was already initialized!");
4242
Initialized = true;
4343
#endif
44-
#ifdef __MVS__
44+
4545
// Bring stdin/stdout/stderr into a known state.
4646
sys::AddSignalHandler(CleanupStdHandles, nullptr);
47-
#endif
47+
4848
if (InstallPipeSignalExitHandler)
4949
// The pipe signal handler must be installed before any other handlers are
5050
// registered. This is because the Unix \ref RegisterHandlers function does

llvm/lib/Support/MemoryBuffer.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/ADT/SmallString.h"
1616
#include "llvm/Config/config.h"
1717
#include "llvm/Support/Alignment.h"
18+
#include "llvm/Support/AutoConvert.h"
1819
#include "llvm/Support/Errc.h"
1920
#include "llvm/Support/Error.h"
2021
#include "llvm/Support/ErrorHandling.h"
@@ -34,9 +35,7 @@
3435
#include <io.h>
3536
#endif
3637

37-
#ifdef __MVS__
38-
#include "llvm/Support/AutoConvert.h"
39-
#endif
38+
4039
using namespace llvm;
4140

4241
//===----------------------------------------------------------------------===//
@@ -507,7 +506,6 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
507506
return std::move(Result);
508507
}
509508

510-
#ifdef __MVS__
511509
ErrorOr<bool> NeedConversion = needzOSConversion(Filename.str().c_str(), FD);
512510
if (std::error_code EC = NeedConversion.getError())
513511
return EC;
@@ -516,9 +514,8 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
516514
// off the stream.
517515
// Note: This only works with the assumption of reading a full file (i.e,
518516
// Offset == 0 and MapSize == FileSize). Reading a file slice does not work.
519-
if (Offset == 0 && MapSize == FileSize && *NeedConversion)
517+
if (*NeedConversion && Offset == 0 && MapSize == FileSize)
520518
return getMemoryBufferForStream(FD, Filename);
521-
#endif
522519

523520
auto Buf =
524521
WritableMemoryBuffer::getNewUninitMemBuffer(MapSize, Filename, Alignment);

llvm/lib/Support/raw_ostream.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -894,21 +894,23 @@ void raw_fd_ostream::anchor() {}
894894
raw_fd_ostream &llvm::outs() {
895895
// Set buffer settings to model stdout behavior.
896896
std::error_code EC;
897-
#ifdef __MVS__
897+
898+
// On z/OS we need to enable auto conversion
898899
EC = enablezOSAutoConversion(STDOUT_FILENO);
899900
assert(!EC);
900-
#endif
901+
901902
static raw_fd_ostream S("-", EC, sys::fs::OF_None);
902903
assert(!EC);
903904
return S;
904905
}
905906

906907
raw_fd_ostream &llvm::errs() {
907908
// Set standard error to be unbuffered.
908-
#ifdef __MVS__
909+
910+
// On z/OS we need to enable auto conversion
909911
std::error_code EC = enablezOSAutoConversion(STDERR_FILENO);
910912
assert(!EC);
911-
#endif
913+
912914
static raw_fd_ostream S(STDERR_FILENO, false, true);
913915
return S;
914916
}

llvm/utils/count/count.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
#include <stdlib.h>
1212

1313
int main(int argc, char **argv) {
14-
#ifdef __MVS__
14+
15+
// On z/OS we need to enable auto conversion
1516
if (enablezOSAutoConversion(fileno(stdin)) == -1)
1617
fprintf(stderr, "Setting conversion on stdin failed\n");
1718

19+
// On z/OS we need to enable auto conversion
1820
if (enablezOSAutoConversion(fileno(stderr)) == -1)
1921
fprintf(stdout, "Setting conversion on stderr failed\n");
20-
#endif
22+
2123
size_t Count, NumLines, NumRead;
2224
char Buffer[4096], *End;
2325

0 commit comments

Comments
 (0)