Repository navigation
build(libobs): make the conversions explicit (#2625) - #2877
Conversation
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
left a comment
There was a problem hiding this comment.
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 * linesizeand(size_t)frame->linesize[0]preserve the old implicit size_t conversion;(size_t)info->cx * (size_t)info->cyprevents theintproduct 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 areint/size_t; the values are channel counts, sample rates and frame sizes, all well insideint.obs-output.c.h:(size_t)payload_size,(size_t)cea708_render(...)and(size_t)idxmatch 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_offseton auint64_ttimestamp 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 becomeuint32_t, which is whatobs_source_get_width/get_base_widthreturn; the one(int)pair inobs_source_process_filter_begin_with_color_spaceis cast back touint32_tforgs_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_keysymsis the allocated byte count.profiler-io.c.h:((uint64_t)1 << indent) - 1is a genuine fix — the old1 << indentwas signed and UB past bit 30.- The rest (
calldata.c.hpointer differences,obs-hotkey.c.hflag masks,obs.c.hbmallocsizes,platform-file.c.h/platform-time.c.h/platform-nix-portal.c.h,cf-lexer.c.hdstr_ncopylength,obs-data.c.halignment) 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.
graphics-ffmpeg.c.h: FFmpeg may report a negativelinesizefor vertically flipped frames. The old implicit conversion tosize_thad the same assumption, so this is not a regression — just worth a comment or an explicitAV_ABSif that path is ever reachable with this loader.extract_buffer_from_seinarrowssei_message_size()tointbefore widening tosize_t; harmless for SEI payloads, but the type round-trip would read better without theinthop.
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.
196b1c5 to
0f96af7
Compare
|
Handed off to the coordinator.
|
…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.
-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 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.
-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 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.
-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 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.
-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 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.
-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).
…#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
Slice of #2625 (the
libobstarget). Refs #2625, does not close it.RED
02e5e158aputs-Wconversion;-Wsign-conversion;-Wfloat-conversionon 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.pyover thecompdb, the cache bypassed) reports 198 conversion findings:
libobs/(own sources)-Wsign-conversion, 29-Wconversionlibobs/graphics/libnsgif(vendored)-Wconversion, 18-Wsign-conversionlibobs/graphics-Wsign-conversionlibobs/util-Wsign-conversionlibobs/media-io-Wsign-conversionlibobs/callback-Wsign-conversionlibobs/audio-monitoring/pulse-Wconversionlibnsgifstays exempt, exactly as it already is for-Wcast-qual,-Wshadowand-Wpedanticin the other vendored C (librtmp, uthash): it isvendored 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:
-Wswitchin the existingtest_qsv_update.c(it includesobs-qsv11.c.h; existing C tests are neveredited) and
-Wpedanticon the empty PCH units.GREEN
196b1c55cstates the 159 conversions in 30 files at theirboundaries; the same replay reports 0 conversion findings, and a real
cmake --build --target libobs libobs-c-referencein the warm tree compiles51 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 moduloUINT_MAX, so it narrows to theunsigned intuthash's hash variable is;the background flag mask is cleared through a
uint32_tcomplement. Onecast clears 22 findings (every
HASH_ADD/HASH_FINDinstantiation).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 areuint32_tend to end(
obs_source_get_width/height,obs_transition_set_size,gs_texrender_begin_with_color_space,gs_set_viewport); where an internalhelper still takes
int(obs_source_render_route_size_skip, whosec_intsignature 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/memcpylengths,
audio_output_connectmix index,obs_data_set_int'slong long,the profiler's double, the reconnect backoff as a
floatproduct).libobs/graphics/*—size_tlengths built from theuint32_timagegeometry (
(size_t)cy * linesize,frame->linesize), and the mipmap flagmasks cleared through a
uint32_tcomplement;image-file.c.halso caststhe frame index to libnsgif's
uint32_tat the boundary.libobs/util/*— thetimespecarithmetic keepsint64_tthroughout(both operands cast at the
uint64_toffset), pointer differences becomesize_t,off_tis cast wheresize_tis subtracted,rand()gives theportal id as
uint32_t.libobs/media-io/*—av_image_alloc/swr_alloc_set_opts2/swr_converttake
intwidths and channel counts, so theuint32_tgeometry, samplerate and frame count are cast at those calls; the scaler's
dst_linesizesand
dst_heightsaresize_tin the copy loop.callback/calldata.c.h— the grow/shrink memmove offsets aresize_tdifferences from the fixed stack buffer.
pulseaudio-output.c.h—pa_usec_to_bytesreturnssize_t; the bufferattribute 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()addssize_t framesizeto anint64_t,and the original
cur_pts + framesizecomputed the sum in unsigned after theusual arithmetic conversions. The unchanged C test pins exactly that
(
(INT64_MAX, 1) == INT64_MIN,(-1, SIZE_MAX) == -2); my(int64_t)castmade the addition signed, which UBSan reported as
signed integer overflowand made
test_encoder_audio_start_stepsfail in both modes. The sum is nowstated as
(int64_t)((uint64_t)cur_pts + (uint64_t)framesize): same value,defined arithmetic, and the test's overflow case is the documentation. The
timespecarithmetic inutil/platform-time.c.hwas converted the same wayfor 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 pinsstay until every target is ratcheted.
Local gate:
./lintok (41 s). PR CI's Tier 2 lane builds libobs and runs theunchanged cmocka suites, so it is the merge gate for this target.
No
docs/features.mdline: build tooling only.