Add restrict annotations to all functions that require it

Alejandro Colomar alx.manpages@gmail.com
Sun Nov 27 12:39:02 GMT 2022


[CC += Andreas]

On 11/27/22 13:30, Alejandro Colomar wrote:
> [CC += all CCs from man-pages patches]
> 
> Hi Seija,
> 
> On 11/27/22 01:56, Seija K. via Libc-alpha wrote:
>> The format value has to be a string literal, every time. Otherwise, you are
>> not using these functions correctly. To reinforce this fact, I put
>> __restrict over every example of this I could find.
> 
> 
> I like this change.  In fact, when I added 'restrict' to the Linux man-pages, I 
> had to check that in some cases POSIX and glibc matched, but in others, either 
> glibc or POSIX had restrict while the other didn't:
> 
> Linux man-pages commits:
> 
> -  746d60af802a4462055c4f87a62681f7254325d8 [strptime(3)]
>     -  You fixed this one in the patch; fine.
> -  0864c240797e3b793a88ee6be5710dd9a8df9b45 [posix_spawnp(3)]
>     -  This one hasn't been changed in you patch; please check.
>     -  Bug reported here: <https://sourceware.org/bugzilla/show_bug.cgi?id=27529>
>     -  See some proof below.
> -  c445280cf371cda66916c4e5e0fdb168db3a5ad6 [lio_listio(3)]
>     -  This one hasn't been changed in you patch; please check.
>     -  Bug reported here: <https://sourceware.org/bugzilla/show_bug.cgi?id=16747>
>     -  See some proof below.
> 
> I might have missed other cases by accident, but I think those 3 are all the 
> cases where POSIX uses restrict and glibc doesn't (there are many more cases of 
> the opposite, but that's OK for your patch), as far as I documented back then 
> when I added restrict to the man-pages.
> 
> Cheers,
> 
> Alex
> 
> P.S.: I'm neutral to having the 'restrict' keyword in function definitions, if 
> they are already in function prototypes (Mike reported this).
> 
> --- posix_spawnp(3):
> 
> $ man 3p posix_spawnp |sed -n '/^SYNOPSIS/,/;/p'
> SYNOPSIS
>         #include <spawn.h>
> 
>         int posix_spawnp(pid_t *restrict pid, const char *restrict file,
>             const posix_spawn_file_actions_t *file_actions,
>             const posix_spawnattr_t *restrict attrp,
>             char *const argv[restrict], char *const envp[restrict]);
> $ grepc posix_spawnp /usr/include
> /usr/include/spawn.h:85:
> extern int posix_spawnp (pid_t *__pid, const char *__file,
>               const posix_spawn_file_actions_t *__file_actions,
>               const posix_spawnattr_t *__attrp,
>               char *const __argv[], char *const __envp[])
>      __nonnull ((2, 5));
> 
> --- lio_listio(3):
> 
> $ man 3p lio_listio |sed -n '/^SYNOPSIS/,/;/p'
> SYNOPSIS
>         #include <aio.h>
> 
>         int lio_listio(int mode, struct aiocb *restrict const list[restrict],
>             int nent, struct sigevent *restrict sig);
> $ grepc lio_listio /usr/include
> /usr/include/aio.h:148:
> extern int lio_listio (int __mode,
>                 struct aiocb *const __list[__restrict_arr],
>                 int __nent, struct sigevent *__restrict __sig)
>    __THROW __nonnull ((2));
> 
> 
> /usr/include/aio.h:214:
> #  define lio_listio lio_listio64

-- 
<http://www.alejandro-colomar.es/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20221127/53071b09/attachment-0001.sig>


More information about the Libc-alpha mailing list