Repository navigation
libobs/util: Move the platform string conversions into platform-conversions.c - #1610
Merged
zackees merged 1 commit intoOct 21, 2026
Merged
Conversation
…rsions.c Behavior-neutral extraction before the Rust port: os_mbs_to_wcs, os_utf8_to_wcs, os_wcs_to_mbs, os_wcs_to_utf8, their _ptr forms, os_utf8_to_mbs_ptr and os_mbs_to_utf8_ptr move verbatim from libobs/util/platform.c.h into libobs/util/platform-conversions.c.h. They were all that was left in platform.c.h after slices 2 to 6, so the file is renamed unchanged (100% similarity). It stays in the libobs.platform unity group and precompiled header, and the oracle compiles it under the new name. No host conditionals, no signature or header change. test_platform_conversions characterizes every function on its own: ASCII, 2-, 3- and 4-byte UTF-8 (a surrogate pair where wchar_t is 16 bits), invalid UTF-8 and lone surrogates, len 0 against an explicit len, the NULL-dst size query, dst_size 0 and 1, an exact and a too-small dst, empty and NULL input, the _ptr allocation and free (bnum_allocs), and the mbs functions in the C locale and a UTF-8 locale, set by the test. Characterized, not endorsed: the mbs functions ignore len; a dst too small for the UTF-8 conversions gives an empty string where the mbs ones cut the text; off Windows the size query accepts an encoded surrogate that the conversion then refuses, and the decoder accepts overlong 3-byte forms, values above U+10FFFF and 5- and 6-byte sequences. Windows replaces invalid input with U+FFFD and drops a leading UTF-8 BOM. Earlier slice 1 work is b7216309-jpg's: obs-rust#263 fixed the mbs conversions' (size_t)-1 and too-small-buffer cases, which the test pins, and obs-rust#267 ported the Windows branch of util/utf8.c that the UTF-8 conversions call. Refs obs-rust#262
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #262 (slice 1, conversions).
What and why
Behavior-neutral extraction before the Rust port, as the testing policy asks for a partial-file port:
os_mbs_to_wcs,os_utf8_to_wcs,os_wcs_to_mbs,os_wcs_to_utf8, their_ptrforms,os_utf8_to_mbs_ptrandos_mbs_to_utf8_ptrmove verbatim fromlibobs/util/platform.c.hintolibobs/util/platform-conversions.c.h. Slices 2 to 6 already took everything else out ofplatform.c.h, so the move is a rename of an unchanged file (100% similarity). There are no static helpers. No Rust, no signature, header or behavior change.libobs.platformunity group andlibobs-platform.pch.h, under its new name.rust/obs-c-oracle/oracle/platform.cincludes it under the new name (the functions were already renamedoracle_*there), so the oracle still runs the real C.Earlier slice 1 work is b7216309-jpg's: #263 fixed the mbs conversions'
(size_t)-1and too-small-buffer cases, which this test pins, and #267 ported the Windows branch ofutil/utf8.cthat the UTF-8 conversions call.New characterization test
test_platform_conversions(tests.d/fragment, plus the Cargo C-test manifest).test_platformhas a few round trips and the #263 cases; this test covers every function on its own.wchar_tis 32 bits on Linux and macOS and 16 bits on Windows, so the expected units are chosen withWCHAR_MAX, and the cases where the Windows API (MultiByteToWideChar/WideCharToMultiByte) and libobs's own decoder differ are pinned per side. The group setup setsLC_ALLto"C"; the UTF-8-locale cases switchLC_CTYPEand back, and skip where no UTF-8 locale is installed. Cases:wchar_tis 16 bits, and the U+FFFF / U+10000 edges, both ways;len0 (up to the NUL) against an explicitlen, which also converts an embedded NUL;dst_size),dst_size0 and 1, an exact-size dst and a too-small one, with guards after the buffer;lenthat cuts one) and lone surrogates: off Windows they fail the whole string, on Windows they become U+FFFD;_ptrforms: onebmallocper call, checked withbnum_allocsand freed withbfree, the intermediate wide buffer ofos_utf8_to_mbs_ptrandos_mbs_to_utf8_ptrfreed, an allocated empty string on failure,*pstrset to NULL for NULL input;Characterized, not endorsed:
len, soos_mbs_to_utf8_ptrdoes too, whileos_utf8_to_mbs_ptrhonors it;ED A0 80) that the conversion then refuses (1, then 0);E0 80 AFis/), values above U+10FFFF and 5- and 6-byte sequences, and the encoder writes values above U+10FFFF in 4 to 6 bytes.RED → GREEN
platform.c.hon master =platform-conversions.c.h). The test also passes against the v0.1.0-beta.20261018 release'slibobs.so.30, both the C one and theobs-studio-rust/one.ENABLE_RUST_LIBOBS=OFFandON). Each runs the cmocka tests againstlibobsand againstlibobs-with-rust:ENABLE_RUST_LIBOBS=OFF)ENABLE_RUST_LIBOBS=ON)¹ Headless (private Xvfb, private D-Bus, fresh HOME). The full
-j6run had no X display, so the four tests that need one skipped (test_output_delay_restart,test_output_interleave_e2e,test_output_interleave_restart,test_screencast_portal_teardown) andtest_v4l2_busy_signalfailed atobs_startup;test_audio_controls(two runs) andtest_pulse_monitor_reset(one run) also failed once under-j6. All of them pass when rerun one at a time under Xvfb in all four.test_platform_conversions: 18/18 in all four, three repeated runs in each.soldr cargo test -p obs-util: 742 passed (Tier 1 and the Tier 3 tests over the oracle, which compiles the renamed file).ci/local_gate.py --lane lint: passed (52 s).--lane cross(Windows and macOSclippy/Dylint, the oracle compiled for both): passed (86 s).Windows/macOS: this test is not behind
MSVCor a host check, so it builds and runs on Windows and macOS wherever their Tier 2 lanes run. The Windows expectations (U+FFFD for invalid input, the dropped BOM, a too-small buffer giving 0) follow #267's characterization of the same API calls; this PR could not run them locally.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable