Skip to content

build(libobs): make the conversions explicit (#2625) - #2877

Merged
zackees merged 2 commits into
masterfrom
infra/2625-conversion-libobs
Oct 29, 2026
Merged

zackees merged 2 commits into
masterfrom
infra/2625-conversion-libobs

Conversation

@zackees

@zackees zackees commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Slice of #2625 (the libobs target). Refs #2625, does not close it.

RED 02e5e158a puts -Wconversion;-Wsign-conversion;-Wfloat-conversion
on the libobs targets instead of letting them inherit the global pins: the
object library, the shared libraries' own host sources, and the C reference.
The replay of the tree's 1286 C units (ci/warning_findings.py over the
compdb, the cache bypassed) reports 198 conversion findings:

directory findings options
libobs/ (own sources) 104 75 -Wsign-conversion, 29 -Wconversion
libobs/graphics/libnsgif (vendored) 39 21 -Wconversion, 18 -Wsign-conversion
libobs/graphics 23 23 -Wsign-conversion
libobs/util 15 15 -Wsign-conversion
libobs/media-io 13 13 -Wsign-conversion
libobs/callback 3 3 -Wsign-conversion
libobs/audio-monitoring/pulse 1 1 -Wconversion

libnsgif stays exempt, exactly as it already is for -Wcast-qual,
-Wshadow and -Wpedantic in the other vendored C (librtmp, uthash): it is
vendored C89 and the differential oracle for the Rust port (#2466, #2488),
and this port does not edit it. The exemption is a per-source option list
guarded by compiler id, in the same commit, so the 39 are out of scope here;
every other unit of the target is covered. The replay's remaining entries are
noise the helper does not filter for this class: -Wswitch in the existing
test_qsv_update.c (it includes obs-qsv11.c.h; existing C tests are never
edited) and -Wpedantic on the empty PCH units.

GREEN 196b1c55c states the 159 conversions in 30 files at their
boundaries; the same replay reports 0 conversion findings, and a real
cmake --build --target libobs libobs-c-reference in the warm tree compiles
51 C objects with 0 warning:/error: lines and links both libraries.

Per area:

  • obs-hotkey.c.h — the custom uthash hash function returns the id modulo
    UINT_MAX, so it narrows to the unsigned int uthash's hash variable is;
    the background flag mask is cleared through a uint32_t complement. One
    cast clears 22 findings (every HASH_ADD/HASH_FIND instantiation).
  • obs-scene.c.h, obs-source.c.h, obs-display.c.h, texture-render.c.h,
    obs-video.c.h — source sizes and viewport sizes are uint32_t end to end
    (obs_source_get_width/height, obs_transition_set_size,
    gs_texrender_begin_with_color_space, gs_set_viewport); where an internal
    helper still takes int (obs_source_render_route_size_skip, whose c_int
    signature the Rust FFI pins) the boundary is cast once instead.
  • obs.c.h, obs-audio-controls.c.h, obs-output.c.h,
    obs-encoder*.c.h, obs-output-interleave.c.h, obs-source-audio-timing.c.h
    — the audio-frame, mixer-index, encoder-frame and interleave-time values are
    cast to the width of the API or field that stores them (bmalloc/memcpy
    lengths, audio_output_connect mix index, obs_data_set_int's long long,
    the profiler's double, the reconnect backoff as a float product).
  • libobs/graphics/* — size_t lengths built from the uint32_t image
    geometry ((size_t)cy * linesize, frame->linesize), and the mipmap flag
    masks cleared through a uint32_t complement; image-file.c.h also casts
    the frame index to libnsgif's uint32_t at the boundary.
  • libobs/util/* — the timespec arithmetic keeps int64_t throughout
    (both operands cast at the uint64_t offset), pointer differences become
    size_t, off_t is cast where size_t is subtracted, rand() gives the
    portal id as uint32_t.
  • libobs/media-io/* — av_image_alloc/swr_alloc_set_opts2/swr_convert
    take int widths and channel counts, so the uint32_t geometry, sample
    rate and frame count are cast at those calls; the scaler's dst_linesizes
    and dst_heights are size_t in the copy loop.
  • callback/calldata.c.h — the grow/shrink memmove offsets are size_t
    differences from the fixed stack buffer.
  • pulseaudio-output.c.h — pa_usec_to_bytes returns size_t; the buffer
    attribute is a uint32_t.

The first run of this PR's Tier 2 lane caught one real semantic slip of mine:
obs_encoder_audio_start_audio_pts() adds size_t framesize to an int64_t,
and the original cur_pts + framesize computed the sum in unsigned after the
usual arithmetic conversions. The unchanged C test pins exactly that
((INT64_MAX, 1) == INT64_MIN, (-1, SIZE_MAX) == -2); my (int64_t) cast
made the addition signed, which UBSan reported as signed integer overflow
and made test_encoder_audio_start_steps fail in both modes. The sum is now
stated as (int64_t)((uint64_t)cur_pts + (uint64_t)framesize): same value,
defined arithmetic, and the test's overflow case is the documentation. The
timespec arithmetic in util/platform-time.c.h was converted the same way
for the same reason (the original also added in uint64_t).

No behaviour change: every cast keeps the value the code already computed, and
no narrowing cast is used where the range is not already enforced. No pragmas
and no per-file -Wno-* were added for first-party sources. The global pins
stay until every target is ratcheted.

Local gate: ./lint ok (41 s). PR CI's Tier 2 lane builds libobs and runs the
unchanged cmocka suites, so it is the merge gate for this target.

No docs/features.md line: build tooling only.

The libobs targets now carry -Wconversion, -Wsign-conversion and
-Wfloat-conversion instead of inheriting the global -Wno-* pins: the object
library, the shared libraries' own host sources and the C reference. The
vendored libnsgif keeps the per-source exemption the other vendored C has
(librtmp, uthash); it is the differential oracle for the Rust port.

Refs #2625.

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

Coordinator review — read the full 31-file diff and the two commits (02e5e158a RED, GREEN head c885…).

Verdict: correct as a conversion-warning ratchet; no blocking findings. Two notes at the end.

Build wiring. The three conversion groups are added to every libobs target (object library, the shared libraries' host sources, the C reference), and libnsgif's four ported-nsgif units get the per-source -Wno-conversion;-Wno-sign-conversion exemption, matching the existing vendored-C treatment (librtmp, uthash). The global pins stay for the un-ratcheted targets. Since -Wno-conversion covers -Wfloat-conversion, the vendored tree stays quiet.

Casts — checked each against the value it carries.

  • graphics-ffmpeg.c.h: (size_t)info->cy * linesize and (size_t)frame->linesize[0] preserve the old implicit size_t conversion; (size_t)info->cx * (size_t)info->cy prevents the int product overflowing before the multiply.
  • obs-audio-controls.c.h, audio-resampler-ffmpeg.c.h, video-scaler-ffmpeg.c.h: all casts are at API boundaries whose parameter types are int/size_t; the values are channel counts, sample rates and frame sizes, all well inside int.
  • obs-output.c.h: (size_t)payload_size, (size_t)cea708_render(...) and (size_t)idx match the parameters; (uint32_t)((float)reconnect_retry_cur_msec * reconnect_retry_exp) keeps the float multiplication the old expression used.
  • obs-source-audio-timing.c.h: (uint64_t)sync_offset on a uint64_t timestamp is modular addition — the same bit result as the old signed add, including a negative offset.
  • obs-scene.c.h/obs-source.c.h: the width/height locals become uint32_t, which is what obs_source_get_width/get_base_width return; the one (int) pair in obs_source_process_filter_begin_with_color_space is cast back to uint32_t for gs_texrender_begin_with_color_space, so the value is unchanged.
  • obs-nix-x11.c.h: (xcb_keycode_t)/(uint8_t) casts fit X11's 8-bit keycodes, and (size_t)num_keysyms is the allocated byte count.
  • profiler-io.c.h: ((uint64_t)1 << indent) - 1 is a genuine fix — the old 1 << indent was signed and UB past bit 30.
  • The rest (calldata.c.h pointer differences, obs-hotkey.c.h flag masks, obs.c.h bmalloc sizes, platform-file.c.h/platform-time.c.h/platform-nix-portal.c.h, cf-lexer.c.h dstr_ncopy length, obs-data.c.h alignment) are identical-value casts.

Tiers/ledger. Build tooling only: no behaviour, no public API, no user-visible change, so no Tier 2/3 lane and no docs/features.md line. PR CI: 20 passed, 0 failed, 2 still running; I'll let the queue take it when they finish (the work list marks it enqueue then).

Two non-blocking notes.

  1. graphics-ffmpeg.c.h: FFmpeg may report a negative linesize for vertically flipped frames. The old implicit conversion to size_t had the same assumption, so this is not a regression — just worth a comment or an explicit AV_ABS if that path is ever reachable with this loader.
  2. extract_buffer_from_sei narrows sei_message_size() to int before widening to size_t; harmless for SEI payloads, but the type round-trip would read better without the int hop.

Fixes every implicit conversion the three groups report in libobs: 159
findings in 30 files, fixed at the call sites (the obs_*_id hash function,
the uint32_t source-size and viewport boundaries, the ffmpeg size_t lengths,
the timespec arithmetic, the xcb keycode/keysym widths, the encoder lcm and
frame-rate fields, calldata's pointer differences).

Ratchet now covers 21 targets.

Refs #2625.
@zackees
zackees force-pushed the infra/2625-conversion-libobs branch from 196b1c5 to 0f96af7 Compare October 29, 2026 07:01
@zackees
zackees added this pull request to the merge queue Oct 29, 2026
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Handed off to the coordinator.

  • Rebased onto master (bc8b13cc6) and pushed the slice as 02e5e158a (RED: the three conversion groups on the libobs targets) + 0f96af7d4 (GREEN: 159 conversions stated at 30 call-site boundaries).
  • PR CI is green end to end, including Rust Tier 2 Linux 🐧 (tests OFF/ON) and CI Gate ✅; the PR is queued (position 1).
  • ./lint ok. The local-gate stamp was not applied: the full PR CI suite already ran and passed on this HEAD, so there is no skipped Linux job to recover. Any later rebase would drop a stamp anyway — rebase and re-stamp if the queue ejects it.
  • The first Tier 2 run caught one real slip and it is recorded in the description: obs_encoder_audio_start_audio_pts() adds size_t to int64_t and the unchanged C test pins the unsigned wrap, so the fix states the sum in uint64_t rather than casting to signed (UBSan flagged the signed form; test_encoder_audio_start_steps failed in both modes until then).
  • Nothing waits on me for this PR. build(cmake): Drop the conversion pins (-Wno-conversion, -Wno-sign-conversion, -Wno-float-conversion) #2625 keeps its claim: the remaining slices are win-capture, mac-capture, the frontend-ON C++ class, and the final pin deletion.

Merged via the queue into master with commit ee3273d Oct 29, 2026
38 checks passed
@zackees
zackees deleted the infra/2625-conversion-libobs branch October 29, 2026 07:25
zackees added a commit that referenced this pull request Oct 29, 2026
…ts (#2625)

#2877 enabled -Wsign-conversion on the libobs targets but could only replay
the Linux translation units. AppleClang reaches obs-cocoa.m.h, and the first
run after the merge failed there with four conversion diagnostics. State each
at its boundary: the CFIndex that the assert proves positive, the enum
subtraction that is unsigned until it is narrowed, the int key-action that
fits UInt16, and the UniCharCount handed to a CFIndex parameter.
zackees added a commit that referenced this pull request Oct 29, 2026
-RED: `Rust Tier 2 (macos-26)` on `07340d52e` + #2887's cocoa fix
(job 123343547757) reports 19 `-Werror,-Wsign-conversion` /
`-Wimplicit-int-conversion` diagnostics in the four Rust seam call
sites below: `enum video_format`, `obs_bounds_type`, `obs_scale_type`,
`obs_blending_method`, `obs_blending_type`, `gs_color_space` and
`obs_deinterlace_mode` passed to a helper the port declares with an
`int` parameter. AppleClang gives an all-non-negative enum an unsigned
underlying type; GCC and Linux clang keep `int`, so #2877's replay of
the same TUs could not see them.

-GREEN: state the conversion at each call site, leaving the seam
signatures and the Rust `c_int` ABI unchanged. Two further sites of the
same class (obs_canvas_draw_technique()/reads_white_level() in
obs.c.h, the deinterlace mode-change call) are cast with them so the
next macOS wave does not re-report the group.

No Rust or cmocka change: no signature moved, and the casts are
behaviour-neutral (the values are enum members, not sentinels).
zackees added a commit that referenced this pull request Oct 29, 2026
The libobs ratchet (#2877) had the same Linux-only replay blind spot: the
macOS Tier 2 lane then reported CFIndex -> size_t (dstr_reserve), obs_key_t ->
int (mouse button index), int -> UInt16 (UCKeyTranslate key code) and
UniCharCount -> CFIndex (CFStringCreateWithCharactersNoCopy). State each at
the call; values unchanged.
zackees added a commit that referenced this pull request Oct 29, 2026
-RED: `Rust Tier 2 (macos-26)` on `07340d52e` + #2887's cocoa fix
(job 123343547757) reports 19 `-Werror,-Wsign-conversion` /
`-Wimplicit-int-conversion` diagnostics in the four Rust seam call
sites below: `enum video_format`, `obs_bounds_type`, `obs_scale_type`,
`obs_blending_method`, `obs_blending_type`, `gs_color_space` and
`obs_deinterlace_mode` passed to a helper the port declares with an
`int` parameter. AppleClang gives an all-non-negative enum an unsigned
underlying type; GCC and Linux clang keep `int`, so #2877's replay of
the same TUs could not see them.

-GREEN: state the conversion at each call site, leaving the seam
signatures and the Rust `c_int` ABI unchanged. Two further sites of the
same class (obs_canvas_draw_technique()/reads_white_level() in
obs.c.h, the deinterlace mode-change call) are cast with them so the
next macOS wave does not re-report the group.

No Rust or cmocka change: no signature moved, and the casts are
behaviour-neutral (the values are enum members, not sentinels).
zackees added a commit that referenced this pull request Oct 29, 2026
The libobs ratchet (#2877) had the same Linux-only replay blind spot: the
macOS Tier 2 lane then reported CFIndex -> size_t (dstr_reserve), obs_key_t ->
int (mouse button index), int -> UInt16 (UCKeyTranslate key code) and
UniCharCount -> CFIndex (CFStringCreateWithCharactersNoCopy). State each at
the call; values unchanged.
zackees added a commit that referenced this pull request Oct 29, 2026
-RED: `Rust Tier 2 (macos-26)` on `07340d52e` + #2887's cocoa fix
(job 123343547757) reports 19 `-Werror,-Wsign-conversion` /
`-Wimplicit-int-conversion` diagnostics in the four Rust seam call
sites below: `enum video_format`, `obs_bounds_type`, `obs_scale_type`,
`obs_blending_method`, `obs_blending_type`, `gs_color_space` and
`obs_deinterlace_mode` passed to a helper the port declares with an
`int` parameter. AppleClang gives an all-non-negative enum an unsigned
underlying type; GCC and Linux clang keep `int`, so #2877's replay of
the same TUs could not see them.

-GREEN: state the conversion at each call site, leaving the seam
signatures and the Rust `c_int` ABI unchanged. Two further sites of the
same class (obs_canvas_draw_technique()/reads_white_level() in
obs.c.h, the deinterlace mode-change call) are cast with them so the
next macOS wave does not re-report the group.

No Rust or cmocka change: no signature moved, and the casts are
behaviour-neutral (the values are enum members, not sentinels).
zackees added a commit that referenced this pull request Oct 29, 2026
The libobs ratchet (#2877) had the same Linux-only replay blind spot: the
macOS Tier 2 lane then reported CFIndex -> size_t (dstr_reserve), obs_key_t ->
int (mouse button index), int -> UInt16 (UCKeyTranslate key code) and
UniCharCount -> CFIndex (CFStringCreateWithCharactersNoCopy). State each at
the call; values unchanged.
zackees added a commit that referenced this pull request Oct 29, 2026
-RED: `Rust Tier 2 (macos-26)` on `07340d52e` + #2887's cocoa fix
(job 123343547757) reports 19 `-Werror,-Wsign-conversion` /
`-Wimplicit-int-conversion` diagnostics in the four Rust seam call
sites below: `enum video_format`, `obs_bounds_type`, `obs_scale_type`,
`obs_blending_method`, `obs_blending_type`, `gs_color_space` and
`obs_deinterlace_mode` passed to a helper the port declares with an
`int` parameter. AppleClang gives an all-non-negative enum an unsigned
underlying type; GCC and Linux clang keep `int`, so #2877's replay of
the same TUs could not see them.

-GREEN: state the conversion at each call site, leaving the seam
signatures and the Rust `c_int` ABI unchanged. Two further sites of the
same class (obs_canvas_draw_technique()/reads_white_level() in
obs.c.h, the deinterlace mode-change call) are cast with them so the
next macOS wave does not re-report the group.

No Rust or cmocka change: no signature moved, and the casts are
behaviour-neutral (the values are enum members, not sentinels).
zackees added a commit that referenced this pull request Oct 29, 2026
The libobs ratchet (#2877) had the same Linux-only replay blind spot: the
macOS Tier 2 lane then reported CFIndex -> size_t (dstr_reserve), obs_key_t ->
int (mouse button index), int -> UInt16 (UCKeyTranslate key code) and
UniCharCount -> CFIndex (CFStringCreateWithCharactersNoCopy). State each at
the call; values unchanged.
zackees added a commit that referenced this pull request Oct 29, 2026
-RED: `Rust Tier 2 (macos-26)` on `07340d52e` + #2887's cocoa fix
(job 123343547757) reports 19 `-Werror,-Wsign-conversion` /
`-Wimplicit-int-conversion` diagnostics in the four Rust seam call
sites below: `enum video_format`, `obs_bounds_type`, `obs_scale_type`,
`obs_blending_method`, `obs_blending_type`, `gs_color_space` and
`obs_deinterlace_mode` passed to a helper the port declares with an
`int` parameter. AppleClang gives an all-non-negative enum an unsigned
underlying type; GCC and Linux clang keep `int`, so #2877's replay of
the same TUs could not see them.

-GREEN: state the conversion at each call site, leaving the seam
signatures and the Rust `c_int` ABI unchanged. Two further sites of the
same class (obs_canvas_draw_technique()/reads_white_level() in
obs.c.h, the deinterlace mode-change call) are cast with them so the
next macOS wave does not re-report the group.

No Rust or cmocka change: no signature moved, and the casts are
behaviour-neutral (the values are enum members, not sentinels).
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
…#2879) (obs-rust#2900)

* libobs-opengl: state the macOS Cocoa conversions too (obs-rust#2879)

The first green attempt still failed: the same #ifdef-only blind spot hides
four more -Wsign-conversion diagnostics (CGLTexImageIOSurface2D takes GLsizei
widths from uint32_t texture fields) and two -Wfloat-conversion ones (CGSize
CGFloat dimensions into device_texture_create's uint32_t). State them at the
call; values unchanged.

* libobs: state the four macOS Cocoa conversions too (obs-rust#2879)

The libobs ratchet (obs-rust#2877) had the same Linux-only replay blind spot: the
macOS Tier 2 lane then reported CFIndex -> size_t (dstr_reserve), obs_key_t ->
int (mouse button index), int -> UInt16 (UCKeyTranslate key code) and
UniCharCount -> CFIndex (CFStringCreateWithCharactersNoCopy). State each at
the call; values unchanged.

* libobs: state the CoreAudio device-name length conversion (obs-rust#2879)

-Wsign-conversion on the macOS Tier 2 lane rejects strlen()'s size_t as the
CFIndex byte count; cast at the boundary.

* build(libobs): state the enum -> int seam conversions (obs-rust#2896)

-RED: `Rust Tier 2 (macos-26)` on `07340d52e` + obs-rust#2887's cocoa fix
(job 123343547757) reports 19 `-Werror,-Wsign-conversion` /
`-Wimplicit-int-conversion` diagnostics in the four Rust seam call
sites below: `enum video_format`, `obs_bounds_type`, `obs_scale_type`,
`obs_blending_method`, `obs_blending_type`, `gs_color_space` and
`obs_deinterlace_mode` passed to a helper the port declares with an
`int` parameter. AppleClang gives an all-non-negative enum an unsigned
underlying type; GCC and Linux clang keep `int`, so obs-rust#2877's replay of
the same TUs could not see them.

-GREEN: state the conversion at each call site, leaving the seam
signatures and the Rust `c_int` ABI unchanged. Two further sites of the
same class (obs_canvas_draw_technique()/reads_white_level() in
obs.c.h, the deinterlace mode-change call) are cast with them so the
next macOS wave does not re-report the group.

No Rust or cmocka change: no signature moved, and the casts are
behaviour-neutral (the values are enum members, not sentinels).

* build(libobs): state the source render-plan conversions (obs-rust#2896)

The next macOS Tier 2 wave after b43279b reports 19 more
'enum -> int' conversions, all in libobs/obs-source.c.h: the monitoring
type fed to obs_source_audio_place_outputs(), the async and sync render
plans' gs_color_space arguments, and src->format into
obs_source_frame_copy_plan().

AppleClang gives all-positive enums an unsigned underlying type; the
seam helpers take int (the Rust c_int ABI carries -1 sentinels), so each
call site is an implicit conversion visible only on Apple platforms.
Cast at each call site; signatures, Rust ABI and tests do not move.

* build(frontend): enable the sign-conversion warnings on the app target (obs-rust#2625)

* frontend: state the sign conversions the app target now reports (obs-rust#2625)

* build(libobs): state the source frame-copy seam conversions (obs-rust#2879)

-Wsign-conversion on the macOS lane rejects enum video_format and
enum video_range_type as the int parameters of the frame-copy helpers,
whose signatures are public API (obs-source-frame-copy.h) and stay int.
State the conversion at each of the seven call sites in obs-source.c.h.

* build(libobs): state the output and video conversions the macOS lane reports (obs-rust#2879)

The macOS Tier 2 lane on this branch stopped on the next wave after the
obs-source frame-copy seams: encoder-type slots, the CoreAudio caption
shift, the video copy-plan keys and the GPU encode format gate. Explicit
casts only; same values the compiler converted implicitly.

* build(libobs): state the hotkey name-map key conversion (obs-rust#2879)

* build(libobs): state the macOS path and CFString size conversions (obs-rust#2879)

* build(libobs): apply the local formatter to the platform-cocoa casts
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