Repository navigation
feat(obs-util): port util/lexer.c to Rust (#6) - #41
Closed
b7216309-jpg wants to merge 3 commits into
Closed
b7216309-jpg wants to merge 3 commits into
b7216309-jpg wants to merge 3 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
This was referenced Oct 9, 2026
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/lexer.c(all tenEXPORTfunctions) to Rust. This is step 3 of the Phase 3 port order, beforecf-lexer/cf-parser. It is independent of #40 (utf8) and branches fromgrind/meta-4-9b41like that PR.Commits
#[repr(C)]mirrors, the oracle, the guard,rust-exports.txtand the tests, against atodo!()core. Tier 1 fails 0/16, Tier 3 aborts on the first call, and the layout tests pass.What's ported
strref_cmp,strref_cmpi,strref_cmp_strref,strref_cmpi_strrefvalid_int_str,valid_float_strvalid_int_str(s, n)/valid_float_str(s, n)(nkeeps C's meaning, including the sign not counting toward it)lexer_getbasetokenget_base_token(text, ignore_ws) -> (advance, Option<BaseToken>)lexer_getstroffsetget_str_offset(text, pos) -> (row, col)error_data_add,error_data_buildstringformat_error_item. The darray push and thebmalloc/bstrdupallocations stay in the shim, since C frees them withbfree.error_data_addreusesffi::darray::darray_push_back_array, so capacity growth matches.The
lexer.hstatic inlinehelpers stay in C under the header-inline exemption. The layout tests coverstrref,base_token(includingsizeof(enum base_token_type)),error_item,error_dataandlexer.Decisions
charsignedness. C compareschar, so bytes ≥ 0x80 sort below ASCII on x86 and above it on Arm Linux. The core compares viacore::ffi::c_char, so it matches the platform. There is a Tier 1 test for this. Clippy is clean foraarch64-unknown-linux-gnu, wherec_charisu8.toupperis the C locale's, ASCII only. Parity on Windows/MSVC runs high bytes throughstrref_cmpi*and matches UCRT.oracle/test_dstr.c: the lexer oracle needsdstr_catf, which lives inutil/dstr.c, and that pulls inutf8.c. Rather than linking all of dstr, this test-onlydstr_catf(dstr_vcatfwith plainbreallocgrowth, since the capacity isn't observable here) follows thetest_bmem.cprecedent. The policy doc says to delete it whendstr.cis ported.bmemdup(forbstrdup) is added totest_bmem.c.lexer_getstroffsetwith a NULLlex->textleavesrow/coluntouched, where C dereferences NULL. This is listed inrust/README.mdand in the parity file.Tier 3 and mutation check
Parity compares the shim with the oracle: return values, the lexer offset, every
base_tokenfield (pre-filled with sentinels, so the untouchedpassed_whitespaceis checked too), and the fullerror_datacontents (num,capacity, each item, the message copies, and the built string). Inputs are random bytes weighted toward the lexer's special characters (signs,.,e, CR/LF, NUL, high bytes), plus two structured generators.I ran fourteen mutations on the core. The first generators missed two of them, which led to the two structured generators:
strref_cmp. This needs a strref holding a NUL exactly where the C string ends. The shared-prefix property now allows NULs in the strref's tail.einvalid_float_str. Random characters rarely form1e-3.number_like()now builds[sign] digits [. digits] [e [sign] digits] [sign]with stray characters.All fourteen are caught now:
cmp_strrefreturns 1 when only the second is emptycmpicase-sensitivecmp_strrefloop<instead of<=neaccepted.allowed after the exponenteallowed without digitsgetbasetokengetstroffsetdoes not skip pairs(null)Verification
On Windows 11 (MSVC):
soldr cargo test --workspace --lockedpasses. Unlike utf8, the lexer shim is not platform-gated, so Tier 3 runs the shim here../lintpasses.cargo clippy -p obs-util -p libobs-rust --lib -D warningsis clean forx86_64-unknown-linux-gnu,aarch64-unknown-linux-gnuandaarch64-apple-darwin.Not verified locally
test_lexerruns unchanged against the Rust symbols with ON, andcf-lexer.c/cf-parser.c/text-lookup.clink against them. The exported-symbol diff (linux-validate/run.sh,tier2-validate) also has to wait: this machine has no Docker and no WSL. Please watchrust-linux-tier2andrust-tier2in CI.🤖 Generated with Claude Code