Repository navigation
feat(obs-util): port util/text-lookup.c to Rust (#6) - #52
Closed
b7216309-jpg wants to merge 8 commits into
Closed
b7216309-jpg wants to merge 8 commits into
b7216309-jpg wants to merge 8 commits into
Conversation
Adds the C ABI shim for the ten EXPORT functions of libobs/util/lexer.c, the #[repr(C)] mirrors of strref, base_token, error_item, error_data and lexer, the oracle wrapper, the ENABLE_RUST_LIBOBS guard, rust-exports.txt entries, and Tier 1, Tier 2 layout and Tier 3 tests. The safe core bodies are todo!(), so soldr cargo test -p obs-util --test lexer fails 0/16 and --test lexer_parity aborts on the first call; the layout test passes. The lexer oracle needs dstr_catf and bmemdup. oracle/test_dstr.c is a test-only dstr_catf (dstr_vcatf with plain brealloc growth), like test_bmem.c for bmem, so the oracle does not pull in util/dstr.c and its utf8.c dependency. bmemdup joins test_bmem.c. Refs obs-rust#6 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Implements the safe core of libobs/util/lexer.c. GREEN for Tier 1 (16/16), the layout tests (5/5) and Tier 3 (9/9). Characters compare as the platform's C char (c_char), so bytes from 0x80 order as in C on both signed (x86) and unsigned (Arm Linux) char targets. toupper is the C locale's, ASCII only. Intentional difference: lexer_getstroffset leaves the outputs untouched when lex->text is NULL, where C dereferences it. Refs obs-rust#6 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # libobs/cmake/rust-exports.txt # rust/obs-c-oracle/build.rs # rust/obs-c-oracle/src/lib.rs
Behavior-neutral move, as the function-extraction policy requires. These 15 functions move verbatim from util/dstr.c into the new util/dstr-libc.c: - the printf family (dstr_printf, dstr_catf, dstr_vprintf, dstr_vcatf), which takes C varargs and va_list; - the wide-character compares (wstrcmpi, wstrcmp_n, wstrcmpi_n, wstrstri, wcsdepad), which depend on towupper and wchar_t width; - the conversions (dstr_from_mbs, dstr_to_mbs, dstr_to_wcs, dstr_from_wcs, dstr_to_upper, dstr_to_lower), which go through platform.c and the locale. wstrblank moves with them, and the static is_padding helper, which both files use, is copied. No header, signature or behavior changes, and the new file is always compiled. What stays in dstr.c is pure byte-string logic that a Rust port can replace under ENABLE_RUST_LIBOBS. Stable Rust cannot define variadic functions, so the printf family has to stay in C. Refs obs-rust#6 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds the C ABI shim for the 26 EXPORT functions left in libobs/util/dstr.c after the dstr-libc.c split, the #[repr(C)] mirror of struct dstr, the oracle wrapper, the ENABLE_RUST_LIBOBS guard, rust-exports.txt entries, and Tier 1, layout and Tier 3 tests. The safe core bodies are todo!(), so soldr cargo test -p obs-util --test dstr fails 0/24 and --test dstr_parity aborts on the first call; the layout test passes. The core is generic over DstrStore, the dstr state plus the allocator calls C makes on it; the shim implements it on the caller's struct dstr with bmalloc/brealloc/bfree, so C and Rust keep sharing dstrs without a copy per call. The test_dstr.c stand-in stays: dstr_catf now lives in dstr-libc.c, which stays in C. Refs obs-rust#6 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Implements the safe core of the byte-string half of libobs/util/dstr.c. GREEN for Tier 1 (24/24), the layout test (1/1) and Tier 3 (5/5). Growth follows the dstr.h inline dstr_ensure_capacity, so capacity matches C after every call. Sources are read before the destination changes; where C reads past a source or through a NULL one, the port reads NUL. Intentional differences, where C is undefined, crashes or hangs: a source inside the destination reads as it was before the call; out-of-range insert/insert_dstr/insert_ch/remove/right arguments do nothing; a NULL or empty dstr_replace find does nothing (C dereferences NULL or loops forever); dstr_insert_ch does not write the extra byte C writes past a full buffer; strlist_split on NUL returns the whole string. Refs obs-rust#6 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds the C ABI shim for text_lookup_create, text_lookup_add, text_lookup_destroy and text_lookup_getstr, the oracle wrapper, the ENABLE_RUST_LIBOBS guard, rust-exports.txt entries, and Tier 1 and Tier 3 tests. The safe core bodies are todo!(), so soldr cargo test -p obs-util --test text_lookup fails 0/12 and --test text_lookup_parity aborts on the first call. struct text_lookup is opaque to C, so there is no layout test: a lookup_t is a boxed Rust TextLookup. The oracle runs on the lexer and dstr oracles. Two test-only stand-ins let it build everywhere cargo test runs: oracle/test_platform_io.c for os_fopen/os_fread_utf8 (util/platform.c) and oracle/include/uthash.h for the system uthash, which the Rust CI jobs do not install. Refs obs-rust#6 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Implements the safe core of the locale string tables. GREEN for Tier 1 (12/12) and Tier 3 (2/2). TextLookup owns a HashMap of CStrings: their buffers never move while an entry lives, so a value pointer handed to C stays valid until its key is replaced or the lookup is destroyed, as with the C hash table. File reading follows os_fread_utf8 (BOM skipped; an empty or BOM-only file fails; the text ends at the first NUL), then every CR becomes a space and the C parser's quirks are kept. Intentional differences: a quote right before a newline or the end of the text ends parsing, where C's string length wraps around to SIZE_MAX and bstrdup_n crashes; NULL lookup, lookup_val or out return false where C dereferences them. Refs obs-rust#6 Co-Authored-By: Claude Opus 5.5 <[email protected]>
6 of 7 tasks
Contributor
Author
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 #43 (Phase 3 tracking; #6 closed when #33 merged)
Ports
libobs/util/text-lookup.c(the locale string tables behindobs_module_textand the frontend'sStr()) to Rust:text_lookup_create,text_lookup_add,text_lookup_destroy,text_lookup_getstr.Commits (new in this PR)
rust-exports.txtand the tests, against atodo!()core. Tier 1 fails 0/12 and Tier 3 aborts.Design
struct text_lookupis private totext-lookup.c, solookup_t *is a boxed RustTextLookup. There is no#[repr(C)]mirror and no layout test.CStrings in aHashMap. Their heap buffers don't move when the map grows, so a pointer returned bytext_lookup_getstrstays valid until that key is replaced or the lookup is destroyed, the same lifetime as with the uthash table.os_fread_utf8: the UTF-8 BOM is skipped; an empty or BOM-only file makescreate/addfail; the text ends at the first NUL. Every CR then becomes a space (dstr_replace(&file_str, "\r", " ")).lookup_gettoken/lookup_getstringtoken/lookup_addfiledataon the safe base lexer from feat(obs-util): port util/lexer.c to Rust (#6) #41, quirks included (characterized, not endorsed):Key = valuestores" ";Key="") ends parsing of the whole file;=is skipped (B==cstores=);bnum_allocsno longer counts them (C never frees them;text_lookup_destroydoes).A crash in today's C code
lookup_getstringtokencomputes the value length as1 + (temp - offset) - 1 - 1when the closing quote check sees the opening quote. That happens for a quote immediately followed by a newline or the end of the file, e.g. a locale lineKey=". Thesize_tlength wraps toSIZE_MAX, andbstrdup_nthen tries to copy that much. One malformed line in any locale.inicrashes OBS. The port treats that string as empty, which ends parsing like any other empty value. The parity generator never emits a quote right before LF, NUL or EOF so the oracle doesn't crash. It's listed as an intentional difference inrust/README.md. Happy to send a separate C fix formasterif wanted.Other intentional differences: a NULL
lookup,lookup_valoroutreturnsfalse, where C dereferences them.Oracle stand-ins (test-only)
oracle/test_platform_io.c:os_fopen/os_fread_utf8, copied fromplatform.c(withftelland the dstr oracle'sastrcmp_n). This avoids linking all of platform.oracle/include/uthash.h: the four uthash macrostext-lookup.cuses (HASH_FIND_STR,HASH_REPLACE_STR,HASH_DELETE,HASH_ITER) as a linked list. The systemuthash.his an external dependency that the Rust CI jobs don't install. Lookups give the same results whatever the hash, and the include dir is scoped to the text-lookup oracle build only.The policy doc says to delete both when the oracle can link
platform.cand a real uthash.Tier 3 and mutation check
Random locale-like files (key=value lines, quotes, escapes, comments, CR/LF,
=/==, BOMs, arbitrary bytes) are written to temp files and loaded by both.createmust agree on success, andgetstron every candidate key (each word of the files, with and without quotes, plus whitespace and punctuation keys). This is checked before and aftertext_lookup_addof a second random file, over 1,024 file pairs.Thirteen mutations: twelve caught, one equivalent.
=skipped twice\"not unescaped#without push-backVerification
On Windows 11 (MSVC):
soldr cargo test --workspace --lockedpasses (146 tests)../lintpasses.-D warningsis clean for x86_64/aarch64 Linux and aarch64 macOS.Not verified locally
test_text_lookupruns unchanged on the Rust symbols with ON, and every module's locale loading goes through them.There is no Docker or WSL here.
🤖 Generated with Claude Code