Closed zappolowski closed 5 months ago
I'm not sure whether wayland allows for NULL in callbacks and couldn't find any information. So, I decided to just implement all needed handlers as empty methods to get rid of the noop functions.
This is standard practice. I've taken this from mako, but there are also plenty of other places where this is used. So I think that should be fine. It is the most clear way to write it. Does the noop function give warnings?
Does the noop function give warnings?
Yes:
src/wayland/foreign_toplevel.c:15:17: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
static void noop() {
^
void
when compiling with clang 16.0.6. gcc 13.2.1 requires -Wstrict-prototype
to warn about this as well.
As the CI builds using both compilers with -Werror
, I wanted to have this fixed (better than ignored/silenced).
Does the noop function give warnings?
Yes:
src/wayland/foreign_toplevel.c:15:17: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes] static void noop() { ^ void
when compiling with clang 16.0.6. gcc 13.2.1 requires
-Wstrict-prototype
to warn about this as well.As the CI builds using both compilers with
-Werror
, I wanted to have this fixed (better than ignored/silenced).
I tried reproducing this warning, but I couldn't on gcc 13.2.1. But I have one more idea to maybe still be able to keep the noop function, namely by using variadic arguments. Let me know if that works
static void noop(...) {
}
I tried reproducing this warning, but I couldn't on gcc 13.2.1.
I can get an compilation error when using
$ env CFLAGS='-Werror -Wstrict-prototypes' make CC=gcc -B src/wayland/foreign_toplevel.o
on gcc 13.2.1 or
$ env CFLAGS=-Werror make CC=clang -B src/wayland/foreign_toplevel.o
on clang 16.0.6.
But I have one more idea to maybe still be able to keep the noop function, namely by using variadic arguments. Let me know if that works
static void noop(...) { }
I've already tried that. Two issues with this approach
- variadic functions need at least one named parameter before the ellipsis (this is not that bad, as all callbacks use
void *user_data
as first argument).- the function signatures are still considered incompatible by the compiler:
error: incompatible function pointer types initializing 'void (*)(void *, struct zwlr_foreign_toplevel_handle_v1 *, const char *)' with an expression of type 'void (void *, ...)' [-Wincompatible-function-pointer-types]
which happens for both compilers.
Attention: 20 lines
in your changes are missing coverage. Please review.
Comparison is base (
2fcea84
) 65.45% compared to head (fe5ac68
) 65.39%.
Files | Patch % | Lines |
---|---|---|
src/wayland/wl.c | 0.00% | 14 Missing :warning: |
src/output.c | 0.00% | 2 Missing :warning: |
src/wayland/foreign_toplevel.c | 0.00% | 2 Missing :warning: |
src/settings.c | 50.00% | 1 Missing :warning: |
test/queues.c | 0.00% | 1 Missing :warning: |
:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
I tried reproducing this warning, but I couldn't on gcc 13.2.1.
I can get an compilation error when using
$ env CFLAGS='-Werror -Wstrict-prototypes' make CC=gcc -B src/wayland/foreign_toplevel.o
on gcc 13.2.1 or
$ env CFLAGS=-Werror make CC=clang -B src/wayland/foreign_toplevel.o
on clang 16.0.6.
But I have one more idea to maybe still be able to keep the noop function, namely by using variadic arguments. Let me know if that works
static void noop(...) { }
I've already tried that. Two issues with this approach
1. variadic functions need at least one named parameter before the ellipsis (this is not that bad, as all callbacks use `void *user_data` as first argument). 2. the function signatures are still considered incompatible by the compiler: `error: incompatible function pointer types initializing 'void (*)(void *, struct zwlr_foreign_toplevel_handle_v1 *, const char *)' with an expression of type 'void (void *, ...)' [-Wincompatible-function-pointer-types]` which happens for both compilers.
I can indeed reproduce it with the line you gave me. But it seems -Wstrict-prototypes is not included in -Wall. So I'm fine with leaving out this warning, so we can keep our noop functions (to me these are more clear than having empty functions).
I can indeed reproduce it with the line you gave me. But it seems -Wstrict-prototypes is not included in -Wall. So I'm fine with leaving out this warning, so we can keep our noop functions (to me these are more clear than having empty functions).
This just works for builds using gcc
. clang
will still fail as there -Wall
also includes -Wstrict-prototypes
. One solution (I strongly dislike) is to use -Wall -Wno-strict-prototypes
for clang
.
I can indeed reproduce it with the line you gave me. But it seems -Wstrict-prototypes is not included in -Wall. So I'm fine with leaving out this warning, so we can keep our noop functions (to me these are more clear than having empty functions).
This just works for builds using
gcc
.clang
will still fail as there-Wall
also includes-Wstrict-prototypes
. One solution (I strongly dislike) is to use-Wall -Wno-strict-prototypes
forclang
.
Yeah, okay it's better to just fix the warning, since the -Wstrict-prototypes can actually give some good warnings as well.
Maybe rename the functions that do nothing with empty_FUNCNAME
. This makes it more clear in the listener structs.
Maybe rename the functions that do nothing with empty_FUNCNAME. This makes it more clear in the listener structs.
When making use of these callbacks later (I don't know whether this will ever happen), one needs to remember to rename them or they will be misleading. I don't know, whether this is actually useful then.
Okay, I've merged it now
As noted in #1229 the code does not compile cleanly on recent compilers.
_Static_assert
.NULL
in callbacks and couldn't find any information. So, I decided to just implement all needed handlers as empty methods to get rid of thenoop
functions.const
within the scope of the function and the warning is suppressed.At the moment, this builds without warnings on GCC 13.2.1 and clang 16.0.6.
Fixes #1229