[libc-commits] [libc] [libc] Lock the output stream for the 'puts' call (PR #76513)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Wed Jan 3 09:05:16 PST 2024


================
@@ -15,8 +15,21 @@
 
 namespace LIBC_NAMESPACE {
 
+// Simple helper to unlock the file once destroyed.
+struct ScopedLock {
+  ScopedLock(LIBC_NAMESPACE::File *stream) : stream(stream) { stream->lock(); }
+  ~ScopedLock() { stream->unlock(); }
+
+private:
+  LIBC_NAMESPACE::File *stream;
+};
+
 LLVM_LIBC_FUNCTION(int, puts, (const char *__restrict str)) {
----------------
nickdesaulniers wrote:

Sorry, can you please provide more info on this point; it doesn't sound right to me.

My understanding of `__restrict` is that it has to do with strict aliasing of function parameters. If there's only 1 parameter, there is __nothing__ to be concerned with wrt to aliasing.

So why add __restrict here?

https://github.com/llvm/llvm-project/pull/76513


More information about the libc-commits mailing list