Skip to content

build(libobs): state the enum -> int seam conversions (#2896) - #2897

Closed
zackees wants to merge 9 commits into
masterfrom
fix/rust-seam-enum-casts
Closed

zackees wants to merge 9 commits into
masterfrom
fix/rust-seam-enum-casts

Conversation

@zackees

@zackees zackees commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Fixes #2896 and #2879. Was stacked on #2892, which is now closed: its three cocoa commits are the first three on this branch, so this PR lands the whole macOS conversion set.

What

Same lane, one wave: Rust Tier 2 (macos-26) on master's code and on #2887's head (job 123343547757) reported 19 -Werror,-Wsign-conversion / -Wimplicit-int-conversion diagnostics in libobs's Rust seam call sites:

obs-canvas.c.h:328:42:            'enum video_format' to 'int'
obs-display.c.h:197:37:           'enum gs_color_space' to 'int'
obs-scene.c.h:433:45, :460:45:    'enum obs_bounds_type' to 'int'
obs-scene.c.h:578:25, :579:25, :580:23:  'obs_scale_type' / 'obs_blending_method' / 'obs_blending_type' to 'int'
obs-scene.c.h:649:32, :674:31/:46, :676:66/:81, :771:43, :808:89  same, via the render-plan helpers
obs-source-deinterlace.c.h:237:45, :283:76, :285:43/:76, :289:86  'obs_deinterlace_mode', 'gs_color_space'

AppleClang gives an enumeration whose enumerators are all non-negative an unsigned underlying type; GCC and Linux clang keep int. The port's seam helpers take int (the Rust ABI is c_int, and some carry -1 sentinels), so each call site that passes the real enum value is an implicit enum -> int conversion: visible on Apple platforms only, which is why #2877's Linux replay of the same TUs was clean.

The same breakage reaches the merge queue: the merge group for #2872 (run 40841144417) failed this lane on master's code and #2872 was ejected.

Green

Cast at each call site. The seam signatures and the Rust c_int ABI do not move, so there is no Rust or cmocka change and the tests are untouched. Two further sites of the same class are cast in the same commit so the next macOS wave does not re-report the group: obs_canvas_draw_technique() / obs_canvas_draw_reads_white_level() in obs.c.h, and the deinterlace mode-change call in obs_set_deinterlace_mode().

./lint ok (39 s); clang-format --dry-run --Werror clean on the five files. No docs/features.md line (a build-warning change, no user-visible behaviour).

Draft until this PR's own Rust Tier 2 (macos-26) lane is green: Linux cannot reproduce the finding, so that lane is the only proof. After #2892 lands I rebase this single commit onto origin/master and retarget.

Waves after the first push

The lane reports one wave per push because clang stops at the first failing TU group; each subsequent green attempt surfaced the next file:

  1. b43279b18 — Wave 2 (libobs/obs-source.c.h), 19 more sites: obs_source_audio_place_outputs(source->monitoring_type), the async/sync render plans' source_space / current_space (obs_source_draw_plan_async_linear_srgb, ..._async_nonlinear_alpha, ..._technique, ..._reads_white_level, ..._multiplier, ..._convert) and src->format into obs_source_frame_copy_plan(). The lane on that push (run 40845602973, job 123357694178) is the RED evidence, verbatim:
libobs/obs-source.c.h:1744:45: 'enum obs_monitoring_type' to 'int' [-Werror,-Wsign-conversion]
libobs/obs-source.c.h:2160:43/57, :2161:75, :2164:35/49, :2165:67/81, :2166:42/56: 'const enum gs_color_space' to 'int'
libobs/obs-source.c.h:2296:52/66, :2298:65/79, :2300:42/56, :2301:38/52: same
libobs/obs-source.c.h:2981:8: 'const enum video_format' to 'int'
  1. 9f5c17d86 — Wave 3: 10 more sites in the same file (obs_source_frame_copy_full_range(), ..._full_range2() and obs_source_frame_copy_shape.format). Lane log from run 40848587918, job 123371438242:
libobs/obs-source.c.h:3167:65, :3308:65, :3407:65: 'const enum video_format' to 'int'
libobs/obs-source.c.h:3192:66/81, :3333:66/81, :3432:66/81: video_format, video_range_type to 'int'
libobs/obs-source.c.h:3263:20: 'const enum video_format' to 'int'

Local reproduction (cheaper than one macOS queue slot per wave)

The lane's warning set reproduces on Linux with clang 21 against the generated unity TU from the existing GCC build tree:

# from build_ubuntu, using the ninja command for libobs.core-source+.h.c,
# swapping cc -> clang and -Wno-conversion -> -Wsign-conversion -Wimplicit-int-conversion -Werror
clang ... -fsyntax-only libobs/build/libobs.core-source+.h.c

That reports the same enum -> int diagnostics AppleClang does (Linux clang picks an unsigned underlying type for all-non-negative enums too), so the remaining waves can be found locally in seconds. With wave 3 applied, libobs.core+, core-output+, graphics+ and core-source+ are all clean under -Wsign-conversion -Wimplicit-int-conversion -Werror.

@zackees
zackees force-pushed the fix/rust-seam-enum-casts branch from 5d36750 to 2da11e3 Compare October 29, 2026 08:43
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Stacked on #2887 (50628d634): this PR's own commit sits on the cocoa fix because the macOS lane reports that file's four diagnostics before it reaches these TUs — the two are the same lane's red and neither can be green alone. After #2887 merges I rebase this commit onto origin/master and retarget, so it lands as the five call-site files alone.

@zackees zackees changed the title build(libobs): state the enum -> int seam conversions (#2896) build(libobs): state the macOS conversions the ratchet reports (#2879, #2896) Oct 29, 2026
@zackees
zackees force-pushed the fix/rust-seam-enum-casts branch from 2da11e3 to b43279b Compare October 29, 2026 08:54
@zackees zackees changed the title build(libobs): state the macOS conversions the ratchet reports (#2879, #2896) build(libobs): state the enum -> int seam conversions (#2896) Oct 29, 2026
@zackees
zackees force-pushed the fix/rust-seam-enum-casts branch from b43279b to e99ef02 Compare October 29, 2026 09:17
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Round 2: the macOS build of e99ef026f (Scheduled 40848489838, job 123362141198) still reported 16 diagnostics, all in libobs/obs-source.c.h — obs_source_audio_place_outputs(source->monitoring_type) (1744) plus the six draw-plan seam calls (2160-2166, 2296-2301), enum gs_color_space / const enum gs_color_space -> int.

c4e270448 casts those call sites (and the obs_source_frame_copy_plan format at 2979, the same class, so the next wave does not re-report it). Re-dispatched macOS evidence: Scheduled 40851868025.

Note: this branch also carries #2892's three cocoa commits (it is stacked on them and its base is master), so a green run here proves the whole macOS conversion set at once.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Round 3 — two further waves, both in libobs/obs-source.c.h:

  • 9f5c17d86 (from the macOS build of job 123375300074): the nine frame-copy conversions — obs_source_frame_copy_full_range(frame->format, …) x3, obs_source_frame_copy_full_range2(frame->format, frame->range) x3, and obs_source_frame_copy_shape's .format = frame->format initializer (const enum video_format / const enum video_range_type -> int).
  • 8424b8326: a repo-wide sweep for the same class instead of waiting for the next wave — obs_source_deinterlace_draw_technique((int)source_space, (int)current_space) and obs_encoder_gpu_gates_p010((int)info->format).

Re-dispatched: Scheduled 40854256103. The sweep found no other uncast enum -> int call in libobs, frontend or plugins, so this should be the last round for the lane.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Round 4 — the lane is clean. 91bf158bf on Scheduled 40855996033:

  • Build 🧱 / macOS 🍏 (arm64) — success (job 123388266212, with the -Werror conversion flags that produced every previous round).
  • Build 🧱 / Ubuntu 🐧 (OBS-Studio-Rust) — success; CI Mode 🛂 success.

91bf158bf fixes the wave this run's predecessor found: obs-video.c.h (.render_space, .scale_type) and obs-output.c.h (obs_output_slots_{video,audio}_type_ok(encoder->info.type) x4, captionData = captionData << 8 int -> uint16_t).

Diagnostic count by round: 2 (stage-surf) -> 6 (gl-cocoa) -> 4 (obs-cocoa) -> 1 (coreaudio) -> 19 (seam enums) -> 16 (draw plan) -> 9 (frame copy) -> 9 (video mix + output slots) -> 0.

Marking ready and handing off to the coordinator.

@zackees
zackees marked this pull request as ready for review October 29, 2026 10:26
@zackees
zackees enabled auto-merge October 29, 2026 10:27

@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 — #2897

Reviewed 91bf158bf (13 files, 49 added (int)-class casts, +74/−68). Verdict: correct and in scope; queueing it.

Correctness. Every change states a conversion that already happened implicitly, so values and behaviour are unchanged:

  • Enum → int at the Rust seam helpers (obs_scene_item_transform_bounded, obs_canvas_rules_format_set, obs_display_clear_linear, obs_output_slots_{video,audio}_type_ok, obs_encoder_gpu_gates_p010, the draw-plan / deinterlace-draw families). The seam signatures and the c_int ABI do not move, so the -1 sentinels some helpers take still arrive as -1; the cast is applied to the enum value, never to a computed result.
  • obs_source_frame_copy_plan((int)src->format, …), frame_copy_shape.format, full_range/range sites: the plan helpers take int and compare against enum constants, so an explicit cast is exactly the implicit one they relied on.
  • captionData = (uint16_t)(captionData << 8) restores the truncation the assignment already performed on a uint16_t — no new width.
  • Cocoa/coreaudio: (size_t) max_size after assert(max_size > 0), (CFIndex) length/strlen(uid), (GLsizei) tex->width/height, (uint32_t) texture size, (UInt16) code (virtual key codes) — all narrowings into API parameter types where the source range is already the parameter's range.

RED → GREEN. Present and traceable: the RED is the Rust Tier 2 (macos-26) / macOS 🍏 (arm64) lane log at each push (job 123343547757, then one wave per push) with the verbatim diagnostics; GREEN is the same lane at 91bf158bf on Scheduled 40855996033 (job 123388266212) with the -Werror conversion flags, plus the local clang-21 replay documented in the description. Diagnostic count 19 → 16 → 9 → 9 → 0.

Rules (AGENTS.md / coordination.md §4). Mechanical warning class (#516): one PR for the class, explicit casts only, no -Wno-*, no #pragma, no per-file exemption — verified, the pin itself was removed in #2877, so the same-change rule is satisfied. No existing C test and no public header touched: the edits are in unity implementation bodies (*.c.h) and libobs-opengl/gl-cocoa.m.h. No docs/features.md line, which is right for a build-warning change with no user-visible behaviour. Base is master (no longer stacked on the closed #2892 — its cocoa commits ride here, so no separate base to land).

Residual risk, not a blocker. The wave enumeration is complete for the units the Tier 2 lane compiles, and the local clang-21 replay is a good filter; the app-build lanes (#2886's territory) compile units Tier 2 does not, so the next -Wsign-conversion group can only show up there. That is tracked, not hidden.

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.
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.
-Wsign-conversion on the macOS Tier 2 lane rejects strlen()'s size_t as the
CFIndex byte count; cast at the boundary.
-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).
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.
Wave 3 of the same lane (run 40848587918, job 123371438242): 10 more
'const enum video_format' / 'const enum video_range_type' -> int
diagnostics in libobs/obs-source.c.h — every
obs_source_frame_copy_full_range()/..._full_range2() call site, plus
the .format field of obs_source_frame_copy_shape.

Validated locally with clang -Wsign-conversion -Wimplicit-int-conversion
-Werror against the generated libobs.core-source unity TU (GCC build
graph, clang front end, same warning set the lane uses): zero
diagnostics. No Rust, cmocka or public-API change.
@zackees
zackees force-pushed the fix/rust-seam-enum-casts branch from 91bf158 to 229ed38 Compare October 29, 2026 10:47
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Coordinator tick — the Tier 2 macOS lane was not clean at 91bf158bf

Correcting the Round 4 note before this is queued: on 91bf158bf the Build 🧱 / Rust Tier 2 (macos-26) job failed, on both of that head's runs.

  • Nightly 40855996033 (workflow_dispatch), job 123394696066, step Validate Tier 2 on macOS (libobs C vs with Rust) — failure at 10:36:49, one diagnostic:
libobs/obs-hotkey-name-map.c.h:110:10: error: implicit conversion changes signedness:
  'int' to 'obs_key_t' (aka 'enum obs_key') [-Werror,-Wsign-conversion]
  • PR run 40855993528 — failure too.

Round 4's evidence (macOS 🍏 (arm64) and macOS 🍏 (x86_64) on the same nightly) is the app build, which compiles a different TU set from the Tier 2 lane, so it does not cover this.

obs_key_from_name() returns int v from obs_hotkey_name_map_lookup() directly, so the statement is return (obs_key_t)v; — not pushed here: the head moved to 229ed3822 at 10:46 while this was being read, and this branch does not allow a maintainer push.

Why this is the whole queue's blocker

Master has been red on that lane since #2877 merged (07:25), not just this branch. Both merge groups prove it on code this PR does not touch:

Consequences right now: #2863 at queue position 1 ejects, #2881 (position 3) and #2872 (position 2) sit UNMERGEABLE behind it, and nothing in the queue can land until this lane is green on master.

Review, unchanged

The review posted on 91bf158bf still stands on the content: the casts are value-preserving, RED → GREEN is documented wave by wave, no -Wno-*/pragma, no public header or C test touched, no ledger line needed. The only thing keeping it out of the queue is this wave.

The macOS Tier 2 lane (`libobs C vs with Rust`, AppleClang,
`CMAKE_COMPILE_WARNING_AS_ERROR`) reports eight more conversion errors
once the RIST and render-plan ones are cast:

- obs-output.c.h: `obs_output_slots_{video,audio}_type_ok()` take `int`
  and are passed `encoder->info.type` (`enum obs_encoder_type`), four
  sites; and the CEA-608 accumulator adds an `int` to a `uint16_t`.
- obs-video-gpu-encode.c.h: `obs_encoder_gpu_gates_p010()` takes `int`
  and is passed `info->format` (`enum video_format`).
- obs-video.c.h: `obs_video_mix_reuse_key.render_space` and the scale
  input's `.scale_type` are `int` fields holding a `gs_color_space` and
  an `obs_scale_type`.

Explicit casts at the seams, no behaviour change and no `-Wno-*` back.

Refs #2896
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Rebased onto master (bc8b13cc6) after #2869/#2870 fixed the RIST cast, which
was stopping this lane earlier and hiding the rest. The macOS Tier 2 lane then
reported eight more conversion errors in libobs, all of the same shape as this
PR (an enum reaching an int seam); they are now cast here too, in
ecc521a95:

  • obs-output.c.h: obs_output_slots_{video,audio}_type_ok() (four sites),
    enum obs_encoder_type -> int; and the CEA-608 uint16_t accumulator.
  • obs-video-gpu-encode.c.h: obs_encoder_gpu_gates_p010(), enum video_format -> int.
  • obs-video.c.h: render_space and .scale_type in the copy/scale input
    structs, int fields holding gs_color_space / obs_scale_type.

./lint clean. The macOS lane is the evidence for the casts themselves
(AppleClang flags what Linux clang does not), so this waits on that job.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Coordinator read of the latest macOS lane failure (2026-10-29 11:01Z, run 40860283546, head 229ed3822)

Your four Cocoa casts did land — this run's Rust Tier 2 (macos-26) no longer reports obs-cocoa.m.h. It now stops on 9 further sites that are on master (2bcddc202), not in this PR's diff:

libobs/obs-output.c.h:1084:51  obs_output_slots_video_type_ok(encoder->info.type)   'enum obs_encoder_type' -> 'int'
libobs/obs-output.c.h:1092:58  obs_output_slots_audio_type_ok(encoder->info.type)   'enum obs_encoder_type' -> 'int'
libobs/obs-output.c.h:1131:63  obs_output_slots_video_type_ok(encoder->info.type)   'enum obs_encoder_type' -> 'int'
libobs/obs-output.c.h:1189:63  obs_output_slots_audio_type_ok(encoder->info.type)   'enum obs_encoder_type' -> 'int'
libobs/obs-output.c.h:1606:30  captionData = captionData << 8;                      'int' -> 'uint16_t' (implicit-int-conversion)
libobs/obs-video-gpu-encode.c.h:254:40  obs_encoder_gpu_gates_p010(info->format)     'const enum video_format' -> 'int'
libobs/obs-video.c.h:122:24   .render_space = mix->render_space                     'const enum gs_color_space' -> 'int'
libobs/obs-video.c.h:267:26   .scale_type = mix->ovi.scale_type                     'enum obs_scale_type' -> 'int'
libobs/obs-hotkey-name-map.c.h:110:10  return v;                                     'int' -> 'obs_key_t' (the earlier head's only failure)

(The first eight are from this run's log; obs-hotkey-name-map.c.h:110 is from the 10:14 run on 91bf158b, so it is still open behind these.)

Because the lane builds these libobs TUs only when a PR touches libobs, this is master-latent red for #2896: PRs that touch libobs or its flags keep getting ejected from the queue even when their own diff is clean — #2863 (rdoupe) was ejected twice on the obs-cocoa.m.h four alone. Extending this PR's sweep to the four files above would fix #2896 completely and unblock the queue; the alternative is one extra sweep PR on top of this one. Not touching your branch.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Coordinator: pushed a fixup: commit (997c3d5) casting the caption shift in libobs/obs-output.c.h:1606 (captionData = (uint16_t)(captionData << 8)), the one -Wimplicit-int-conversion error left in the Tier 2 macOS run. Re-running checks now.

The macOS Tier 2 lane (AppleClang) reports one more seam once the
encoder and frame-copy casts are in: obs_key_from_name() returns the
int the name map stores as an obs_key_t.

Refs #2896
@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

The macOS Tier 2 lane (libobs C vs with Rust, AppleClang) caught one more seam after the first round: libobs/obs-hotkey-name-map.c.h:110 returned the name map's int as an obs_key_t. 83f27be95 states that conversion; no other error in the job's log. Re-running.

@zackees

zackees commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Superseded by master: the coordinator landed the same seam casts (997c3d5 "fixup: state the caption shift conversion in obs-output.c.h", and master's obs-output.c.h:1084/1092 + obs-hotkey-name-map.c.h:109 already carry the calls I raised here). Rebasing onto master dropped six of my nine commits as already upstream and only the caption hunk conflicted, so there is nothing left in this branch. Closing; #2896 still needs a macOS Tier 2 run to confirm the lane is green.

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.

bug(libobs): macOS Tier 2 red on the enum -> int seam conversions after #2877

1 participant