This patch makes use of cpp::string_view instead of const char* for write_to_stderr. This helps sending non null-terminated buffers such as a single character, cpp::string_view or cpp::string.
It also fizes the gpu version that had several bugs (See https://reviews.llvm.org/D145913#4236641).
Details
- Reviewers
sivachandra jhuber6 - Commits
- rG9a99afb45560: [libc] Use string_view for write_to_stderr
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Do we want to stop using const char *? We only use this internally currently, but it was easier for me to test when it was a C type. I'll let @sivachandra decide.
libc/src/__support/OSUtil/gpu/io.cpp | ||
---|---|---|
22 | ||
26 | Does libc not use C++ style casts? |
cpp::string_view is implicitly constructible from a const char* so the current code still works. Are you calling the function from C code?
Relevant discussion for this patch: https://reviews.llvm.org/D147231#inline-1423241
libc/src/__support/OSUtil/gpu/io.cpp | ||
---|---|---|
22 | Thx for catching the typo! |
I was just calling it using this function for a standalone test, but it's not a huge deal. Alternatively, we could keep the function interface the same and do the conversion internally.
namespace __llvm_libc { void write_to_stderr(const char *msg); void quick_exit(int); } // namespace __llvm_libc
I can keep the const char* version in the gpu folder on top of the string_view version if that helps.
Alternatively, we could keep the function interface the same and do the conversion internally.
This wouldn't help for single char or non null-terminated strings.