man3: SYNOPSIS: Use 'restrict' in prototypes (batch 3)
cover man3: SYNOPSIS: Use 'restrict' in prototypes (batch 3)
Hi Michael,
This fixes up to pthread_attr_setguardsize.3 to use 'restrict'. Please have a special look at printf.3, because of the ffix.
Also, I included in this patchset one patch about 'volatile': malloc_hook.3. I introduced it by accident into this patch set,
and I'm too lazy to remove it :P
I have no other patches related to 'volatile' pending.
If you think it's likely that there are more cases, please tell me, and I'll try to have a look (I'd have to create a list of man[23] variables for that, similar to man_lsfunc()).
Cheers,
Alex
Alejandro Colomar (22):
getservent_r.3: SYNOPSIS: Use 'restrict' in prototypes getsubopt.3: SYNOPSIS: Use 'restrict' in prototypes glob.3: SYNOPSIS: Use 'restrict' in prototypes
iconv.3: SYNOPSIS: Use 'restrict' in prototypes inet_ntop.3: SYNOPSIS: Use 'restrict' in prototypes inet_pton.3: SYNOPSIS: Use 'restrict' in prototypes lio_listio.3: SYNOPSIS: Use 'restrict' in prototypes makecontext.3: SYNOPSIS: Use 'restrict' in prototypes malloc_hook.3: SYNOPSIS: Use 'volatile' in prototypes mbrlen.3: SYNOPSIS: Use 'restrict' in prototypes mbrtowc.3: SYNOPSIS: Use 'restrict' in prototypes mbsnrtowcs.3: SYNOPSIS: Use 'restrict' in prototypes mbsrtowcs.3: SYNOPSIS: Use 'restrict' in prototypes mbstowcs.3: SYNOPSIS: Use 'restrict' in prototypes mbtowc.3: SYNOPSIS: Use 'restrict' in prototypes mempcpy.3: SYNOPSIS: Use 'restrict' in prototypes mq_getattr.3: SYNOPSIS: Use 'restrict' in prototypes mq_receive.3: SYNOPSIS: Use 'restrict' in prototypes posix_spawn.3: SYNOPSIS: Use 'restrict' in prototypes posix_spawn.3: SYNOPSIS: Use 'restrict' in prototypes printf.3: SYNOPSIS: Use 'restrict' in prototypes; ffix too pthread_attr_setguardsize.3: SYNOPSIS: Use 'restrict' in prototypes
man3/getservent_r.3 | 21 +++++++++++++-------- man3/getsubopt.3 | 4 ++-- man3/glob.3 | 4 ++-- man3/iconv.3 | 4 ++-- man3/inet_ntop.3 | 4 ++-- man3/inet_pton.3 | 3 ++- man3/lio_listio.3 | 4 ++-- man3/makecontext.3 | 6 ++++-- man3/malloc_hook.3 | 10 +++++----- man3/mbrlen.3 | 3 ++- man3/mbrtowc.3 | 5 +++-- man3/mbsnrtowcs.3 | 5 +++-- man3/mbsrtowcs.3 | 4 ++-- man3/mbstowcs.3 | 3 ++- man3/mbtowc.3 | 3 ++- man3/mempcpy.3 | 7 +++++-- man3/mq_getattr.3 | 4 ++-- man3/mq_receive.3 | 6 +++--- man3/posix_spawn.3 | 18 ++++++++++-------- man3/printf.3 | 29 ++++++++++++++++++----------- man3/pthread_attr_setguardsize.3 | 4 ++-- 21 files changed, 88 insertions(+), 63 deletions(-)
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 1/22 getservent_r.3: SYNOPSIS: Use 'restrict' in prototypes
glibc uses 'restrict' in getservent_r(), getservbyname_r(), getservbyport_r().
Let's use it here too.
.../glibc$ grep_glibc_prototype getservent_r resolv/netdb.h:306:
extern int getservent_r (struct servent *__restrict __result_buf,
char *__restrict __buf, size_t __buflen, struct servent **__restrict __result);
.../glibc$ grep_glibc_prototype getservbyname_r resolv/netdb.h:310:
extern int getservbyname_r (const char *__restrict __name,
const char *__restrict __proto, struct servent *__restrict __result_buf, char *__restrict __buf, size_t __buflen, struct servent **__restrict __result);
.../glibc$ grep_glibc_prototype getservbyport_r resolv/netdb.h:316:
extern int getservbyport_r (int __port, const char *__restrict __proto,
struct servent *__restrict __result_buf, char *__restrict __buf, size_t __buflen, struct servent **__restrict __result);
.../glibc$
--- man3/getservent_r.3 | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
man3/getservent_r.3 +13 -8
@@ -31,14 +31,19 @@ service entry (reentrant) .nf .B #include <netdb.h> .PP -.BI "int getservent_r(struct servent *" result_buf ", char *" buf , -.BI " size_t " buflen ", struct servent **" result ); -.BI "int getservbyname_r(const char *" name ", const char *" proto , -.BI " struct servent *" result_buf ", char *" buf , -.BI " size_t " buflen ", struct servent **" result ); -.BI "int getservbyport_r(int " port ", const char *" proto , -.BI " struct servent *" result_buf ", char *" buf , -.BI " size_t " buflen ", struct servent **" result ); +.BI "int getservent_r(struct servent *restrict " result_buf , +.BI " char *restrict " buf ", size_t " buflen , +.BI " struct servent **restrict " result ); +.BI "int getservbyname_r(const char *restrict " name , +.BI " const char *restrict " proto , +.BI " struct servent *restrict " result_buf , +.BI " char *restrict " buf ", size_t " buflen , +.BI " struct servent **restrict " result ); +.BI "int getservbyport_r(int " port , +.BI " const char *restrict " proto , +.BI " struct servent *restrict " result_buf , +.BI " char *restrict " buf ", size_t " buflen , +.BI " struct servent **restrict " result ); .PP .fi .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 2/22 getsubopt.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarPOSIX does NOT specify getsubopt() to use 'restrict'. However, glibc uses 'restrict'.
Users might be surprised by this! Let's use it here too!
.../glibc$ grep_glibc_prototype getsubopt stdlib/stdlib.h:958:
extern int getsubopt (char **__restrict __optionp,
char *const *__restrict __tokens,
char **__restrict __valuep)
__THROW __nonnull ((1, 2, 3)) __wur;.../glibc$
--- man3/getsubopt.3 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
man3/getsubopt.3 +2 -2
@@ -29,8 +29,8 @@ getsubopt \- parse suboption arguments from a string .nf .B #include <stdlib.h> .PP -.BI "int getsubopt(char **"optionp ", char * const *" tokens \ -", char **" valuep ); +.BI "int getsubopt(char **restrict " optionp ", char *const *restrict " tokens , +.BI " char **restrict " valuep ); .fi .PP .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 3/22 glob.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in glob().
Let's use it here too.
.../glibc$ grep_glibc_prototype glob posix/glob.h:146:
extern int glob (const char *__restrict __pattern, int __flags,
int (*__errfunc) (const char *, int), glob_t *__restrict __pglob) __THROW;
.../glibc$
--- man3/glob.3 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
man3/glob.3 +2 -2
@@ -38,9 +38,9 @@ glob, globfree \- find pathnames matching a pattern, free memory from glob() .nf .B #include <glob.h> .PP -.BI "int glob(const char *" pattern ", int " flags , +.BI "int glob(const char *restrict " pattern ", int " flags , .BI " int (*" errfunc ")(const char *" epath ", int " eerrno ), -.BI " glob_t *" pglob ); +.BI " glob_t *restrict " pglob ); .BI "void globfree(glob_t *" pglob ); .fi .SH DESCRIPTION
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 4/22 iconv.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in iconv().
Let's use it here too.
.../glibc$ grep_glibc_prototype iconv iconv/iconv.h:42:
extern size_t iconv (iconv_t __cd, char **__restrict __inbuf,
size_t *__restrict __inbytesleft, char **__restrict __outbuf, size_t *__restrict __outbytesleft);
.../glibc$
--- man3/iconv.3 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
man3/iconv.3 +2 -2
@@ -23,8 +23,8 @@ iconv \- perform character set conversion .B #include <iconv.h> .PP .BI "size_t iconv(iconv_t " cd , -.BI " char **" inbuf ", size_t *" inbytesleft , -.BI " char **" outbuf ", size_t *" outbytesleft ); +.BI " char **restrict " inbuf ", size_t *restrict " inbytesleft , +.BI " char **restrict " outbuf ", size_t *restrict " outbytesleft ); .fi .SH DESCRIPTION The
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 5/22 inet_ntop.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in inet_ntop(). Let's use it here too.
.../glibc$ grep_glibc_prototype inet_ntop inet/arpa/inet.h:64:
extern const char *inet_ntop (int __af, const void *__restrict __cp,
char *__restrict __buf, socklen_t __len)
__THROW;.../glibc$
--- man3/inet_ntop.3 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
man3/inet_ntop.3 +2 -2
@@ -30,8 +30,8 @@ inet_ntop \- convert IPv4 and IPv6 addresses from binary to text form .nf .B #include <arpa/inet.h> .PP -.BI "const char *inet_ntop(int " "af" ", const void *" "src" , -.BI " char *" "dst" ", socklen_t " "size" ); +.BI "const char *inet_ntop(int " af ", const void *restrict " src , +.BI " char *restrict " dst ", socklen_t " size ); .fi .SH DESCRIPTION This function converts the network address structure
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 6/22 inet_pton.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in inet_pton(). Let's use it here too.
.../glibc$ grep_glibc_prototype inet_pton inet/arpa/inet.h:58:
extern int inet_pton (int __af, const char *__restrict __cp,
void *__restrict __buf) __THROW;
.../glibc$
--- man3/inet_pton.3 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
man3/inet_pton.3 +2 -1
@@ -31,7 +31,8 @@ inet_pton \- convert IPv4 and IPv6 addresses from text to binary form .nf .B #include <arpa/inet.h> .PP -.BI "int inet_pton(int " "af" ", const char *" "src" ", void *" "dst" ); +.BI "int inet_pton(int " af ", const char *restrict " src \ +", void *restrict " dst ); .fi .SH DESCRIPTION This function converts the character string
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 7/22 lio_listio.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in lio_listio(). However, POSIX is a bit more restrictive than glibc for the second parameter.
Let's document the more restrictive POSIX variant.
$ 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);
$
.../glibc$ grep_glibc_prototype lio_listiort/aio.h:148:
extern int lio_listio (int __mode,
struct aiocb *const __list[__restrict_arr], int __nent, struct sigevent *__restrict __sig)
__THROW __nonnull ((2));
.../glibc$
--- man3/lio_listio.3 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
man3/lio_listio.3 +2 -2
@@ -28,8 +28,8 @@ lio_listio \- initiate a list of I/O requests .nf .B "#include <aio.h>" .PP -.BI "int lio_listio(int " mode ", struct aiocb *const " aiocb_list [], -.BI " int " nitems ", struct sigevent *" sevp ); +.BI "int lio_listio(int " mode ", struct aiocb *restrict const " aiocb_list [restrict], +.BI " int " nitems ", struct sigevent *restrict " sevp ); .PP Link with \fI\-lrt\fP. .fi
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 8/22 makecontext.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX.1-2001 and glibc use 'restrict' in swapcontext(). Let's use it here too.
.../glibc$ grep_glibc_prototype swapcontext stdlib/ucontext.h:41:
extern int swapcontext (ucontext_t *__restrict __oucp,
const ucontext_t *__restrict __ucp)
__THROWNL __INDIRECT_RETURN;
.../glibc$
--- man3/makecontext.3 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
man3/makecontext.3 +4 -2
@@ -32,8 +32,10 @@ makecontext, swapcontext \- manipulate user context .nf .B #include <ucontext.h> .PP -.BI "void makecontext(ucontext_t *" ucp ", void (*" func ")(), int " argc ", ...);" -.BI "int swapcontext(ucontext_t *" oucp ", const ucontext_t *" ucp ); +.BI "void makecontext(ucontext_t *" ucp ", void (*" func ")(), int " argc \ +", ...);" +.BI "int swapcontext(ucontext_t *restrict " oucp , +.BI " const ucontext_t *restrict " ucp ); .fi .SH DESCRIPTION In a System V-like environment, one has the type
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 9/22 malloc_hook.3: SYNOPSIS: Use 'volatile' in prototypes
In reply to Alejandro Colomarglibc uses 'volatile' in __malloc_hook, __realloc_hook, __memalign_hook, __free_hook, and __after_morecore_hook. Let's use it here too.
.../glibc$ find * -type f \
|grep '\.h$' \
|xargs pcregrep -Mn '(?s)\b__malloc_hook\b.*?;';malloc/malloc.h:168:
extern void *(*__MALLOC_HOOK_VOLATILE __malloc_hook)(size_t __size,
const void *)__MALLOC_DEPRECATED;
.../glibc$ find * -type f \
|grep '\.h$' \
|xargs pcregrep -Mn '(?s)\b__realloc_hook\b.*?;';malloc/malloc.h:171:
extern void *(*__MALLOC_HOOK_VOLATILE __realloc_hook)(void *__ptr,
size_t __size, const void *)__MALLOC_DEPRECATED;
.../glibc$ find * -type f \
|grep '\.h$' \
|xargs pcregrep -Mn '(?s)\b__memalign_hook\b.*?;';malloc/malloc.h:175:
extern void *(*__MALLOC_HOOK_VOLATILE __memalign_hook)(size_t __alignment,
size_t __size, const void *)__MALLOC_DEPRECATED;
.../glibc$ find * -type f \
|grep '\.h$' \
|xargs pcregrep -Mn '(?s)\b__free_hook\b.*?;';malloc/malloc.h:165:
extern void (*__MALLOC_HOOK_VOLATILE __free_hook) (void *__ptr,
const void *)__MALLOC_DEPRECATED;
.../glibc$ find * -type f \
|grep '\.h$' \
|xargs pcregrep -Mn '(?s)\*\w*\s*\b__malloc_initialize_hook\b.*?;';malloc/malloc-hooks.h:22:
void (*__malloc_initialize_hook) (void);
.../glibc$ find * -type f \
|grep '\.h$' \
|xargs pcregrep -Mn '(?s)\*\w*\s*\b__after_morecore_hook\b.*?;';malloc/malloc.h:179:
extern void (*__MALLOC_HOOK_VOLATILE __after_morecore_hook) (void)
__MALLOC_DEPRECATED;
.../glibc$
--- man3/malloc_hook.3 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
man3/malloc_hook.3 +5 -5
@@ -16,19 +16,19 @@ __after_morecore_hook \- malloc debugging variables .nf .B "#include <malloc.h>" .PP -.BI "void *(*__malloc_hook)(size_t " size ", const void *" caller ); +.BI "void *(*volatile __malloc_hook)(size_t " size ", const void *" caller ); .PP -.BI "void *(*__realloc_hook)(void *" ptr ", size_t " size \ +.BI "void *(*volatile __realloc_hook)(void *" ptr ", size_t " size \ ", const void *" caller ); .PP -.BI "void *(*__memalign_hook)(size_t " alignment ", size_t " size , +.BI "void *(*volatile __memalign_hook)(size_t " alignment ", size_t " size , .BI " const void *" caller ); .PP -.BI "void (*__free_hook)(void *" ptr ", const void *" caller ); +.BI "void (*volatile __free_hook)(void *" ptr ", const void *" caller ); .PP .B "void (*__malloc_initialize_hook)(void);" .PP -.B "void (*__after_morecore_hook)(void);" +.B "void (*volatile __after_morecore_hook)(void);" .fi .SH DESCRIPTION The GNU C library lets you modify the behavior of
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 10/22 mbrlen.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in mbrlen().
Let's use it here too.
.../glibc$ grep_glibc_prototype mbrlen wcsmbs/wchar.h:307:
extern size_t mbrlen (const char *__restrict __s, size_t __n,
mbstate_t *__restrict __ps) __THROW;
.../glibc$
--- man3/mbrlen.3 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
man3/mbrlen.3 +2 -1
@@ -20,7 +20,8 @@ mbrlen \- determine number of bytes in next multibyte character .nf .B #include <wchar.h> .PP -.BI "size_t mbrlen(const char *" s ", size_t " n ", mbstate_t *" ps ); +.BI "size_t mbrlen(const char *restrict " s ", size_t " n , +.BI " mbstate_t *restrict " ps ); .fi .SH DESCRIPTION The
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 11/22 mbrtowc.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in mbrtowc().
Let's use it here too.
.../glibc$ grep_glibc_prototype mbrtowcwcsmbs/wchar.h:296:
extern size_t mbrtowc (wchar_t *__restrict __pwc,
const char *__restrict __s, size_t __n, mbstate_t *__restrict __p) __THROW;
.../glibc$
--- man3/mbrtowc.3 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
man3/mbrtowc.3 +3 -2
@@ -21,8 +21,9 @@ mbrtowc \- convert a multibyte sequence to a wide character .nf .B #include <wchar.h> .PP -.BI "size_t mbrtowc(wchar_t *" pwc ", const char *" s ", size_t " n \ -", mbstate_t *" ps ); +.BI "size_t mbrtowc(wchar_t *restrict " pwc ", const char *restrict " s \ +", size_t " n , +.BI " mbstate_t *restrict " ps ); .fi .SH DESCRIPTION The main case for this function is when
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 12/22 mbsnrtowcs.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in mbsnrtowcs(). Let's use it here too.
.../glibc$ grep_glibc_prototype mbsnrtowcs wcsmbs/wchar.h:351:
extern size_t mbsnrtowcs (wchar_t *__restrict __dst,
const char **__restrict __src, size_t __nmc, size_t __len, mbstate_t *__restrict __ps) __THROW;
.../glibc$
--- man3/mbsnrtowcs.3 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
man3/mbsnrtowcs.3 +3 -2
@@ -19,8 +19,9 @@ mbsnrtowcs \- convert a multibyte string to a wide-character string .nf .B #include <wchar.h> .PP -.BI "size_t mbsnrtowcs(wchar_t *" dest ", const char **" src , -.BI " size_t " nms ", size_t " len ", mbstate_t *" ps ); +.BI "size_t mbsnrtowcs(wchar_t *restrict " dest ", const char **restrict " src , +.BI " size_t " nms ", size_t " len \ +", mbstate_t *restrict " ps ); .fi .PP .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 13/22 mbsrtowcs.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in mbsrtowcs(). Let's use it here too.
.../glibc$ grep_glibc_prototype mbsrtowcs wcsmbs/wchar.h:337:
extern size_t mbsrtowcs (wchar_t *__restrict __dst,
const char **__restrict __src, size_t __len, mbstate_t *__restrict __ps) __THROW;
.../glibc$
--- man3/mbsrtowcs.3 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
man3/mbsrtowcs.3 +2 -2
@@ -20,8 +20,8 @@ mbsrtowcs \- convert a multibyte string to a wide-character string .nf .B #include <wchar.h> .PP -.BI "size_t mbsrtowcs(wchar_t *" dest ", const char **" src , -.BI " size_t " len ", mbstate_t *" ps ); +.BI "size_t mbsrtowcs(wchar_t *restrict " dest ", const char **restrict " src , +.BI " size_t " len ", mbstate_t *restrict " ps ); .fi .SH DESCRIPTION If
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 14/22 mbstowcs.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in mbstowcs(). Let's use it here too.
.../glibc$ grep_glibc_prototype mbstowcs stdlib/stdlib.h:933:
extern size_t mbstowcs (wchar_t *__restrict __pwcs,
const char *__restrict __s, size_t __n) __THROW
__attr_access ((__read_only__, 2));.../glibc$
--- man3/mbstowcs.3 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
man3/mbstowcs.3 +2 -1
@@ -21,7 +21,8 @@ mbstowcs \- convert a multibyte string to a wide-character string .nf .B #include <stdlib.h> .PP -.BI "size_t mbstowcs(wchar_t *" dest ", const char *" src ", size_t " n ); +.BI "size_t mbstowcs(wchar_t *restrict " dest ", const char *restrict " src , +.BI " size_t " n ); .fi .SH DESCRIPTION If
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 15/22 mbtowc.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in mbtowc().
Let's use it here too.
.../glibc$ grep_glibc_prototype mbtowcstdlib/stdlib.h:925:
extern int mbtowc (wchar_t *__restrict __pwc,
const char *__restrict __s, size_t __n) __THROW;
.../glibc$
--- man3/mbtowc.3 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
man3/mbtowc.3 +2 -1
@@ -20,7 +20,8 @@ mbtowc \- convert a multibyte sequence to a wide character .nf .B #include <stdlib.h> .PP -.BI "int mbtowc(wchar_t *" pwc ", const char *" s ", size_t " n ); +.BI "int mbtowc(wchar_t *restrict " pwc ", const char *restrict " s \ +", size_t " n ); .fi .SH DESCRIPTION The main case for this function is when
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 16/22 mempcpy.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro Colomarglibc uses 'restrict' in mempcpy(), wmempcpy().
Let's use it here too.
.../glibc$ grep_glibc_prototype mempcpystring/string.h:384:
extern void *mempcpy (void *__restrict __dest,
const void *__restrict __src, size_t __n)
__THROW __nonnull ((1, 2));
.../glibc$ grep_glibc_prototype wmempcpy
wcsmbs/wchar.h:276:
extern wchar_t *wmempcpy (wchar_t *__restrict __s1,
const wchar_t *__restrict __s2, size_t __n)
__THROW;.../glibc$
--- man3/mempcpy.3 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
man3/mempcpy.3 +5 -2
@@ -15,12 +15,15 @@ mempcpy, wmempcpy \- copy memory area .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */" .B #include <string.h> .PP -.BI "void *mempcpy(void *" dest ", const void *" src ", size_t " n ); +.BI "void *mempcpy(void *restrict " dest ", const void *restrict " src \ +", size_t " n ); .PP .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */" .B #include <wchar.h> .PP -.BI "wchar_t *wmempcpy(wchar_t *" dest ", const wchar_t *" src ", size_t " n ); +.BI "wchar_t *wmempcpy(wchar_t *restrict " dest \ +", const wchar_t *restrict " src , +.BI " size_t " n ); .fi .SH DESCRIPTION The
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 17/22 mq_getattr.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in mq_setattr(). Let's use it here too.
.../glibc$ grep_glibc_prototype mq_setattr rt/mqueue.h:51:
extern int mq_setattr (mqd_t __mqdes,
const struct mq_attr *__restrict __mqstat, struct mq_attr *__restrict __omqstat)
__THROW __nonnull ((2));
.../glibc$
--- man3/mq_getattr.3 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
man3/mq_getattr.3 +2 -2
@@ -30,8 +30,8 @@ mq_getattr, mq_setattr \- get/set message queue attributes .B #include <mqueue.h> .PP .BI "int mq_getattr(mqd_t " mqdes ", struct mq_attr *" attr ); -.BI "int mq_setattr(mqd_t " mqdes ", const struct mq_attr *" newattr "," -.BI " struct mq_attr *" oldattr ); +.BI "int mq_setattr(mqd_t " mqdes ", const struct mq_attr *restrict " newattr , +.BI " struct mq_attr *restrict " oldattr ); .fi .PP Link with \fI\-lrt\fP.
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 18/22 mq_receive.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in mq_timedreceive(). Let's use it here too.
.../glibc$ grep_glibc_prototype mq_timedreceivert/mqueue.h:76:
extern ssize_t mq_timedreceive (mqd_t __mqdes, char *__restrict __msg_ptr,
size_t __msg_len,
unsigned int *__restrict __msg_prio, const struct timespec *__restrict __abs_timeout)
__nonnull ((2, 5));
.../glibc$
--- man3/mq_receive.3 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
man3/mq_receive.3 +3 -3
@@ -35,9 +35,9 @@ mq_receive, mq_timedreceive \- receive a message from a message queue .B #include <time.h> .B #include <mqueue.h> .PP -.BI "ssize_t mq_timedreceive(mqd_t " mqdes ", char *" msg_ptr , -.BI " size_t " msg_len ", unsigned int *" msg_prio , -.BI " const struct timespec *" abs_timeout ); +.BI "ssize_t mq_timedreceive(mqd_t " mqdes ", char *restrict " msg_ptr , +.BI " size_t " msg_len ", unsigned int *restrict " msg_prio , +.BI " const struct timespec *restrict " abs_timeout ); .fi .PP Link with \fI\-lrt\fP.
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 19/22 posix_spawn.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in posix_spawn(). Let's use it here too.
.../glibc$ grep_glibc_prototype posix_spawnposix/spawn.h:72:
extern int posix_spawn (pid_t *__restrict __pid,
const char *__restrict __path,
const posix_spawn_file_actions_t *__restrict
__file_actions,
const posix_spawnattr_t *__restrict __attrp,
char *const __argv[__restrict_arr],
char *const __envp[__restrict_arr])
__nonnull ((2, 5));.../glibc$
I conciously did an exception with respect to the right margin of the rendered page. Instead of having the right margin at 78 as usual (per Branden's recommendation), I let it use col 79 this time, to avoid breaking the prototype in an ugly way, or shifting all of the parameters to the left, unaligned with respect to the function parentheses.
--- man3/posix_spawn.3 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
man3/posix_spawn.3 +5 -4
@@ -35,10 +35,11 @@ posix_spawn, posix_spawnp \- spawn a process .nf .B #include <spawn.h> .PP -.BI "int posix_spawn(pid_t *" pid ", const char *" path , -.BI " const posix_spawn_file_actions_t *" file_actions , -.BI " const posix_spawnattr_t *" attrp , -.BI " char *const " argv[] ", char *const " envp[] ); +.BI "int posix_spawn(pid_t *restrict " pid ", const char *restrict " path , +.BI " const posix_spawn_file_actions_t *restrict " file_actions , +.BI " const posix_spawnattr_t *restrict " attrp , +.BI " char *const " argv [restrict], +.BI " char *const " envp [restrict]); .BI "int posix_spawnp(pid_t *" pid ", const char *" file , .BI " const posix_spawn_file_actions_t *" file_actions , .BI " const posix_spawnattr_t *" attrp ,
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 20/22 posix_spawn.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarPOSIX uses 'restrict' in posix_spawnp().
However, glibc doesn't.
Let's document here the more restrictive of them, which is POSIX. I reported a bug to glibc about this.
$ 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]);
$
.../glibc$ grep_glibc_prototype posix_spawnp posix/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));.../glibc$
I conciously did an exception with respect to the right margin of the rendered page. Instead of having the right margin at 78 as usual (per Branden's recommendation), I let it use col 79 this time, to avoid breaking the prototype in an ugly way, or shifting all of the parameters to the left, unaligned with respect to the function parentheses.
--- man3/posix_spawn.3 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
man3/posix_spawn.3 +5 -4
@@ -40,10 +40,11 @@ posix_spawn, posix_spawnp \- spawn a process .BI " const posix_spawnattr_t *restrict " attrp , .BI " char *const " argv [restrict], .BI " char *const " envp [restrict]); -.BI "int posix_spawnp(pid_t *" pid ", const char *" file , -.BI " const posix_spawn_file_actions_t *" file_actions , -.BI " const posix_spawnattr_t *" attrp , -.BI " char *const " argv[] ", char *const " envp[] ); +.BI "int posix_spawnp(pid_t *restrict " pid ", const char *restrict " file , +.BI " const posix_spawn_file_actions_t *restrict " file_actions , +.BI " const posix_spawnattr_t *restrict " attrp , +.BI " char *const " argv [restrict], +.BI " char *const " envp [restrict]); .fi .SH DESCRIPTION The
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 21/22 printf.3: SYNOPSIS: Use 'restrict' in prototypes; ffix too
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in printf(), fprintf(), dprintf(), sprintf(), snprintf(), vprintf(), vfprintf(), vdprintf(), vsprintf(), vsnprintf().
Let's use it here too.
.../glibc$ grep_glibc_prototype printf libio/stdio.h:332:
extern int printf (const char *__restrict __format, ...); .../glibc$ grep_glibc_prototype fprintf libio/stdio.h:326:
extern int fprintf (FILE *__restrict __stream,
const char *__restrict __format, ...);
.../glibc$ grep_glibc_prototype dprintf
libio/stdio.h:382:
extern int dprintf (int __fd, const char *__restrict __fmt, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
.../glibc$ grep_glibc_prototype sprintf
libio/stdio.h:334:
extern int sprintf (char *__restrict __s,
const char *__restrict __format, ...) __THROWNL;
.../glibc$ grep_glibc_prototype snprintf
libio/stdio.h:354:
extern int snprintf (char *__restrict __s, size_t __maxlen,
const char *__restrict __format, ...)
__THROWNL __attribute__ ((__format__ (__printf__, 3, 4)));.../glibc$ grep_glibc_prototype vprintflibio/stdio.h:347:
extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg); .../glibc$ grep_glibc_prototype vfprintflibio/stdio.h:341:
extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
__gnuc_va_list __arg);
.../glibc$ grep_glibc_prototype vdprintf
libio/stdio.h:379:
extern int vdprintf (int __fd, const char *__restrict __fmt,
__gnuc_va_list __arg)
__attribute__ ((__format__ (__printf__, 2, 0)));
.../glibc$ grep_glibc_prototype vsprintf
libio/stdio.h:349:
extern int vsprintf (char *__restrict __s, const char *__restrict __format,
__gnuc_va_list __arg) __THROWNL;
.../glibc$ grep_glibc_prototype vsnprintf
libio/stdio.h:358:
extern int vsnprintf (char *__restrict __s, size_t __maxlen,
const char *__restrict __format, __gnuc_va_list __arg)
__THROWNL __attribute__ ((__format__ (__printf__, 3, 0)));.../glibc$
ffix: Align common parameters.
--- man3/printf.3 | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
man3/printf.3 +18 -11
@@ -39,20 +39,27 @@ vsprintf, vsnprintf \- formatted output conversion .nf .B #include <stdio.h> .PP -.BI "int printf(const char *" format ", ...);" -.BI "int fprintf(FILE *" stream ", const char *" format ", ...);" -.BI "int dprintf(int " fd ", const char *" format ", ...);" -.BI "int sprintf(char *" str ", const char *" format ", ...);" -.BI "int snprintf(char *" str ", size_t " size ", const char *" format ", ...);" +.BI "int printf(const char *restrict " format ", ...);" +.BI "int fprintf(FILE *restrict " stream , +.BI " const char *restrict " format ", ...);" +.BI "int dprintf(int " fd , +.BI " const char *restrict " format ", ...);" +.BI "int sprintf(char *restrict " str , +.BI " const char *restrict " format ", ...);" +.BI "int snprintf(char *restrict " str ", size_t " size , +.BI " const char *restrict " format ", ...);" .PP .B #include <stdarg.h> .PP -.BI "int vprintf(const char *" format ", va_list " ap ); -.BI "int vfprintf(FILE *" stream ", const char *" format ", va_list " ap ); -.BI "int vdprintf(int " fd ", const char *" format ", va_list " ap ); -.BI "int vsprintf(char *" str ", const char *" format ", va_list " ap ); -.BI "int vsnprintf(char *" str ", size_t " size ", const char *" format \ -", va_list " ap ); +.BI "int vprintf(const char *restrict " format ", va_list " ap ); +.BI "int vfprintf(FILE *restrict " stream , +.BI " const char *restrict " format ", va_list " ap ); +.BI "int vdprintf(int " fd , +.BI " const char *restrict " format ", va_list " ap ); +.BI "int vsprintf(char *restrict " str , +.BI " const char *restrict " format ", va_list " ap ); +.BI "int vsnprintf(char *restrict " str ", size_t " size , +.BI " const char *restrict " format ", va_list " ap ); .fi .PP .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
PATCH 22/22 pthread_attr_setguardsize.3: SYNOPSIS: Use 'restrict' in prototypes
In reply to Alejandro ColomarBoth POSIX and glibc use 'restrict' in pthread_attr_getguardsize(). Let's use it here too.
.../glibc$ grep_glibc_prototype pthread_attr_getguardsize sysdeps/htl/pthread.h:180:
extern int pthread_attr_getguardsize (const pthread_attr_t *__restrict __attr,
size_t *__restrict __guardsize)
__THROW __nonnull ((1, 2));
sysdeps/nptl/pthread.h:283:
extern int pthread_attr_getguardsize (const pthread_attr_t *__attr,
size_t *__guardsize)
__THROW __nonnull ((1, 2));.../glibc$
--- man3/pthread_attr_setguardsize.3 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
man3/pthread_attr_setguardsize.3 +2 -2
@@ -33,8 +33,8 @@ attribute in thread attributes object .PP .BI "int pthread_attr_setguardsize(pthread_attr_t *" attr \ ", size_t " guardsize ); -.BI "int pthread_attr_getguardsize(const pthread_attr_t *" attr , -.BI " size_t *" guardsize ); +.BI "int pthread_attr_getguardsize(const pthread_attr_t *restrict " attr , +.BI " size_t *restrict " guardsize ); .PP Compile and link with \fI\-pthread\fP. .fi
Signature · 1 line
2.30.1.721.g45526154a5
Hi Alex,
Quoted 3 lines · Alejandro Colomar
Hi Michael,
This fixes up to pthread_attr_setguardsize.3 to use 'restrict'.
Thanks!
Quoted 1 line
Please have a special look at printf.3, because of the ffix.
It looks okay to me.
Quoted 3 lines
Also, I included in this patchset one patch about 'volatile': malloc_hook.3. I introduced it by accident into this patch set,
and I'm too lazy to remove it :P
Okay.
Quoted 4 lines
I have no other patches related to 'volatile' pending. If you think it's likely that there are more cases, please tell me, and I'll try to have a look (I'd have to create a list of man[23] variables for that, similar to
man_lsfunc()).
I'm not aware of other 'volatile' cases.
Quoted 20 lines
Cheers,
Alex
Alejandro Colomar (22):
getservent_r.3: SYNOPSIS: Use 'restrict' in prototypes getsubopt.3: SYNOPSIS: Use 'restrict' in prototypes glob.3: SYNOPSIS: Use 'restrict' in prototypes iconv.3: SYNOPSIS: Use 'restrict' in prototypes inet_ntop.3: SYNOPSIS: Use 'restrict' in prototypes inet_pton.3: SYNOPSIS: Use 'restrict' in prototypes lio_listio.3: SYNOPSIS: Use 'restrict' in prototypes makecontext.3: SYNOPSIS: Use 'restrict' in prototypes malloc_hook.3: SYNOPSIS: Use 'volatile' in prototypes mbrlen.3: SYNOPSIS: Use 'restrict' in prototypes mbrtowc.3: SYNOPSIS: Use 'restrict' in prototypes mbsnrtowcs.3: SYNOPSIS: Use 'restrict' in prototypes mbsrtowcs.3: SYNOPSIS: Use 'restrict' in prototypes mbstowcs.3: SYNOPSIS: Use 'restrict' in prototypes
Quoted 8 lines
mbtowc.3: SYNOPSIS: Use 'restrict' in prototypes mempcpy.3: SYNOPSIS: Use 'restrict' in prototypes mq_getattr.3: SYNOPSIS: Use 'restrict' in prototypes mq_receive.3: SYNOPSIS: Use 'restrict' in prototypes posix_spawn.3: SYNOPSIS: Use 'restrict' in prototypes posix_spawn.3: SYNOPSIS: Use 'restrict' in prototypes printf.3: SYNOPSIS: Use 'restrict' in prototypes; ffix too pthread_attr_setguardsize.3: SYNOPSIS: Use 'restrict' in prototypes
I've applied all of these.
Thanks!
Michael
Quoted 23 lines
man3/getservent_r.3 | 21 +++++++++++++-------- man3/getsubopt.3 | 4 ++-- man3/glob.3 | 4 ++-- man3/iconv.3 | 4 ++-- man3/inet_ntop.3 | 4 ++-- man3/inet_pton.3 | 3 ++- man3/lio_listio.3 | 4 ++-- man3/makecontext.3 | 6 ++++-- man3/malloc_hook.3 | 10 +++++----- man3/mbrlen.3 | 3 ++- man3/mbrtowc.3 | 5 +++-- man3/mbsnrtowcs.3 | 5 +++-- man3/mbsrtowcs.3 | 4 ++-- man3/mbstowcs.3 | 3 ++- man3/mbtowc.3 | 3 ++- man3/mempcpy.3 | 7 +++++-- man3/mq_getattr.3 | 4 ++-- man3/mq_receive.3 | 6 +++--- man3/posix_spawn.3 | 18 ++++++++++-------- man3/printf.3 | 29 ++++++++++++++++++----------- man3/pthread_attr_setguardsize.3 | 4 ++-- 21 files changed, 88 insertions(+), 63 deletions(-)
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/