Skip to content

build(cmake): compile C with -Wpedantic (#2623) - #2643

Merged
zackees merged 6 commits into
masterfrom
infra/2623-wpedantic
Oct 27, 2026
Merged

zackees merged 6 commits into
masterfrom
infra/2623-wpedantic

Conversation

@zackees

@zackees zackees commented Oct 27, 2026

Copy link
Copy Markdown
Member

Compile first-party C with -Wpedantic and 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

  1. -Wpedantic for C only — added to _obs_clang_c_options
    (cmake/common/compiler_common.cmake) and to the GNU C option string in
    cmake/linux/compilerconfig.cmake. C++ is untouched.
  2. Vendored code exempted at the target / per-source level, mirroring build: Maximum C/C++ warning strictness with -Werror on every platform (cross-compiled with soldr) #516:
    deps/glad (object <-> function pointer casts), deps/libcaption, and
    librtmp in plugins/obs-outputs (__FUNCTION__). No global -Wno-pedantic.
  3. First-party findings fixed at the source — no per-file -Wno-* and no
    #pragma, so a new violation still fails under
    CMAKE_COMPILE_WARNING_AS_ERROR=ON.

Findings and how they are fixed

Finding Fix
__FUNCTION__ (not ISO C) __func__
object <-> function pointer conversions (os_dlsym(), dlsym(), a callback passed to a void * validator) copy through a union, which the compiler elides; obs_enum()/obs_enum_uuid() now take the callback as a function pointer instead of void *
return with expression in a void function (the translate_key() macro returns void) dropped the redundant return in the X11/Wayland key translators
%p on a non-void * argument explicit (const void *) cast
%m (gnu_printf extension) in linux-pipewire strerror(errno)
empty initializer braces before C23 (struct dstr str = {}) = {0}
forward reference to enum spa_media_subtype in linux-pipewire include spa/param/format.h
__int128 in a cmocka test util_uint128 helpers

Verification

Tier 2 (Docker) build stage, -Wpedantic on and warnings-as-error at its
default (ON), from this branch:

== environment: user=root nproc=16 cmake=4.2.3 cc=cc (Ubuntu 15.2.0-16ubuntu1) 15.2.0
== configure + build (libobs and libobs-c-reference)
== libobs exported symbols, C vs Rust
IDENTICAL (1766 symbols)
RUN_DONE rc=0

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 at
the end of their file, per BUILD.md rule 5).

@zackees zackees left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.cmake adds -Wpedantic to _obs_clang_c_options; cmake/linux/compilerconfig.cmake adds 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.
  • %p argument casts ((const void *)samples, profiler entries, pipewire pointers) — no behaviour change.
  • %m → strerror(errno) in pipewire: equivalent to glibc's %m, and errno is read before the blog call.
  • 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.c drops unsigned __int128 for util_mul64_64/util_div128_32; ns * rate / 1e9 still fits the low word, so the arithmetic is unchanged.
  • No docs/features.md line needed: this is a build/tooling change with no user-visible behaviour.

Two things to settle before this lands, neither a code defect:

  1. macOS is not exercised by PR CI. _obs_clang_c_options is the list the macOS Clang C build uses, but the PR's Build 🧱 / macOS job is skipped on pull requests. A macOS-only -Wpedantic finding 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.
  2. obs_enum / obs_enum_uuid changed shape. They now take bool (*)(void *, void *), and each caller casts from bool (*)(void *, obs_*_t *). That removes the pedantic warning (the old code stored a void * 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 in obs.c.h so 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.
…#2623)

glad (object<->function pointer casts), librtmp (its __FUNCTION__ use) and
libcaption (extra ';', %p) are vendored third-party code, exempted at the
target/per-file level as #516 does, not with a global -Wno-pedantic.

Also replace the first-party __FUNCTION__ uses with the ISO C __func__.
-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.
@zackees
zackees force-pushed the infra/2623-wpedantic branch from 5fb5299 to ab7a4c9 Compare October 27, 2026 14:18
@zackees

zackees commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

CI (run 40517182701, head 5fb5299) is red on both lanes that build C: Build 🧱 / Fast Gate ⚡ and Build 🧱 / Rust Tier 2 Linux 🐧 (build). Both stop on the same -Wpedantic + -Werror pair — cc1: all warnings being treated as errors — so this is the flag landing, not a flake. Two sites, and neither is the ones the local Tier 2 run caught.

1. MODULE_EXPORT redefined — libobs/core+ unity build

libobs/obs-module.c.h:36:9: error: 'MODULE_EXPORT' redefined [-Werror]
   36 | #define MODULE_EXPORT(field, name)                                 \
In file included from libobs/build/libobs.pch.h:25,
                 from .../libobs-objects.dir/cmake_pch.h:4:
libobs/obs-module.h:26:9: note: this is the location of the previous definition
   26 | #define MODULE_EXPORT EXPORT

The #undef at the end of obs-module.c.h (BUILD.md rule 5) does not cover the entry: the PCH pulls in obs-module.h (#define MODULE_EXPORT EXPORT) before the unity TU includes obs-module.c.h, so the differing redefinition is a warning at the definition itself. It only appears in the build/libobs.core+.h.c group, which is why a non-unity build is clean. A matching #undef MODULE_EXPORT immediately before line 36 fixes it (same shape as the trailing guard).

2. __FUNCTION__ in librtmp, reached through the cmocka targets

plugins/obs-outputs/librtmp/amf.c:1069:18: error: ISO C does not support '__FUNCTION__' predefined identifier [-Werror=pedantic]

FAILED: list from the same run: test/cmocka/CMakeFiles/test_amf.dir/__/__/plugins/obs-outputs/librtmp/amf.c.o, plus test_amf3_classname, test_amf3_terminator, test_amf_decode (amf.c, hashswf.c, rtmp.c), test_flv_mux, test_rtmp_chunk_size, test_rtmp_dbr_user_bitrate, test_rtmp_error, test_rtmp_send_thread_leak — i.e. every cmocka test recompiles the librtmp sources as its own TU, so the target/per-source exemption added under plugins/obs-outputs does not reach them. The exemption has to be extended to the test/cmocka targets that compile those sources (target-scoped option there), not a per-file #pragma.

Not touched: test_pipewire_frame_pacing was also in the failed list, so it likely recompiles plugins/linux-pipewire/frame-pacing.c on the same path and will need the same treatment once the first two are fixed.

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 Build 🧱 / Rust Tier 2 Linux 🐧 (build) after the fix; the console summary is bounded, so read the full compile log rather than the build_errors.py tail.

@zackees

zackees commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

Rebased onto master (c4edc1d21) and fixed the PR CI failure.

Failure (Build 🧱 / Fast Gate ⚡, run 40517182701, job 122234010049):

libobs/obs-module.c.h:36:9: error: 'MODULE_EXPORT' redefined [-Werror]
libobs/obs-module.h:26:9: note: this is the location of the previous definition
cc1: all warnings being treated as errors
FAILED: libobs/CMakeFiles/libobs-objects.dir/build/libobs.core+.h.c.o

The os_dlsym() union helper I added in the "stop converting between object and function pointers" commit was named MODULE_EXPORT, which collides with the object-like MODULE_EXPORT that libobs/obs-module.h (pulled in by libobs.pch.h) already defines in the same unity group (libobs/build/libobs.core+.h.c). Under -Wpedantic an incompatible macro redefinition is a pedantic error. Renamed the local helper to LOAD_MODULE_SYMBOL (and its trailing #undef), which is the only new macro in the branch that collided — blog, GRAPHICS_IMPORT[_OPTIONAL], NVH_FAILED/NV_FAILED/error_hr all already existed on master with only __FUNCTION__ -> __func__.

Rebased head: ab7a4c911

commit was
39b77c14a build(cmake): Compile C with -Wpedantic (#2623) 72cb9588a
f8c07e615 build(cmake): Exempt vendored glad/libcaption/librtmp (#2623) 66de6df67
cb6a6e04a fix(c): stop converting between object and function pointers (#2623) 79d535684 (+ the rename)
ab7a4c911 fix(c): silence the remaining -Wpedantic findings (#2623) 5fb5299b3

./lint is green on the rebased head; PR CI is re-running.

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.
@zackees

zackees commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

Second CI failure, finished (a9cd25387, on top of the rebase/rename in ab7a4c911).

__FUNCTION__ in librtmp, reached through the cmocka targets

The plugins/obs-outputs source-file exemption does not reach the cmocka tests: test_amf, test_amf3_classname, test_amf3_terminator, test_amf_decode, test_flv_mux and the test_rtmp_* family each compile librtmp/amf.c, hashswf.c and rtmp.c as their own TUs, so __FUNCTION__ still tripped -Wpedantic there (and hashswf.c:695 "empty translation unit"). test_pipewire_frame_pacing, which recompiles linux-pipewire/frame-pacing.c on the same path, needs the same cover.

Fixed the way this directory already handles the #516 flags (-Wno-shadow, -Wno-cast-qual, -Wno-double-promotion): a blanket -Wno-pedantic in test/cmocka/CMakeLists.txt, because existing C tests are never edited to satisfy a new warning. That also lets the four test edits the branch carried (config_close_fault.c, test_audio_buffering_subsample.c, test_graphics_host_functions.c, test_output_end_capture_thread_join.c) be reverted to master.

-Wpedantic is still in the C flag lists and every first-party product target still enforces it under CMAKE_COMPILE_WARNING_AS_ERROR=ON; only the test directory is exempt, as the #516 flags are.

@zackees
zackees enabled auto-merge October 27, 2026 14:23
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.
@zackees

zackees commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

Third failure — now the tests, which the build error had been masking (36dbd8a23).

With the build fixed, Build 🧱 / Rust Tier 2 Linux 🐧 (tests ON) and (tests OFF) ran and test_hotkey_translations failed 9 cases:

OBS_KEY_INSERT: got "Escape", expected "Insert"
OBS_KEY_DELETE: got "", expected "A del"

Cause: dropping the return before translate_key(...) in obs-nix-x11.c.h / obs-nix-wayland.c.h (the "return with a value in a void function" fix) was not behaviour-preserving. Those switch cases never break — they relied on the return to leave the function, so every listed key fell through into the following cases, came out as the last one ("Escape"), and then ran on into the F-key and platform-context paths below.

return translate_key(...) is what -Wpedantic rejects, and return (void)translate_key(...) is rejected too (checked with -Wpedantic -Werror on both gcc and clang), so the call stays and the exit is explicit: translate_key(...); return;. Behaviour is back to master's for every key.

@zackees

zackees commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

CI is green on 36dbd8a23 (run 40523842267) — CI Gate ✅, including Rust Tier 2 macos-26, Rust Tier 2 windows-2025-vs2026, Fast Gate ⚡ and both Rust Tier 2 Linux 🐧 (tests ON/OFF) plus their serial halves, and the hotkey-translation cases that failed last run.

That closes both acceptance criteria that CI can check: the Linux and macOS CMake builds compile C with -Wpedantic and no findings; deps/glad (and the other vendored targets) are exempt at target/source level, not with a global -Wno-pedantic; the flag still applies under CMAKE_COMPILE_WARNING_AS_ERROR=ON; and the only blanket exemption is test/cmocka, which follows the #516 precedent for the tests.

Auto-merge is on and the PR is in the merge queue. Handed off to the coordinator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant