Skip to contentSkip to conversation

makecontext.3: Fix function declarator with empty parentheses.

PATCH In review Alejandro Colomar 3 participants 6 messages Mar 4, 2021 – Mar 5, 2021 1 message not in the archive Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 makecontext.3: Fix function declarator with empty parentheses.

glibc uses 'void (*f)(void)' for makecontext()'s second parameter.

C11 marked function declarators with empty parentheses as obsolescent:

Quoted 4 lines

6.11.6 Function declarators
1 The use of function declarators with empty parentheses (not
prototype-format parametertype declarators) is an obsolescent feature.

Let's use the correct syntax by explicitly using '(void)'.

.../glibc$ grep_glibc_prototype makecontext stdlib/ucontext.h:51:
extern void makecontext (ucontext_t *__ucp, void (*__func) (void),

			 int __argc, ...) __THROW;

.../glibc$

---
 man3/makecontext.3 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
man3/makecontext.3 +2 -1
index 83720dd2c..ac9afcf69 100644
@@ -32,7 +32,8 @@ makecontext, swapcontext \- manipulate user context
 .nf
 .B #include <ucontext.h>
 .PP
-.BI "void makecontext(ucontext_t *" ucp ", void (*" func ")(), int " argc ", ...);"
+.BI "void makecontext(ucontext_t *" ucp ", void (*" func ")(void), int " argc \
+", ...);"
 .BI "int swapcontext(ucontext_t *" oucp ", const ucontext_t *" ucp );
 .fi
 .SH DESCRIPTION
Signature · 1 line
2.30.1.721.g45526154a5

A message that is not in the archive (sent off-list or not yet received): CAKCAbMg3G4EAeuUhN9EQTDnrTSD0sPoH0uH1=kkpfj9qYorPdg@mail.gmail.com

#2 lore raw

* Zack Weinberg:

Quoted 2 lines

This is actually the Austin Group’s primary rationale for deprecating makecontext and its relatives.

That's a bit surprising because open and fcntl have a similar problem:
the argument type before the ellipsis cannot be int.

And doesn't a later C standard add a generic function pointer type?

Thanks,
Florian

#3 lore raw

Hello Zack, Florian, Michael,

Quoted 10 lines · Alejandro Colomar

glibc uses 'void (*f)(void)' for makecontext()'s second parameter.

C11 marked function declarators with empty parentheses as obsolescent:

Quoted 4 lines

6.11.6 Function declarators
1 The use of function declarators with empty parentheses (not
prototype-format parameter type declarators) is an obsolescent feature.

I quoted C11, but it's also in C99 (same section 6.11.6.1) and in C89 (in section 3.9.4) with the same wording.

Quoted 12 lines

Let's use the correct syntax by explicitly using '(void)'.

.../glibc$ grep_glibc_prototype makecontext stdlib/ucontext.h:51:
extern void makecontext (ucontext_t *__ucp, void (*__func) (void),

			 int __argc, ...) __THROW;

.../glibc$

---

Quoted 7 lines · Zack Weinberg

On Thu, Mar 4, 2021 at 2:48 PM Alejandro Colomar via Libc-alpha <[email protected] <mailto:[email protected]>> wrote:

glibc uses 'void (*f)(void)' for makecontext()'s second parameter.

Did you mean ‘void (*f)()’ ?

I did actually mean 'void (*f)(void)'. Glibc uses that for the prototype (as you can see from my commit message (see above)), and as I confirmed just now, it also uses that type for the definition of the function:

[
.../glibc$ grep -rn '^makecontext\s*(' stdlib/makecontext.c:22:makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
.../glibc$
]

However, I should have read the manual page (I must admit that I only read the SYNOPSIS and EXAMPLES sections of the manual page and the glibc source before writing the patch). It's clear that the prototype that was being used in the manual page was more correct (in the sense that it more accurately represented the actual expected function pointer) than the glibc prototype (eventhough the glibc prototype is more standards conforming).

So my patch is wrong.

Florian, should I file a bug in glibc's bugzilla?

Quoted 11 lines

C11 marked function declarators with empty parentheses as obsolescent:

> 6.11.6 Function declarators
> 1 The use of function declarators with empty parentheses (not
> prototype-format parametertype declarators) is an obsolescent
> feature.

Quoted 8 lines

Let's use the correct syntax by explicitly using '(void)

Unfortunately this change would be incorrect. makecontext’s second parameter really is a pointer to a function that takes any number and type of arguments, and there is no other way to write that in C than ‘void (*)()’. Which, yes, means this function cannot be declared in conformant C11.

Yes, you're completely right! Thanks for noticing.

Quoted 9 lines · Florian Weimer

* Zack Weinberg:

Quoted 2 lines

This is actually the Austin Group’s primary rationale for deprecating makecontext and its relatives.

That's a bit surprising because open and fcntl have a similar problem:
the argument type before the ellipsis cannot be int.

And doesn't a later C standard add a generic function pointer type?

Ahh, I found it. It's not in any standard, yet, but we might see it soon in C2x: <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2230.htm>

Actually, one of the proposals is to reuse the empty parentheses for this generic function pointer (thus removing it as a valid function declaration), so the current prototype used in the manual page would still be correct.

Another proposal is to add 'funcptr_t' for that, which seems to be compatible with older standards.

You could even use it in glibc.

Michael, please ignore this patch.

Thank you all,

Alex

Signature · 3 lines
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
#4 lore raw

* Alejandro Colomar:

Quoted 20 lines

I did actually mean 'void (*f)(void)'. Glibc uses that for the prototype (as you can see from my commit message (see above)), and as I confirmed just now, it also uses that type for the definition of the function:

[
.../glibc$ grep -rn '^makecontext\s*(' stdlib/makecontext.c:22:makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
.../glibc$
]

However, I should have read the manual page (I must admit that I only read the SYNOPSIS and EXAMPLES sections of the manual page and the glibc source before writing the patch). It's clear that the prototype that was being used in the manual page was more correct (in the sense that it more accurately represented the actual expected function pointer) than the glibc prototype (eventhough the glibc prototype is more standards conforming).

Quoted 3 lines

So my patch is wrong.

Florian, should I file a bug in glibc's bugzilla?

I don't know. SUSv2 has (void *func) (), which would make this a glibc bug. I'm not sure if I have easy access to POSIX.1 from 2001, which I believe still has this function.

I am not sure if all glibc implementations of makecontext can be used to call variadic functions.

Thanks,
Florian

#5 lore raw
Quoted 3 lines · Florian Weimer via Libc-alpha

I don't know. SUSv2 has (void *func) (), which would make this a glibc bug. I'm not sure if I have easy access to POSIX.1 from 2001, which I believe still has this function.

https://pubs.opengroup.org/onlinepubs/009695399/functions/makecontext.html

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
#6 lore raw
In reply to Florian Weimer

Hi Florian,

Quoted 9 lines · Florian Weimer

* Alejandro Colomar:

Quoted 1 line

Florian, should I file a bug in glibc's bugzilla?

I don't know. SUSv2 has (void *func) (), which would make this a glibc bug. I'm not sure if I have easy access to POSIX.1 from 2001, which I believe still has this function.

I am not sure if all glibc implementations of makecontext can be used to call variadic functions.

I reported the bug: <https://sourceware.org/bugzilla/show_bug.cgi?id=27523>

Thanks,

Alex

Signature · 3 lines
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/