From: Alejandro Colomar <alx.manpages@gmail.com>
To: Ingo Schwarze <schwarze@usta.de>
Cc: linux-man@vger.kernel.org, JeanHeyd Meneide <wg14@soasis.org>
Subject: Re: [PATCH] Various pages: SYNOPSIS: Use VLA syntax in function parameters
Date: Sat, 27 Aug 2022 14:15:32 +0200 [thread overview]
Message-ID: <89d79095-d1cd-ab2b-00e4-caa31126751e@gmail.com> (raw)
In-Reply-To: <Ywn7jMtB5ppSW0PB@asta-kit.de>
[-- Attachment #1.1: Type: text/plain, Size: 4593 bytes --]
Hi Ingo,
On 8/27/22 13:10, Ingo Schwarze wrote:
> Hi Alejandro,
>
>> -.BI "char *getcwd(char *" buf ", size_t " size );
>> +.BI "char *getcwd(char " buf [ size "], size_t " size );
>
> I dislike this.
>
> Manual pages should show function prototypes as they really are in
> the header file, or if the header file contains useless fluff like
> "restrict", a shortened form showing the essence that actually matters
> for using the API.
Regarding restrict, it is essential to differentiate memcpy(3) and
memmove(3), which are otherwise identical:
void *memmove(void *dest, const void *src, size_t n);
void *memcpy(void *restrict dest, const void *restrict src,
size_t n);
I guess you will argue that the description specified the difference, so
it's not necessary in the synopsis. That's true. But reality is that
programmers have historically not cared about those details; so much
that glibc had to provide a compat symbol for old programs, which
basically maps memcpy(3) to memmove(3) for code linked against old glibc
versions.
In some cases, like in memcpy(3), the use of restrict is important; in
others, such as in printf(3), it is irrelevant. But for consistency, I
decided to use restrict everywhere where one of POSIX, or glibc used it
(assuming that POSIX would never remove a restrict qualifier if ISO C
required it). In some cases, glibc and POSIX differed, and I used the
most restrictive prototype.
I didn't add that change about restrict without concerns about being too
noisy. I had them, and still have them. But I think the added value is
more than the one I removed. Now prototypes are more precise, and
overcoming the noise shouldn't be too much of a problem.
In the case of (abusing) VLA syntax, it's more or less the same thing,
with a bit of added WTF moments about the "Why is this code using an
identifier declared right after it? Is it a typo?". I guess the WTF
moments will be more relevant the first few months, and less so when
time passes and programmers get used to the syntax.
I used strlcpy(3) in the commit message on purpose, as it's a great
example, similar to how good is the one about memcpy(3). The competitor
(as they promoted it) to strlcpy(3) in the Linux kernel is strscpy(9)
(not available to user space). They seem to be the same thing, but they
are not. Let's show their prototypes:
size_t strlcpy(char dst[size], const char *src, size_t size);
ssize_t strscpy(char dst[size], const char src[size], size_t size);
From those prototypes, I can already see that the kernel accepts a
possibly-not-terminated string, while strlcpy(3) requires that the
string is terminated. I didn't use restrict here to more clearly show
the difference in VLA syntax (therefore admitting that a bit of noise is
true).
Then of course, there's no difference in the prototypes between
strscpy(9) and strncpy(3), apart from the return value, of course:
char *strncpy(char dest[n], const char src[n], size_t n);
And yet they are different functions (one guarantees the produced string
to be NUL-terminated and the other not (and also clears unnecessarily
the rest of the buffer, so strncpy(3) is just broken). But they are
more or less in the same league, as they are used for transforming
untrusted strings into proper strings (strncpy(3) only if you use it
with sizeof(buf) - 1), and that's shown by the prototypes.
Do you regard the (abused) VLA syntax as something much worse than the
use of restrict? Or are they more or less equivalent to you?
> They should certainly not show something imaginary
> that does not match reality, and even less so using invalid syntax.
Well, not that I haven't had those thoughts, but we already use ilegal
syntax in some cases for good reasons. See for example open(2):
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
Of course, you can't declare two conflicting prototypes like that. But
it shows that those are the two only ways you can use it. I'll admit
that a long time ago I told Michael that we should fix those prototypes
to match reality, with legal syntax, because otherwise they are
confusing. But with time, I got used to that weirdness, and it now
seems to me more informative than just '...' as FreeBSD and OpenBSD
document.
>
> Yours,
> Ingo
Cheers,
Alex
--
Alejandro Colomar
<http://www.alejandro-colomar.es/>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2022-08-27 12:15 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-26 21:07 [PATCH] Various pages: SYNOPSIS: Use VLA syntax in function parameters Alejandro Colomar
2022-08-27 11:10 ` Ingo Schwarze
2022-08-27 12:15 ` Alejandro Colomar [this message]
2022-08-27 13:08 ` Ingo Schwarze
2022-08-27 18:38 ` Alejandro Colomar
2022-08-28 11:24 ` Alejandro Colomar
[not found] ` <CACqA6+mfaj6Viw+LVOG=nE350gQhCwVKXRzycVru5Oi4EJzgTg@mail.gmail.com>
2022-09-02 21:02 ` Alejandro Colomar
2022-09-02 21:57 ` Alejandro Colomar
2022-09-03 12:47 ` Martin Uecker
2022-09-03 13:29 ` Ingo Schwarze
2022-09-03 15:08 ` Alejandro Colomar
2022-09-03 13:41 ` Alejandro Colomar
2022-09-03 14:35 ` Martin Uecker
2022-09-03 14:59 ` Alejandro Colomar
2022-09-03 15:31 ` Martin Uecker
2022-09-03 20:02 ` Alejandro Colomar
2022-09-05 14:31 ` Alejandro Colomar
2022-11-10 0:06 ` Alejandro Colomar
2022-11-10 0:09 ` Alejandro Colomar
2022-11-10 1:33 ` Joseph Myers
2022-11-10 1:39 ` Joseph Myers
2022-11-10 6:21 ` Martin Uecker
2022-11-10 10:09 ` Alejandro Colomar
2022-11-10 23:19 ` Joseph Myers
2022-11-10 23:28 ` Alejandro Colomar
2022-11-11 19:52 ` Martin Uecker
2022-11-12 1:09 ` Joseph Myers
2022-11-12 7:24 ` Martin Uecker
2022-11-12 12:34 ` Alejandro Colomar
2022-11-12 12:46 ` Alejandro Colomar
2022-11-12 13:03 ` Joseph Myers
2022-11-12 13:40 ` Alejandro Colomar
2022-11-12 13:58 ` Alejandro Colomar
2022-11-12 14:54 ` Joseph Myers
2022-11-12 15:35 ` Alejandro Colomar
2022-11-12 17:02 ` Joseph Myers
2022-11-12 17:08 ` Alejandro Colomar
2022-11-12 15:56 ` Martin Uecker
2022-11-13 13:19 ` Alejandro Colomar
2022-11-13 13:33 ` Alejandro Colomar
2022-11-13 14:02 ` Alejandro Colomar
2022-11-13 14:58 ` Martin Uecker
2022-11-13 15:15 ` Alejandro Colomar
2022-11-13 15:32 ` Martin Uecker
2022-11-13 16:25 ` Alejandro Colomar
2022-11-13 16:28 ` Alejandro Colomar
2022-11-13 16:31 ` Alejandro Colomar
2022-11-13 16:34 ` Alejandro Colomar
2022-11-13 16:56 ` Alejandro Colomar
2022-11-13 19:05 ` Alejandro Colomar
2022-11-14 18:13 ` Joseph Myers
2022-11-28 22:59 ` Alex Colomar
2022-11-28 23:18 ` Alex Colomar
2022-11-29 0:05 ` Joseph Myers
2022-11-29 14:58 ` Michael Matz
2022-11-29 15:17 ` Uecker, Martin
2022-11-29 15:44 ` Michael Matz
2022-11-29 16:58 ` Uecker, Martin
2022-11-29 17:28 ` Alex Colomar
2022-11-29 16:49 ` Joseph Myers
2022-11-29 16:53 ` Jonathan Wakely
2022-11-29 17:00 ` Martin Uecker
2022-11-29 17:19 ` Alex Colomar
2022-11-29 17:29 ` Alex Colomar
2022-12-03 21:03 ` Alejandro Colomar
2022-12-03 21:13 ` Andrew Pinski
2022-12-03 21:15 ` Martin Uecker
2022-12-03 21:18 ` Alejandro Colomar
2022-12-06 2:08 ` Joseph Myers
2022-11-14 17:52 ` Joseph Myers
2022-11-14 17:57 ` Alejandro Colomar
2022-11-14 18:26 ` Joseph Myers
2022-11-28 23:02 ` Alex Colomar
2022-11-10 9:40 ` G. Branden Robinson
2022-11-10 10:59 ` Alejandro Colomar
2022-11-10 17:47 ` Alejandro Colomar
2022-11-10 18:04 ` MR macro 4th argument (was: [PATCH] Various pages: SYNOPSIS: Use VLA syntax in function parameters) Alejandro Colomar
2022-11-10 18:11 ` Alejandro Colomar
2022-11-10 18:20 ` Alejandro Colomar
2022-11-10 19:37 ` Alejandro Colomar
2022-11-10 20:41 ` Alejandro Colomar
2022-11-10 22:55 ` G. Branden Robinson
2022-11-10 23:55 ` Alejandro Colomar
2022-11-11 4:44 ` G. Branden Robinson
2022-11-10 22:25 ` [PATCH] Various pages: SYNOPSIS: Use VLA syntax in function parameters G. Branden Robinson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=89d79095-d1cd-ab2b-00e4-caa31126751e@gmail.com \
--to=alx.manpages@gmail.com \
--cc=linux-man@vger.kernel.org \
--cc=schwarze@usta.de \
--cc=wg14@soasis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox