[libc] Change default behaviour of baremetal/printf to use stdout (#143703)
In #94078, `write_to_stdout` had not been fully implemented. However, now that it has been implemented, to conform with the C standard (7.23.6.3. The printf function, specifically point 2), we use `stdout`. This issue is tracked in #94685. - Also prefer `static constexpr` - Made it explicit that we are writing to `stdout`
This commit is contained in:
@@ -21,8 +21,8 @@ namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
namespace {
|
||||
|
||||
LIBC_INLINE int raw_write_hook(cpp::string_view new_str, void *) {
|
||||
write_to_stderr(new_str);
|
||||
LIBC_INLINE int stdout_write_hook(cpp::string_view new_str, void *) {
|
||||
write_to_stdout(new_str);
|
||||
return printf_core::WRITE_OK;
|
||||
}
|
||||
|
||||
@@ -35,11 +35,11 @@ LLVM_LIBC_FUNCTION(int, printf, (const char *__restrict format, ...)) {
|
||||
// and pointer semantics, as well as handling
|
||||
// destruction automatically.
|
||||
va_end(vlist);
|
||||
constexpr size_t BUFF_SIZE = 1024;
|
||||
static constexpr size_t BUFF_SIZE = 1024;
|
||||
char buffer[BUFF_SIZE];
|
||||
|
||||
printf_core::WriteBuffer<printf_core::WriteMode::FLUSH_TO_STREAM> wb(
|
||||
buffer, BUFF_SIZE, &raw_write_hook, nullptr);
|
||||
buffer, BUFF_SIZE, &stdout_write_hook, nullptr);
|
||||
printf_core::Writer<printf_core::WriteMode::FLUSH_TO_STREAM> writer(wb);
|
||||
|
||||
int retval = printf_core::printf_main(&writer, format, args);
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace LIBC_NAMESPACE_DECL {
|
||||
LLVM_LIBC_FUNCTION(int, putchar, (int c)) {
|
||||
char uc = static_cast<char>(c);
|
||||
|
||||
write_to_stderr(cpp::string_view(&uc, 1));
|
||||
write_to_stdout(cpp::string_view(&uc, 1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ LLVM_LIBC_FUNCTION(int, puts, (const char *__restrict str)) {
|
||||
cpp::string_view str_view(str);
|
||||
|
||||
// TODO: Can we combine these to avoid needing two writes?
|
||||
write_to_stderr(str_view);
|
||||
write_to_stderr("\n");
|
||||
write_to_stdout(str_view);
|
||||
write_to_stdout("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
namespace {
|
||||
|
||||
LIBC_INLINE int raw_write_hook(cpp::string_view new_str, void *) {
|
||||
write_to_stderr(new_str);
|
||||
LIBC_INLINE int stdout_write_hook(cpp::string_view new_str, void *) {
|
||||
write_to_stdout(new_str);
|
||||
return printf_core::WRITE_OK;
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ LLVM_LIBC_FUNCTION(int, vprintf,
|
||||
internal::ArgList args(vlist); // This holder class allows for easier copying
|
||||
// and pointer semantics, as well as handling
|
||||
// destruction automatically.
|
||||
constexpr size_t BUFF_SIZE = 1024;
|
||||
static constexpr size_t BUFF_SIZE = 1024;
|
||||
char buffer[BUFF_SIZE];
|
||||
|
||||
printf_core::WriteBuffer<printf_core::WriteMode::FLUSH_TO_STREAM> wb(
|
||||
buffer, BUFF_SIZE, &raw_write_hook, nullptr);
|
||||
buffer, BUFF_SIZE, &stdout_write_hook, nullptr);
|
||||
printf_core::Writer<printf_core::WriteMode::FLUSH_TO_STREAM> writer(wb);
|
||||
|
||||
int retval = printf_core::printf_main(&writer, format, args);
|
||||
|
||||
Reference in New Issue
Block a user