Skip to content

Commit e602aa8

Browse files
authored
Revert "[libc] Add printf error handling (#162876)"
This reverts commit 0c707c9.
1 parent ca00234 commit e602aa8

39 files changed

+104
-584
lines changed

libc/src/stdio/CMakeLists.txt

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ add_entrypoint_object(
125125
DEPENDS
126126
libc.src.stdio.printf_core.printf_main
127127
libc.src.stdio.printf_core.writer
128-
libc.src.stdio.printf_core.core_structs
129-
libc.src.stdio.printf_core.error_mapper
130-
libc.src.__support.libc_errno
131-
libc.src.__support.CPP.limits
132128
)
133129

134130
add_entrypoint_object(
@@ -140,10 +136,6 @@ add_entrypoint_object(
140136
DEPENDS
141137
libc.src.stdio.printf_core.printf_main
142138
libc.src.stdio.printf_core.writer
143-
libc.src.stdio.printf_core.core_structs
144-
libc.src.stdio.printf_core.error_mapper
145-
libc.src.__support.libc_errno
146-
libc.src.__support.CPP.limits
147139
)
148140

149141
add_entrypoint_object(
@@ -154,10 +146,6 @@ add_entrypoint_object(
154146
asprintf.h
155147
DEPENDS
156148
libc.src.stdio.printf_core.vasprintf_internal
157-
libc.src.stdio.printf_core.core_structs
158-
libc.src.stdio.printf_core.error_mapper
159-
libc.src.__support.libc_errno
160-
libc.src.__support.CPP.limits
161149
)
162150

163151
add_entrypoint_object(
@@ -169,10 +157,6 @@ add_entrypoint_object(
169157
DEPENDS
170158
libc.src.stdio.printf_core.printf_main
171159
libc.src.stdio.printf_core.writer
172-
libc.src.stdio.printf_core.core_structs
173-
libc.src.stdio.printf_core.error_mapper
174-
libc.src.__support.libc_errno
175-
libc.src.__support.CPP.limits
176160
)
177161

178162
add_entrypoint_object(
@@ -184,10 +168,6 @@ add_entrypoint_object(
184168
DEPENDS
185169
libc.src.stdio.printf_core.printf_main
186170
libc.src.stdio.printf_core.writer
187-
libc.src.stdio.printf_core.core_structs
188-
libc.src.stdio.printf_core.error_mapper
189-
libc.src.__support.libc_errno
190-
libc.src.__support.CPP.limits
191171
)
192172

193173
add_entrypoint_object(
@@ -198,10 +178,6 @@ add_entrypoint_object(
198178
vasprintf.h
199179
DEPENDS
200180
libc.src.stdio.printf_core.vasprintf_internal
201-
libc.src.stdio.printf_core.core_structs
202-
libc.src.stdio.printf_core.error_mapper
203-
libc.src.__support.libc_errno
204-
libc.src.__support.CPP.limits
205181
)
206182

207183
add_subdirectory(printf_core)

libc/src/stdio/asprintf.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/stdio/asprintf.h"
10-
#include "src/__support/CPP/limits.h"
1110
#include "src/__support/arg_list.h"
12-
#include "src/__support/libc_errno.h"
1311
#include "src/__support/macros/config.h"
14-
#include "src/stdio/printf_core/core_structs.h"
15-
#include "src/stdio/printf_core/error_mapper.h"
1612
#include "src/stdio/printf_core/vasprintf_internal.h"
1713

1814
namespace LIBC_NAMESPACE_DECL {
@@ -26,18 +22,8 @@ LLVM_LIBC_FUNCTION(int, asprintf,
2622
// and pointer semantics, as well as handling
2723
// destruction automatically.
2824
va_end(vlist);
29-
auto ret_val = printf_core::vasprintf_internal(buffer, format, args);
30-
if (!ret_val.has_value()) {
31-
libc_errno = printf_core::internal_error_to_errno(ret_val.error());
32-
return -1;
33-
}
34-
if (ret_val.value() > cpp::numeric_limits<int>::max()) {
35-
libc_errno =
36-
printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
37-
return -1;
38-
}
39-
40-
return static_cast<int>(ret_val.value());
25+
int ret = printf_core::vasprintf_internal(buffer, format, args);
26+
return ret;
4127
}
4228

4329
} // namespace LIBC_NAMESPACE_DECL

libc/src/stdio/baremetal/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,8 @@ add_entrypoint_object(
2929
DEPENDS
3030
libc.src.stdio.printf_core.printf_main
3131
libc.src.stdio.printf_core.writer
32-
libc.src.stdio.printf_core.error_mapper
33-
libc.src.stdio.printf_core.core_structs
3432
libc.src.__support.arg_list
3533
libc.src.__support.OSUtil.osutil
36-
libc.src.__support.libc_errno
37-
libc.src.__support.CPP.limits
3834
)
3935

4036
add_entrypoint_object(
@@ -91,12 +87,8 @@ add_entrypoint_object(
9187
DEPENDS
9288
libc.src.stdio.printf_core.printf_main
9389
libc.src.stdio.printf_core.writer
94-
libc.src.stdio.printf_core.error_mapper
95-
libc.src.stdio.printf_core.core_structs
9690
libc.src.__support.arg_list
9791
libc.src.__support.OSUtil.osutil
98-
libc.src.__support.libc_errno
99-
libc.src.__support.CPP.limits
10092
)
10193

10294
add_entrypoint_object(

libc/src/stdio/baremetal/printf.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/stdio/printf.h"
10-
#include "src/__support/CPP/limits.h"
1110
#include "src/__support/OSUtil/io.h"
1211
#include "src/__support/arg_list.h"
13-
#include "src/__support/libc_errno.h"
1412
#include "src/__support/macros/config.h"
1513
#include "src/stdio/printf_core/core_structs.h"
16-
#include "src/stdio/printf_core/error_mapper.h"
1714
#include "src/stdio/printf_core/printf_main.h"
1815
#include "src/stdio/printf_core/writer.h"
1916

@@ -45,25 +42,13 @@ LLVM_LIBC_FUNCTION(int, printf, (const char *__restrict format, ...)) {
4542
buffer, BUFF_SIZE, &stdout_write_hook, nullptr);
4643
printf_core::Writer<printf_core::WriteMode::FLUSH_TO_STREAM> writer(wb);
4744

48-
auto retval = printf_core::printf_main(&writer, format, args);
49-
if (!retval.has_value()) {
50-
libc_errno = printf_core::internal_error_to_errno(retval.error());
51-
return -1;
52-
}
45+
int retval = printf_core::printf_main(&writer, format, args);
5346

5447
int flushval = wb.overflow_write("");
55-
if (flushval != printf_core::WRITE_OK) {
56-
libc_errno = printf_core::internal_error_to_errno(-flushval);
57-
return -1;
58-
}
48+
if (flushval != printf_core::WRITE_OK)
49+
retval = flushval;
5950

60-
if (retval.value() > cpp::numeric_limits<int>::max()) {
61-
libc_errno =
62-
printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
63-
return -1;
64-
}
65-
66-
return static_cast<int>(retval.value());
51+
return retval;
6752
}
6853

6954
} // namespace LIBC_NAMESPACE_DECL

libc/src/stdio/baremetal/vprintf.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/stdio/vprintf.h"
10-
#include "src/__support/CPP/limits.h"
1110
#include "src/__support/OSUtil/io.h"
1211
#include "src/__support/arg_list.h"
13-
#include "src/__support/libc_errno.h"
1412
#include "src/__support/macros/config.h"
1513
#include "src/stdio/printf_core/core_structs.h"
16-
#include "src/stdio/printf_core/error_mapper.h"
1714
#include "src/stdio/printf_core/printf_main.h"
1815
#include "src/stdio/printf_core/writer.h"
1916

@@ -43,25 +40,13 @@ LLVM_LIBC_FUNCTION(int, vprintf,
4340
buffer, BUFF_SIZE, &stdout_write_hook, nullptr);
4441
printf_core::Writer<printf_core::WriteMode::FLUSH_TO_STREAM> writer(wb);
4542

46-
auto retval = printf_core::printf_main(&writer, format, args);
47-
if (!retval.has_value()) {
48-
libc_errno = printf_core::internal_error_to_errno(retval.error());
49-
return -1;
50-
}
43+
int retval = printf_core::printf_main(&writer, format, args);
5144

5245
int flushval = wb.overflow_write("");
53-
if (flushval != printf_core::WRITE_OK) {
54-
libc_errno = printf_core::internal_error_to_errno(-flushval);
55-
return -1;
56-
}
46+
if (flushval != printf_core::WRITE_OK)
47+
retval = flushval;
5748

58-
if (retval.value() > cpp::numeric_limits<int>::max()) {
59-
libc_errno =
60-
printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
61-
return -1;
62-
}
63-
64-
return static_cast<int>(retval.value());
49+
return retval;
6550
}
6651

6752
} // namespace LIBC_NAMESPACE_DECL

libc/src/stdio/generic/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,7 @@ add_generic_entrypoint_object(
393393
list(APPEND fprintf_deps
394394
libc.hdr.types.FILE
395395
libc.src.__support.arg_list
396-
libc.src.__support.CPP.limits
397-
libc.src.__support.libc_errno
398396
libc.src.stdio.printf_core.vfprintf_internal
399-
libc.src.stdio.printf_core.core_structs
400-
libc.src.stdio.printf_core.error_mapper
401397
)
402398

403399
if(LLVM_LIBC_FULL_BUILD)

libc/src/stdio/generic/fprintf.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88

99
#include "src/stdio/fprintf.h"
1010

11-
#include "src/__support/CPP/limits.h"
1211
#include "src/__support/File/file.h"
1312
#include "src/__support/arg_list.h"
1413
#include "src/__support/macros/config.h"
15-
#include "src/stdio/printf_core/core_structs.h"
16-
#include "src/stdio/printf_core/error_mapper.h"
1714
#include "src/stdio/printf_core/vfprintf_internal.h"
1815

1916
#include "hdr/types/FILE.h"
@@ -30,18 +27,8 @@ LLVM_LIBC_FUNCTION(int, fprintf,
3027
// and pointer semantics, as well as handling
3128
// destruction automatically.
3229
va_end(vlist);
33-
auto ret_val = printf_core::vfprintf_internal(stream, format, args);
34-
if (!ret_val.has_value()) {
35-
libc_errno = printf_core::internal_error_to_errno(ret_val.error());
36-
return -1;
37-
}
38-
if (ret_val.value() > cpp::numeric_limits<int>::max()) {
39-
libc_errno =
40-
printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
41-
return -1;
42-
}
43-
44-
return static_cast<int>(ret_val.value());
30+
int ret_val = printf_core::vfprintf_internal(stream, format, args);
31+
return ret_val;
4532
}
4633

4734
} // namespace LIBC_NAMESPACE_DECL

libc/src/stdio/generic/printf.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88

99
#include "src/stdio/printf.h"
1010

11-
#include "src/__support/CPP/limits.h"
1211
#include "src/__support/File/file.h"
1312
#include "src/__support/arg_list.h"
1413
#include "src/__support/macros/config.h"
15-
#include "src/stdio/printf_core/core_structs.h"
16-
#include "src/stdio/printf_core/error_mapper.h"
1714
#include "src/stdio/printf_core/vfprintf_internal.h"
1815

1916
#include "hdr/types/FILE.h"
@@ -34,19 +31,9 @@ LLVM_LIBC_FUNCTION(int, printf, (const char *__restrict format, ...)) {
3431
// and pointer semantics, as well as handling
3532
// destruction automatically.
3633
va_end(vlist);
37-
auto ret_val = printf_core::vfprintf_internal(
34+
int ret_val = printf_core::vfprintf_internal(
3835
reinterpret_cast<::FILE *>(PRINTF_STDOUT), format, args);
39-
if (!ret_val.has_value()) {
40-
libc_errno = printf_core::internal_error_to_errno(ret_val.error());
41-
return -1;
42-
}
43-
if (ret_val.value() > cpp::numeric_limits<int>::max()) {
44-
libc_errno =
45-
printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
46-
return -1;
47-
}
48-
49-
return static_cast<int>(ret_val.value());
36+
return ret_val;
5037
}
5138

5239
} // namespace LIBC_NAMESPACE_DECL

libc/src/stdio/generic/vfprintf.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88

99
#include "src/stdio/vfprintf.h"
1010

11-
#include "src/__support/CPP/limits.h"
1211
#include "src/__support/File/file.h"
1312
#include "src/__support/arg_list.h"
1413
#include "src/__support/macros/config.h"
15-
#include "src/stdio/printf_core/core_structs.h"
16-
#include "src/stdio/printf_core/error_mapper.h"
1714
#include "src/stdio/printf_core/vfprintf_internal.h"
1815

1916
#include "hdr/types/FILE.h"
@@ -27,18 +24,8 @@ LLVM_LIBC_FUNCTION(int, vfprintf,
2724
internal::ArgList args(vlist); // This holder class allows for easier copying
2825
// and pointer semantics, as well as handling
2926
// destruction automatically.
30-
auto ret_val = printf_core::vfprintf_internal(stream, format, args);
31-
if (!ret_val.has_value()) {
32-
libc_errno = printf_core::internal_error_to_errno(ret_val.error());
33-
return -1;
34-
}
35-
if (ret_val.value() > cpp::numeric_limits<int>::max()) {
36-
libc_errno =
37-
printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
38-
return -1;
39-
}
40-
41-
return static_cast<int>(ret_val.value());
27+
int ret_val = printf_core::vfprintf_internal(stream, format, args);
28+
return ret_val;
4229
}
4330

4431
} // namespace LIBC_NAMESPACE_DECL

libc/src/stdio/generic/vprintf.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88

99
#include "src/stdio/vprintf.h"
1010

11-
#include "src/__support/CPP/limits.h"
1211
#include "src/__support/File/file.h"
1312
#include "src/__support/arg_list.h"
1413
#include "src/__support/macros/config.h"
15-
#include "src/stdio/printf_core/core_structs.h"
16-
#include "src/stdio/printf_core/error_mapper.h"
1714
#include "src/stdio/printf_core/vfprintf_internal.h"
1815

1916
#include "hdr/types/FILE.h"
@@ -32,19 +29,9 @@ LLVM_LIBC_FUNCTION(int, vprintf,
3229
internal::ArgList args(vlist); // This holder class allows for easier copying
3330
// and pointer semantics, as well as handling
3431
// destruction automatically.
35-
auto ret_val = printf_core::vfprintf_internal(
32+
int ret_val = printf_core::vfprintf_internal(
3633
reinterpret_cast<::FILE *>(PRINTF_STDOUT), format, args);
37-
if (!ret_val.has_value()) {
38-
libc_errno = printf_core::internal_error_to_errno(ret_val.error());
39-
return -1;
40-
}
41-
if (ret_val.value() > cpp::numeric_limits<int>::max()) {
42-
libc_errno =
43-
printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
44-
return -1;
45-
}
46-
47-
return static_cast<int>(ret_val.value());
34+
return ret_val;
4835
}
4936

5037
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)