Repository navigation
build(cmake): compile C with -Wpedantic (#2623) - #2643
Conversation
zackees
left a comment
There was a problem hiding this comment.
Reviewed the full diff (36 files, +265/-175). The change is mechanical and the shape is right: -Wpedantic is opt-in for C only, vendored code is exempted at target/per-source level with no global -Wno-pedantic (glad, libcaption, librtmp — the #516 precedent), and first-party findings are fixed at the source.
What I verified in the diff:
cmake/common/compiler_common.cmakeadds-Wpedanticto_obs_clang_c_options;cmake/linux/compilerconfig.cmakeadds it to the GNU C option string. C++ headers (-Wno-shadow,-Winvalid-offsetof) are untouched.__FUNCTION__→__func__throughout (pulse, image-file, obs-output*, bpm, nvenc, obs-output-delay, profiler) — equivalent, C99-standard.return <void expr>;removed in void functions (device_sync_destroy,obs_key_to_str,obs_nix_*_key_to_str) — no behaviour change.%pargument casts ((const void *)samples, profiler entries, pipewire pointers) — no behaviour change.%m→strerror(errno)in pipewire: equivalent to glibc's%m, anderrnois read before theblogcall.- Object↔function-pointer conversions now go through a union
{.obj = dlsym(...)} / .fn(graphics imports, module exports, nvenc loaders, vlc-video, the cmocka interposers) — the GNU-sanctioned way to do this without a pedantic-rejected cast. test_audio_buffering_subsample.cdropsunsigned __int128forutil_mul64_64/util_div128_32;ns * rate / 1e9still fits the low word, so the arithmetic is unchanged.- No
docs/features.mdline needed: this is a build/tooling change with no user-visible behaviour.
Two things to settle before this lands, neither a code defect:
- macOS is not exercised by PR CI.
_obs_clang_c_optionsis the list the macOS Clang C build uses, but the PR'sBuild 🧱 / macOSjob is skipped on pull requests. A macOS-only-Wpedanticfinding would first appear in the release gate. Either confirm a macOS build was run by hand, or say in the PR that the first macOS signal will be the release lane. The Windows cross-compile (Cross Compile 🧰 (win-x64)) is still pending here too; the vendored exemptions name AppleClang/Clang/GNU, so clang-cl is the uncovered combination. obs_enum/obs_enum_uuidchanged shape. They now takebool (*)(void *, void *), and each caller casts frombool (*)(void *, obs_*_t *). That removes the pedantic warning (the old code stored avoid *in a function pointer), but the cast itself is still a function-pointer conversion between incompatible types — benign on every ABI this ships on, not a standard fix. Not blocking; worth a comment inobs.c.hso a later reader doesn't assume it is type-safe.
I could not run the compile here; this review is from the diff and the CI evidence in the PR body. Queue the PR once uv run -m workflow.coordinator checks obs-rust/obs-studio 2643 exits 0 (Fast Gate and the Windows cross-compile were still running when I looked).
Add -Wpedantic to the C warning lists (clang C list in compiler_common.cmake; the GNU C-only list in compilerconfig.cmake). deps/glad is exempted at the target level in the follow-up, not with a global -Wno-pedantic. RED: the Tier 2 libobs build then fails on the first -Wpedantic finding.
-Wpedantic rejects casts and implicit conversions between object and function pointers (ISO C forbids them). Where a value crosses that boundary anyway, copy it through a union, which the compiler elides: * os_dlsym() results: obs-module.c.h, graphics-imports.c.h, vlc-video, obs-nvenc; the two dlsym() tests. * a callback passed to a void * validator: obs_enum()/obs_enum_uuid() now take the callback as a function pointer, and gs_enum_adapters(), obs_encoder_ start(), obs_encoder_stop() and obs_source_enum_filters() pass it through a union. * test_graphics_host_functions.c: the entry-point null checks.
* __FUNCTION__ -> __func__ (elsewhere in this branch) and, here, "return with
expression in a void function": the translate_key() macro returns void, so
drop the redundant return in the X11 and Wayland key translators.
* %p formatting on non-void * arguments: cast to (const void *) rather than
relying on the implicit conversion.
* %m (a gnu_printf extension) in linux-pipewire: use strerror(errno).
* empty initializer braces before C23: struct dstr str = {0}.
* enum spa_media_subtype is used before pipewire.h defines it.
* size_t frames_at(): util_uint128 instead of __int128.
5fb5299 to
ab7a4c9
Compare
|
CI (run 40517182701, head 5fb5299) is red on both lanes that build C: 1. The 2.
Not touched: Left to the author — this is the PR's own change, not a master regression (head 5fb5299 is the failing commit, and master is green on this job). Re-run |
|
Rebased onto master ( Failure ( The Rebased head:
|
Follow-up to the rename: the vendored librtmp sources are also compiled by the cmocka test targets (test_amf and the test_rtmp_* family, which build librtmp/amf.c, hashswf.c and rtmp.c as their own TUs), where the plugins/obs-outputs source-file exemption does not reach. Their __FUNCTION__ use still tripped -Wpedantic, so the Tier 2 build stopped there. Follow the #516 precedent for this directory (existing C tests are never edited to satisfy a new warning): add the blanket -Wno-pedantic alongside the -Wno-shadow / -Wno-cast-qual / -Wno-double-promotion lines, and drop the four test edits that worked around the finding.
|
Second CI failure, finished (
The Fixed the way this directory already handles the #516 flags (
|
Deleting the `return` before translate_key() in obs-nix-x11.c.h and
obs-nix-wayland.c.h to clear the -Wpedantic "return with a value in a void
function" was not behaviour-preserving: the switch cases never `break`,
they relied on that return to leave the function, so every listed key fell
through into the following cases and came out as the last one ("Escape"),
then ran on into the F-key and platform-context paths below.
test_hotkey_translations.c caught it once the build stopped masking the
tests: `OBS_KEY_INSERT: got "Escape", expected "Insert"` (9 cases).
`return translate_key(...)` is exactly what -Wpedantic rejects, and
`return (void)translate_key(...)` is rejected too, so keep the call and
make the exit explicit. No behaviour change on any other key.
|
Third failure — now the tests, which the build error had been masking ( With the build fixed, Cause: dropping the
|
|
CI is green on That closes both acceptance criteria that CI can check: the Linux and macOS CMake builds compile C with Auto-merge is on and the PR is in the merge queue. Handed off to the coordinator. |
Compile first-party C with
-Wpedanticand clear the findings it surfaces.Refs #2623 (Linux verified here; the macOS leg is left to PR/release CI).
Refs #516 (the vendored-exemption precedent for
-Wcast-qual/-Wshadow).What this does
-Wpedanticfor C only — added to_obs_clang_c_options(
cmake/common/compiler_common.cmake) and to the GNU C option string incmake/linux/compilerconfig.cmake. C++ is untouched.deps/glad(object <-> function pointer casts),deps/libcaption, andlibrtmp in
plugins/obs-outputs(__FUNCTION__). No global-Wno-pedantic.-Wno-*and no#pragma, so a new violation still fails underCMAKE_COMPILE_WARNING_AS_ERROR=ON.Findings and how they are fixed
__FUNCTION__(not ISO C)__func__os_dlsym(),dlsym(), a callback passed to avoid *validator)obs_enum()/obs_enum_uuid()now take the callback as a function pointer instead ofvoid *returnwith expression in avoidfunction (thetranslate_key()macro returnsvoid)returnin the X11/Wayland key translators%pon a non-void *argument(const void *)cast%m(gnu_printfextension) in linux-pipewirestrerror(errno)struct dstr str = {})= {0}enum spa_media_subtypein linux-pipewirespa/param/format.h__int128in a cmocka testutil_uint128helpersVerification
Tier 2 (Docker) build stage,
-Wpedanticon and warnings-as-error at itsdefault (
ON), from this branch:Zero
warning:lines in the run../lint(local gate lint lane) is green,including
ci/test_build_groups.py(the new file-local macros are#undefed atthe end of their file, per BUILD.md rule 5).