Skip to content

port: util/platform.c to obs-util #262

Closed

Description

@b7216309-jpg

Tracking the platform.c item of #153. The OS-specific platform-nix.c and platform-windows.c are not part of this; they're the next item on #153.

platform.c is 834 lines and mixes unrelated groups, so it comes in slices, one PR each. Each slice starts with its functions moved verbatim into their own .c file (a behavior-neutral commit, as the testing policy asks for partial-file ports), then C characterization, RED, GREEN, and parity against the oracle:

  1. Conversions: 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. These are over the existing utf8 port and the C locale functions (mbstowcs/wcstombs). On Windows they need the utf8.c Windows branch, which isn't ported yet. Done well, this also replaces the oracle copies in platform_conv_host.c (see bug: Oracle stand-ins in test_stubs.c can diverge from libobs #145).
  2. Numbers: os_strtod and os_dtostr (decimal point independent of the locale).
  3. Files: os_wfopen/os_fopen, os_fgetsize, os_stat, os_fseeki64/os_ftelli64, os_fread_mbs/os_fread_utf8, os_quick_read_*/os_quick_write_* (including _safe) and os_get_file_size.
  4. Directories: os_mkdirs.
  5. Filenames: os_generate_formatted_filename.
  6. Time: os_nstime_to_timespec.

Tier 2 gates: test_platform, test_os_path and test_formatted_filename. I can run Windows (MSVC) and Linux (an Ubuntu 26.04 VM) locally. Slices go in the order above unless review prefers otherwise; I'll open each one here before starting it.

Activity

  1. b7216309-jpg commented on Oct 11, 2026

    @b7216309-jpg
    ContributorAuthor

    Slice 1 (conversions) is under way:

    1. libobs/util: Treat unconvertible text as a failed mbs conversion #263 (C fix first): os_mbs_to_wcs and os_wcs_to_mbs took (size_t)-1 from mbstowcs/wcstombs as a length. The _ptr forms then called bmalloc(0), which crashes; it's reachable from X11 window titles in xcomposite. Separately, a buffer too small for the text got its NUL written one past the end.
    2. The Windows branch of util/utf8.c (MultiByteToWideChar/WideCharToMultiByte), so utf8_to_wchar and wchar_to_utf8 exist in Rust on every OS. The conversions need it on Windows.
    3. The port of the twelve conversion functions, with parity against the fixed C.
  2. zackees commented on Oct 13, 2026

    @zackees
    Member

    FYI for the platform.c slices: os_generate_formatted_filename (libobs/util/platform.c:697) uses non-reentrant localtime(), the same race as #132 (log timestamps from other threads share the static buffer). Worth localtime_r/localtime_s in the C and the Rust port. I left it alone because this issue is claimed.

  3. zackees commented on Oct 14, 2026

    @zackees
    Member

    @b7216309-jpg are you still on the platform.c slices? Since #263 and #267 landed, I don't see a PR for slice 1 (conversions). If you're busy, I can take slice 2 (numbers: os_strtod, os_dtostr), which doesn't overlap with the conversions. Same flow: a verbatim move into its own .c, characterization, RED, GREEN, parity. I won't start unless you say so or there's no reply by tomorrow; slice 1 stays yours either way.

  4. zackees commented on Oct 15, 2026

    @zackees
    Member

    Taking slice 2 (numbers: os_strtod, os_dtostr), no reply in 24 h. Slice 1 (conversions) stays with @b7216309-jpg.

    Claiming: #262 slice 2

    1. Behavior-neutral: move os_strtod/os_dtostr (with their locale helpers) verbatim from platform.c into libobs/util/platform-number.c.
    2. Characterization: cmocka for both (test_dtostr_exponent from util: Fix os_dtostr leaving exponent tail digits behind #796 already covers the exponent rows).
    3. RED: Rust stubs + Tier 1 tests; GREEN: port to obs-util, shims, Tier 3 parity against the oracle, ENABLE_RUST_LIBOBS guard.

    First PR (step 1–2) today.

  5. added
    claimed
    on Oct 15, 2026
  6. zackees commented on Oct 15, 2026

    @zackees
    Member

    Slice 2 (numbers) done: #825 moved os_strtod/os_dtostr into util/platform-number.c, and #826 ported it to obs-util (platform_number.rs, Tier 1 + Tier 3 against the real C, dropped under ENABLE_RUST_LIBOBS=ON). The config-file port now shares the same parser and formatter, and the oracle compiles the real file instead of copies (#145).

    Intentional difference: Rust always uses .; C swaps in the LC_NUMERIC decimal point, so only text already written with a non-. locale point ("1,5") reads differently.

    Releasing my claim on slice 2. Left on this issue: slice 1 (conversions, @b7216309-jpg) and slices 3+ (files, directories, …).

  7. swilk19 commented on Oct 18, 2026

    @swilk19
    Contributor

    Claiming: #262 slice 3 (files: os_wfopen/os_fopen, os_fgetsize, os_stat, os_fseeki64/os_ftelli64, os_fread_mbs/os_fread_utf8, os_quick_read_*/os_quick_write_* incl. _safe, os_get_file_size)

    1. Behavior-neutral: move them verbatim from platform.c into libobs/util/platform-file.c.h; add cmocka characterization where test_platform/test_os_path don't cover them.
    2. RED: Rust stubs + Tier 1; GREEN: port to obs-util (Windows paths under src/platform/windows/), Tier 3 parity against the oracle, ENABLE_RUST_LIBOBS guard.

    Decisions: Windows os_fopen keeps calling the C os_utf8_to_wcs_ptr (slice 1, @b7216309-jpg's) until slice 1 is ported, so the two slices don't overlap.

    First PR (step 1) within a day.

  8. 30 remaining items

  9. moved this from In progress to Triage in obs-rust Multiviewon Oct 25, 2026
  10. removed
    claimed
    on Oct 25, 2026
  11. zackees commented on Oct 25, 2026

    @zackees
    Member

    Triage: the slice tracker for platform.c (item of #153); slice 1 is up as #1874. Labelling it tracker.

  12. added
    tracker
    on Oct 25, 2026
  13. zackees commented on Oct 30, 2026

    @zackees
    Member

    Tracker complete: every slice of platform.c has landed in obs-util, so closing.

    Slice Unit Landed as
    1 conversions os_mbs_to_wcs, os_utf8_to_wcs, os_wcs_to_mbs, os_wcs_to_utf8 and _ptr forms #1874 (platform_conversions.rs)
    2 numbers os_strtod, os_dtostr #826 (platform_number.rs)
    3 files os_wfopen/os_fopen, sizes, stat, seek/tell, quick read/write #1444 (platform_file.rs)
    4 directories os_mkdirs #1446 (platform_mkdirs.rs)
    5 filenames os_generate_formatted_filename #1511 (platform_filename.rs)
    6 time os_nstime_to_timespec #1507 (platform_time.rs)

    Checked on master 5074635e3: each slice has an ENABLE_RUST_LIBOBS C ABI export under libobs/cmake/rust-exports.d/obs-util-platform_{conversions,number,file,mkdirs,filename,time}.txt, and the Tier 2 gates named in the tracker (test_platform, test_os_path, test_formatted_filename) are the ones CI runs for them. The tracker's step text is stale per slice 1's note: the original PRs moved each group into its own platform-*.c first, so the calls are per-file rather than through one platform.c.

    Remaining on #153: pipe-windows.c, platform-nix.c/platform-windows.c, and the threading pair; the #145 oracle stand-ins were also folded into slice 1. #153's checkbox is ticked.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    tracker

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions