Re: Logging with a string via %s
Marc Herbert
On 20 May 2019, at 00:20, pawel.dunaj@... wrote: There's a violation of the "Least Astonishment" principle but it's not with the '%s'. The '%s' traditionally refers to the type of the argument only, it says nothing about memory management. I don't think LOG_ASYNC('%s', ...) or LOG(O_NONBLOCK, '%s', ... ) would surprise anyone. Confusing memory semantics with format specifiers would break not just user expectations but also tools like this: https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Common-Function-Attributes.html#index-format-function-attribute (I found an insane number of bugs with this attribute) + other static checkers trying to make C a bit more safe. BTW the current API is neither "asynchronous" nor "non-blocking" in the usual API meanings. It's not asynchronous in the usual sense because there's no callback or any other second step to know when the memory can be freed or re-used. It's not non-blocking because it always succeeds, never asks to retry with EAGAIN/EWOULDBLOCK etc. It's a "globals-only", "UFO" API like nothing else.
|
|