Skip to content

rust: Port util/config-file.c to obs-util - #77

Merged
zackees merged 7 commits into
obs-rust:masterfrom
chriscoveries:rust/config-file-port
Oct 10, 2026
Merged

zackees merged 7 commits into
obs-rust:masterfrom
chriscoveries:rust/config-file-port

Conversation

@chriscoveries

@chriscoveries chriscoveries commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Refs #44

Ports libobs/util/config-file.c to Rust per docs/rust-port/testing-policy.md:

  • Safe core rust/obs-util/src/config_file.rs: Config/Section/Item behind a Mutex, replicating C semantics — HASH_ADD_STR prepend order (last-added duplicate wins lookups), one section object per [ header, in-place value update on config_set_*, # comments, [] aborts the parse, BOM strip on read, os_dtostr byte-for-byte output including the positive-exponent digit-duplication quirk (1e+18 → 1e188).
  • Thin FFI shim rust/obs-util/src/ffi/config_file.rs: all 30 config_* symbols, no logic; every unsafe documented.
  • Oracle rust/obs-c-oracle/oracle/config_file.c + config_file_host.c: #define renames + #include of the untouched original.
  • Tier 1: 48 tests 1:1 from test/cmocka/test_config_file.c (RED commit 3d4750a, reviewed: coverage complete), including the test_open_null_config NULL-config_t ** asserts through the FFI shim.
  • Tier 3: proptest parity over arbitrary/malformed INI input — saved files compared byte-for-byte in separate temp dirs plus all return values, defaults, save_safe side effects.
  • util/config-file.c moved under the ENABLE_RUST_LIBOBS OFF guard; symbols added to rust-exports.txt (export_list passes; libobs exports identical OFF vs ON, 1752 symbols).

Mutation check: dtostr precision 17→16 fails 3 parity tests (dtostr_values, parity_open_mutate_save, parity_defaults) — reverted, suite green.

Intentional behavior differences: none on POSIX; on Windows the core writes the UTF-8 BOM and hands wide paths to the OS like C. path_from_bytes substitutes U+FFFD like C (MultiByteToWideChar(CP_UTF8, 0) at libobs/util/utf8.c:47 has no MB_ERR_INVALID_CHARS), but via a different maximal-invalid-subpart rule, so a pre-existing file named after the resulting U+FFFD sequence could open on one side and not the other; both return CONFIG_FILENOTFOUND in the normal case. The oracle host stub uses the stricter MB_ERR_INVALID_CHARS, which is not libobs behavior.

Gates: ./lint ok; ./unittest — Tiers 1–3 plus Tier 2 cmocka 29/29 in Docker OFF/ON; clippy -D warnings and fmt clean; soldr cargo test --workspace --locked green.

@zackees

zackees commented Oct 10, 2026

Copy link
Copy Markdown
Member

Rebased on master (incl. #70's config_save fclose/empty-config fix). Resolved build.rs conflict (keep both platform_conv_host.c/utf8.c and lexer.c).

  • Port already reproduces the fixed C behavior; Tier 1 mirrors it (config_save_reports_flush_failure via /dev/full, config_save_safe_preserves_original, config_save_empty_succeeds). RED: at the RED commit they panic on todo!(); mutation check (ignoring write/flush errors) makes the two flush tests fail; head passes.
  • Parity: INI generator now mixes raw bytes with structured lines incl. malformed ones (unterminated/empty headers, text after ], keys before sections, no =, empty keys, comments, escapes, CR/LF/CRLF, no final newline) with colliding names so probes hit. Green at 2000 cases.
  • Oracle needed system <uthash.h> (no CI host besides Linux has it): vendored upstream uthash v2.3.0 under rust/obs-c-oracle/oracle/uthash.
  • Local gate (lint, rust-test, tier2-linux) passed and stamped.

@zackees
zackees force-pushed the rust/config-file-port branch 5 times, most recently from 384ea65 to d81a0db Compare October 10, 2026 18:29
chriscoveries and others added 7 commits October 10, 2026 13:18
Port of every assertion in test/cmocka/test_config_file.c and
test_config_save.c 1:1 into rust/obs-util/tests/config_file.rs, against
todo!() stubs in rust/obs-util/src/config_file.rs. NULL-config_t* cases
are reserved for the C ABI parity file.

soldr cargo test -p obs-util --test config_file: 0 passed, 46 failed
(all 'not implemented' panics from the todo!() stubs, as expected for RED).

Lane: rd3
Signed-Agent: rd3 · swe-2-max · devin-cloud · roundplane
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Safe core (Config/Section/Item) plus thin extern C shim in
src/ffi/config_file.rs; the C file moves under the
ENABLE_RUST_LIBOBS OFF-only guard and its 30 config_* symbols join
rust-exports.txt. C oracle wrapper (config_file.c + config_file_host.c)
feeds Tier 3 proptest parity over arbitrary INI input, byte-for-byte
saved files and all return values.

Refs #44

Lane: wick-devin-rt
Signed-Agent: devin-rt
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
- tests/config_file.rs: read_file_utf8 strips a leading UTF-8 BOM like
  C's expect_file via os_fread_utf8, matching the core's BOM-on-save on
  Windows (fixes every post-save expect_file there).
- Drop the false Windows-difference claim: the core does write the
  _O_WTEXT BOM and wide paths. The remaining difference is precise:
  path_from_bytes lossy-converts invalid UTF-8 where C's UTF-8->UTF-16
  conversion fails the open.
- test_open_null_config: port the two missing 1:1 asserts
  (config_open(NULL)->CONFIG_ERROR, config_open_string(NULL)->
  CONFIG_ERROR, config_close(NULL) no-op) through the FFI shim, the only
  place NULL exists.

Refs #44

Lane: wick-devin-rt
Signed-Agent: devin-rt
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Refs #44

Lane: wick-devin-rt
Signed-Agent: devin-rt
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Generate INI from well-formed and malformed line shapes (unterminated and
empty headers, trailing text after ], keys before sections, lines without
=, empty keys, comments, escapes, CR/LF/CRLF, no final newline) alongside
raw bytes, with colliding section/key names so probes hit stored values.

libobs/util/uthash.h needs the system <uthash.h>; vendor upstream v2.3.0
for the oracle so cargo test builds without uthash-dev.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=3fac5f5b22f24d4fd696e503a96d7c548879a97a secs=20 lanes=lint:reused@4426dca47946,rust-test:reused@915d520bcf1e,tier2-linux:run
Ci-Attestation: {"at":1791649837,"gate":"rust/all/fmt","host":"linux-x86_64","key":"4426dca479464ae6d38898d1f00c9ddb9842e558d0db7ed07301e69fd69ed6b3","lane":"lint","parents":["41df98f4c5b5bf69604c056c0a8a9badb08bb106"],"secs":null,"stamp":"28cf47c68c079d192c07a5cb409a1efc","tree":"3fac5f5b22f24d4fd696e503a96d7c548879a97a","v":1,"via":"reused"}
Ci-Attestation: {"at":1791649837,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"4426dca479464ae6d38898d1f00c9ddb9842e558d0db7ed07301e69fd69ed6b3","lane":"lint","parents":["41df98f4c5b5bf69604c056c0a8a9badb08bb106"],"secs":null,"stamp":"fe810225dfa218b8a9857b622c9c315e","tree":"3fac5f5b22f24d4fd696e503a96d7c548879a97a","v":1,"via":"reused"}
Ci-Attestation: {"at":1791649837,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"915d520bcf1e71bf9818fd84b20e6ed27af7b24e6ddd6d47f9fc8f735158ebc1","lane":"rust-test","parents":["41df98f4c5b5bf69604c056c0a8a9badb08bb106"],"secs":null,"stamp":"8931e61b5ad5e54fdab58e6172c15860","tree":"3fac5f5b22f24d4fd696e503a96d7c548879a97a","v":1,"via":"reused"}
Ci-Attestation: {"at":1791650811,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"63e30873239e9d17da068b7cc3f2a93a8f775617577adf9819bc800374052f29","lane":"tier2-linux","parents":["41df98f4c5b5bf69604c056c0a8a9badb08bb106"],"secs":19,"stamp":"4c15a7e619379e455601b1da3c0873f0","tree":"3fac5f5b22f24d4fd696e503a96d7c548879a97a","v":1,"via":"run"}
- macOS has no /dev/full: config_save_safe_preserves_original is
  Linux-only, like its Tier 2 counterpart.
- Exclude the vendored uthash.h from clang-format, like deps/w32-pthreads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=c63130acd9be2435589f676b145cb40718d773f4 secs=83 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791656981,"gate":"rust/all/fmt","host":"linux-x86_64","key":"bc249f383e2df21ca0174f7b95c9f36eca34e3a14302d4eda3cd24a40c289c26","lane":"lint","parents":["74ef7c5c9ffd9f317685cd60a9b775764160618a"],"secs":23,"stamp":"90b1ec02c143365c01d2d2ec87d179da","tree":"c63130acd9be2435589f676b145cb40718d773f4","v":1,"via":"run"}
Ci-Attestation: {"at":1791656981,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"bc249f383e2df21ca0174f7b95c9f36eca34e3a14302d4eda3cd24a40c289c26","lane":"lint","parents":["74ef7c5c9ffd9f317685cd60a9b775764160618a"],"secs":23,"stamp":"df13f42388c3aaf69f57651c477530de","tree":"c63130acd9be2435589f676b145cb40718d773f4","v":1,"via":"run"}
Ci-Attestation: {"at":1791656981,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"a3c29d667a28b4f8e254224522dd242c4e0f3e6dd6dfeb57d9c78c712d3169bc","lane":"rust-test","parents":["74ef7c5c9ffd9f317685cd60a9b775764160618a"],"secs":29,"stamp":"402b0df62a1ce293b6262321308b3e76","tree":"c63130acd9be2435589f676b145cb40718d773f4","v":1,"via":"run"}
Ci-Attestation: {"at":1791656981,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"058f04a566e2db73a4c11e64246d8dd1ea25807d8f26e20b38d097a6b85a1d8d","lane":"tier2-linux","parents":["74ef7c5c9ffd9f317685cd60a9b775764160618a"],"secs":31,"stamp":"948a7fd3c0cd86ab8738790f0da32a92","tree":"c63130acd9be2435589f676b145cb40718d773f4","v":1,"via":"run"}
…racle

After rebasing onto the dstr/utf8/bmem port (#59), the config-file oracle
defined a second os_fread_utf8 (also in test_stubs.c, which is faithful
to platform.c and returns 0 where this copy returned the size) and called
dstr_printf, which the oracle now provides only as oracle_dstr_printf.
Drop the duplicate and map dstr_printf. Also drop the second vendored
uthash.h; the oracle already vendors the identical v2.3.0 header.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=ef51922f491a4fe263185dc1da2378b22a8b8dad secs=122 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791663729,"gate":"rust/all/fmt","host":"linux-x86_64","key":"3d995bbf6c67895f6671a6f6fc11e865076044218ad98830103f697e65d4e650","lane":"lint","parents":["7527727eb95c00ed71c159c3e2e1c7f86ef9e1e5"],"secs":36,"stamp":"c575d8d07689e72a90d4171fa2697360","tree":"ef51922f491a4fe263185dc1da2378b22a8b8dad","v":1,"via":"run"}
Ci-Attestation: {"at":1791663729,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"3d995bbf6c67895f6671a6f6fc11e865076044218ad98830103f697e65d4e650","lane":"lint","parents":["7527727eb95c00ed71c159c3e2e1c7f86ef9e1e5"],"secs":36,"stamp":"869a6d8d1f196354c46bd557fc50e48c","tree":"ef51922f491a4fe263185dc1da2378b22a8b8dad","v":1,"via":"run"}
Ci-Attestation: {"at":1791663729,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"26a01ce11566f855f04267b0ffe9f56b8fc971fd5d474b414647ea8de3339ae3","lane":"rust-test","parents":["7527727eb95c00ed71c159c3e2e1c7f86ef9e1e5"],"secs":28,"stamp":"32e302c2650a1ca783b70871b606bdba","tree":"ef51922f491a4fe263185dc1da2378b22a8b8dad","v":1,"via":"run"}
Ci-Attestation: {"at":1791663729,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"ba570743c5bfee732fff75a44b04461a8dec0b0b227b5881d915ac71e00c0957","lane":"tier2-linux","parents":["7527727eb95c00ed71c159c3e2e1c7f86ef9e1e5"],"secs":58,"stamp":"91d2fa8e6981d011391c50ad6ff4586b","tree":"ef51922f491a4fe263185dc1da2378b22a8b8dad","v":1,"via":"run"}
@zackees

zackees commented Oct 10, 2026

Copy link
Copy Markdown
Member

Rebased onto master (after #49, #59, #76, #78 and #106). Changes beyond conflict resolution:

  • I dropped the second vendored uthash.h and its include path. The oracle already vendors the identical v2.3.0 header in vendor/uthash.
  • The config-file oracle now reuses master's test_stubs.c os_fread_utf8, which faithfully returns 0 like platform.c; this PR's copy returned the size. It also maps dstr_printf to oracle_dstr_printf.

RED→GREEN, checked with soldr's cache disabled: config_file fails 47/48 at the RED commit and the full suite passes at head, including config_file_parity. Tier 2 OFF/ON passes, including test_config_save and test_config_file, so #70's flush and empty-config fixes hold with the Rust port. The local gate passes and is stamped.

@zackees
zackees force-pushed the rust/config-file-port branch from d81a0db to 2a56110 Compare October 10, 2026 20:22
@zackees
zackees merged commit bedfe14 into obs-rust:master Oct 10, 2026
22 checks passed
swilk19 pushed a commit to swilk19/obs-studio that referenced this pull request Oct 10, 2026
Both are swapped out by ENABLE_RUST_LIBOBS (obs-rust#77, obs-rust#78) but had no row in
rust/README.md. The intentional differences come from their parity test
headers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=9bf357cc9b333ab587a9ef1a12a03c5e10401b49 secs=104 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791675815,"gate":"rust/all/fmt","host":"linux-x86_64","key":"8cf5e62ed81a4c59ed6b7033b8f8cbbf74d28306dd3a4d4626d241aabd83034a","lane":"lint","parents":["faaca71086cff4fed3c2d807d98cb98e8e109ab4"],"secs":18,"stamp":"f54bd4c098026f1f9d10d31c1973d641","tree":"9bf357cc9b333ab587a9ef1a12a03c5e10401b49","v":1,"via":"run"}
Ci-Attestation: {"at":1791675815,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"8cf5e62ed81a4c59ed6b7033b8f8cbbf74d28306dd3a4d4626d241aabd83034a","lane":"lint","parents":["faaca71086cff4fed3c2d807d98cb98e8e109ab4"],"secs":18,"stamp":"988410300c630644864eb4e5a8cae506","tree":"9bf357cc9b333ab587a9ef1a12a03c5e10401b49","v":1,"via":"run"}
Ci-Attestation: {"at":1791675815,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"41470548073c550943aa7b8d49f8768c2ca95be8f542e5c4b5ae60065d9c2dca","lane":"rust-test","parents":["faaca71086cff4fed3c2d807d98cb98e8e109ab4"],"secs":35,"stamp":"dc126abfc792a7b5644da0cf8bd58b2e","tree":"9bf357cc9b333ab587a9ef1a12a03c5e10401b49","v":1,"via":"run"}
Ci-Attestation: {"at":1791675815,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"ad50e2b36bd04a0536651de9bb040dca4d14bcb9e40d429d60ecfe1683cd071d","lane":"tier2-linux","parents":["faaca71086cff4fed3c2d807d98cb98e8e109ab4"],"secs":51,"stamp":"862b2575f5f1a0e16f41950eccc711bb","tree":"9bf357cc9b333ab587a9ef1a12a03c5e10401b49","v":1,"via":"run"}
@chriscoveries
chriscoveries deleted the rust/config-file-port branch October 11, 2026 02:18
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.

2 participants