|
From: | Paul Eggert |
Subject: | Re: `message' not outputting the newline "atomically" |
Date: | Mon, 24 Jun 2019 15:03:01 -0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 |
On 6/24/19 2:33 PM, Lars Ingebrigtsen wrote:
the code also calls code_convert_string, so I thought one more xmalloc didn't make much difference.
If code_convert_string could cause an infloop when reporting low-on-memory messages, then we should fix that infloop too. In the meantime we shouldn't make things worse by doing yet another heap allocation.
One possibility would be to use an auto (C stack) buffer of size (min (MAX_ALLOCA, PIPE_BUF)) bytes if that buffer is large enough; otherwise, stick with the current code. This would handle the vast majority of cases atomically, and the remaining cases would be no worse off than they are now.
Still, it would be better if the code didn't need to copy the string into a buffer at all. writev would work for that, since stderr is unbuffered. There are other possibilities.
I think it's worth having that comment here. Someone reading this code will reasonably wonder why we're going to all this trouble to hand-buffer stderr here, when we don't bother doing it elsewhere. The commit log is not a good place to document curious code like that.* The patch also needs a FIXME comment saying it fixes only "message" output, not the other uses of stderr in Emacs. Well... that's kinda unusual. The commit message may say so, but having that in the code would be odd.
[Prev in Thread] | Current Thread | [Next in Thread] |