diff options
author | Joseph Huber <jhuber6@vols.utk.edu> | 2023-04-28 17:44:17 -0500 |
---|---|---|
committer | Joseph Huber <jhuber6@vols.utk.edu> | 2023-04-28 21:32:01 -0500 |
commit | 91528d20584066e393a926a3430e9380f394dabc (patch) | |
tree | 905f54b5276f8d132793c5c4fe8a92a13b8742ce /libc/utils | |
parent | e52a8b89addaec496fd726a3a90bcf82d42065c9 (diff) | |
download | llvm-91528d20584066e393a926a3430e9380f394dabc.tar.gz |
[libc] Fix printing on the GPU when given a `cpp::string_ref`
The implementation of the test printing currently expects a null
terminated C-string. However, the `write_to_stderr` interface uses a
string view, which doesn't need to be null terminated. This patch
changes the printing interface to directly use `fwrite` instead rather
than relying on a null terminator.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D149493
Diffstat (limited to 'libc/utils')
-rw-r--r-- | libc/utils/gpu/loader/Server.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/libc/utils/gpu/loader/Server.h b/libc/utils/gpu/loader/Server.h index af432fcfe1fb..cd043359b1ea 100644 --- a/libc/utils/gpu/loader/Server.h +++ b/libc/utils/gpu/loader/Server.h @@ -30,10 +30,15 @@ void handle_server() { switch (port->get_opcode()) { case __llvm_libc::rpc::Opcode::PRINT_TO_STDERR: { - void *str = nullptr; - port->recv_n([&](uint64_t size) { return str = malloc(size); }); - fputs(reinterpret_cast<char *>(str), stderr); - free(str); + uint64_t str_size; + char *str = nullptr; + port->recv_n([&](uint64_t size) { + str_size = size; + str = new char[size]; + return str; + }); + fwrite(str, str_size, 1, stderr); + delete[] str; break; } case __llvm_libc::rpc::Opcode::EXIT: { |