Skip to content

libobs: Move the effect parser blocks to own file - #3561

Merged
rdoupe merged 6 commits into
masterfrom
fix/rust-port-extract-the-effect-par-564
Nov 3, 2026
Merged

rdoupe merged 6 commits into
masterfrom
fix/rust-port-extract-the-effect-par-564

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #3550

What and why

First step of porting the effect parser's struct and sampler-state blocks to obs-graphics: a characterization test, a behaviour-neutral extraction, and a fix for the sampler-state item's leak, C only. The Rust port of the moved file follows in its own PR on #3550. Same shape as the shader parser's blocks (#3536, then #3541).

  • test: Characterize the effect parser blocks: a new test_effect_parser_blocks (cmocka) calls ep_init(), ep_parse() and ep_free() on 65 fixed effect texts and pins, written out and compared whole, the structs (each variable's type, name and mapping), the samplers (states and values in order), the params and functions kept after each block, every error with its row, column and level, and the allocations still held after ep_free(). It covers well-formed blocks (several in a row, empty, repeated, multi-line with tabs, a value of several tokens), malformed ones (a missing name, {, ;, =, type, variable name or mapping, an empty value, a stray token before ; or }, a stray } before the block, no ; after it) and text cut short at each step of each block. Odd but real results are marked "characterized, not endorsed": among them, an item with an empty value (Filter = ;), and text that ends inside an item, leave its state name (and the value read so far) allocated after ep_free(); the last two commits fix that (below). ep_parse() and ep_free() are hidden in libobs, so the test compiles the original effect parser C into itself and links libobs for the rest; each text is parsed behind a first line of {}, whose error keeps ep_parse() from calling ep_compile() (which needs a device). No display and no graphics context, so it runs on every platform.
  • libobs: Move the effect parser blocks to own file: ep_parse_struct_var(), ep_parse_struct(), ep_parse_sampler_state_item() and ep_parse_sampler_state() move, as written, from libobs/graphics/effect-parser.c.h into the new libobs/graphics/effect-parser-blocks.c.h. The two that ep_parse() calls lose their static and are declared in a new internal graphics/effect-parser-blocks.h (a private adapter, not a new public API; effect-parser.h stays as it is); the item and variable helpers stay static. The file has its own live unity group, libobs.effect-parser-blocks (graphics module), with a precompiled header of effect-parser-blocks.h only, so the port can later move its include into a ported group. docs/rust-port/naming.md lists it under obs-graphics. Two follow-up commits sort the new group into modules.d/graphics.json and LIBOBS_SOURCES.json.
  • test: Expect the effect sampler items to free and libobs: Free the effect sampler item on all paths: ep_parse_sampler_state_item() dropped an item with an empty value (Filter = ;) without freeing its state name, and on end of text inside an item returned without freeing the state name or the value read so far: one or two allocations per malformed item, which the asan job's LeakSanitizer reported (8 allocations) from the new test. It now frees both on those paths; the return codes, tokens read and items kept are unchanged, so the effect loads or fails as before. The test expects leaked 0 in those six cases. The Rust port then has no intentional difference.

Moved code: Lain Bailey's (upstream obs-studio), credited on the move commit. No upstream issue.

Move harness (scratch, not committed): origin/master's four functions and the moved ones, each set compiled whole over logging stand-ins for every token call, strref_cmp(), cf_adderror_syntax_error(), bfree(), dstr_ncat(), dstr_free(), the init and free helpers and every da_push_back(), answering from the same seeded script. 200,000 scenarios (struct and sampler blocks, failure rates from 1/64 to 29/64) gave identical logs (4,651,504 lines, live allocations counted after each) in 8 builds: GCC and Clang, -O0 and -O2, with and without ASan and UBSan without recovery. Sixteen planted mutants all differ.

RED → GREEN

  • RED commit: test: Expect the effect sampler items to free (a246568). test_effect_parser_blocks fails sampler_errors, sampler_eof and mixed (6 cases differ: leaked 1 or leaked 2 where leaked 0 is expected). The extraction itself has no RED: the characterization test passes on master's code and after the move, unchanged.
  • GREEN: libobs: Free the effect sampler item on all paths (0224c6f). test_effect_parser_blocks passes 7/7, and under ASan and UBSan with leak detection on it has no LeakSanitizer report. test_effect_parser_blocks and the effect and shader tests (test_effect_int_bool_defaults, test_effect_lookups, test_effect_number_defaults, test_effect_param_numbers_steps, test_effect_param_types_steps, test_effect_param_values, test_effect_parser_lifecycle, test_effect_pass_loop, test_effect_set_default_null, test_shader_parser_blocks, test_shader_number_defaults) pass 12/12 on the C build and 14/14 (with _rust variants) on the hybrid libobs and on libobs-c-reference, before and after the move and after the fix, none skipped. The C, hybrid and C reference builds export the same 1767 symbols as master; ep_parse_struct and ep_parse_sampler_state are local (t) in each. --test-diff: 6366 Rust tests passed. The tests above and the export comparison ran on 0224c6f; ./unittest ran on a4e52e8 (the same code, one source-list line earlier) and passed (6366 and 912 Rust tests; Tier 2 712/712 against libobs-c-reference and 712/712 against the hybrid libobs).
  • Real app (UI, protocol output or logging changes): N/A, no UI, protocol or logging change.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change; the leak fix only lowers the shutdown leak count for malformed effect files)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (not applicable: no Rust in this PR)

rdoupe and others added 3 commits November 3, 2026 07:24
The effect parser's struct and sampler-state blocks have no C test of
their own: the effect tests cover parameter values, defaults, lookups,
passes and ep_free(). test_effect_parser_blocks calls ep_init(),
ep_parse() and ep_free() on fixed effect texts and pins, written out
and compared whole, the structs (name, each variable's type, name and
mapping), the samplers (name, states and values in order), the params
and functions kept after each block, every error with its row, column
and level, and the allocations still held after ep_free().

65 texts: well-formed structs and sampler states (several in a row,
empty, repeated, multi-line with tabs, a value of several tokens),
malformed ones (a missing name, '{', ';', '=', type, variable name or
mapping, an empty value, a stray token before ';' or '}', a stray '}'
before the block, no ';' after it) and text cut short at each step of
each block. Odd but real results are marked "characterized, not
endorsed". Among them: an item with an empty value, and end of text
inside an item, leave its state name (and the value read so far)
allocated after ep_free().

ep_parse() and ep_free() are hidden in libobs, so the test compiles
the original effect parser C into itself (effect-parser.c with its
lifecycle, parameter type and number files) and links libobs for the
rest. Every text is parsed behind a first line of "{}", whose error
keeps ep_parse() from calling ep_compile(), which needs a device;
gs_preprocessor_name() is the no-context answer, NULL. No display and
no graphics context: it runs on every platform. It passes, none
skipped, against the C, hybrid and C reference libobs.

Refs #3550.
Behaviour-neutral extraction before the Rust port. The effect parser's
struct and sampler-state blocks move, as written, into the new
libobs/graphics/effect-parser-blocks.c.h:

- ep_parse_struct_var() and ep_parse_struct();
- ep_parse_sampler_state_item() and ep_parse_sampler_state().

ep_parse() calls ep_parse_struct() and ep_parse_sampler_state(), so
those two lose their static and are declared in a new internal
graphics/effect-parser-blocks.h, a private adapter and not a new public
API; the item and variable helpers stay static in the new file.
Nothing else changes: ep_parse() calls them on the same keyword
tokens, in the same place.

The new file has its own live group, libobs.effect-parser-blocks (in
the graphics module), with a precompiled header of
effect-parser-blocks.h only, so the C oracle can compile it alone and
the port can move its include into a ported group. No Rust: the hybrid
libobs compiles the C too. The C, hybrid and C reference builds export
the same 1767 symbols as master, the two functions local (t) in each.
test_effect_parser_blocks compiles the moved file beside
effect-parser.c.

Move harness (scratch, not committed): origin/master's four functions,
as written in place, and the moved ones, each set compiled whole over
logging stand-ins for every token call (cf_next_valid_token(),
cf_token_is(), cf_token_is_type(), cf_copy_token(),
cf_go_to_valid_token(), cf_next_name(), cf_next_token_should_be(),
cf_peek_valid_token()), strref_cmp(), cf_adderror_syntax_error(),
bfree(), dstr_ncat(), dstr_free(), the init and free helpers and every
da_push_back(), each answering from the same seeded script: 200,000
scenarios (struct and sampler blocks, failure rates from 1/64 to
29/64), identical logs (4,651,504 lines, live allocations counted
after each) in 8 builds (GCC and Clang, -O0 and -O2, with and without
ASan and UBSan without recovery). Sixteen planted mutants (states
pushed as values, a state or value not freed, a value ending on '}',
an empty value pushed, the item loop stopping on any failure, the
sampler loop's '}' check changed, a wrong skip token for '{', for a
variable and for the closing ';', an unexpected break taken as a plain
one, a syntax error dropped, a variable's early return reported as
success, a variable not freed at end of text, the mapping copied into
the type, the mapping's skip token dropped) all differ.

test_effect_parser_blocks and the effect and shader tests, unchanged,
pass on the C, hybrid and C reference builds, none skipped.

Refs #3550.

Co-authored-by: Lain <[email protected]>
List libobs.effect-parser-blocks in alphabetical order among the
graphics module's groups, in modules.d/graphics.json and in the
graphics part of LIBOBS_SOURCES.json, instead of after them. No
change in what is built: the C, hybrid and C reference builds export
the same 1767 symbols, and the effect and shader tests pass on each.

Refs #3550.
@rdoupe
rdoupe requested a review from zackees as a code owner November 3, 2026 13:48
In LIBOBS_SOURCES.json, list libobs.effect-parser-blocks in
alphabetical order among the unity groups, after libobs.core-source and
before libobs.util-cf, instead of beside libobs.graphics. The existing
entries keep master's order. No change in what is built: the C, hybrid
and C reference builds export the same 1767 symbols, and the effect
and shader tests pass on each.

Refs #3550.
@vpacher

vpacher commented Nov 3, 2026

Copy link
Copy Markdown
Member

The asan failure here comes from the PR's own test, so a rerun will not clear it. test_effect_parser_blocks pins the parser's leaks with leaked 1 and leaked 2 (#3550), and LeakSanitizer reports the same allocations at exit: 303 bytes in 8 allocations, through ep_parse (run 41648082885).

Two ways through:

  1. Fix the leaks and expect leaked 0. I would prefer this one, because the goal for the known list is zero (docs/knowledge/asan-pr-failure.md).
  2. Add a bug entry for the test that names rust: Port the effect parser's struct and sampler-state blocks #3550, and raise KNOWN_ENTRIES in ci/test_sanitize_triage.py. The fix for rust: Port the effect parser's struct and sampler-state blocks #3550 then drops the entry.

ep_parse_sampler_state_item() drops an item whose value is empty
("Filter = ;") without freeing its state name, and on end of text
inside an item it returns without freeing the state name or the value
read so far. test_effect_parser_blocks pinned those as "leaked 1" and
"leaked 2", and the asan job's LeakSanitizer reports the same 8
allocations at exit, so the test fails asan as it stands.

Expect "leaked 0" in those six cases instead. They fail until the
parser frees both.

Refs #3550.
ep_parse_sampler_state_item() drops an item with an empty value
("Filter = ;") without freeing its state name, and when the text ends
inside an item it returns PARSE_EOF without freeing the state name or
the value read so far. Each malformed item leaked one or two
allocations; the effect loads or fails the same either way.

Free both when the value is empty, and take the fail path on end of
text inside the value. The return codes, the tokens read and the
items kept are unchanged. test_effect_parser_blocks passes with
"leaked 0" and has no LeakSanitizer report.

Refs #3550.
@rdoupe

rdoupe commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, you're right: the asan failure was the test's own pinned leaks. I went with option 1. Option 2 isn't open here anyway, since the known list never takes a test the PR adds.

  • test: Expect the effect sampler items to free (a246568) changes the six cases that pinned leaked 1 or leaked 2 to expect leaked 0. On its own it fails sampler_errors, sampler_eof and mixed.
  • libobs: Free the effect sampler item on all paths (0224c6f) makes ep_parse_sampler_state_item() free the state name when the value is empty, and take its fail path, which frees the state name and the partial value, when the text ends inside a value. The return codes, the tokens it reads and the items it keeps are unchanged, so an effect loads or fails as before.

On 0224c6f, test_effect_parser_blocks passes, and built with ASan and UBSan with leak detection on, it has no LeakSanitizer report. The effect and shader tests pass on the C, hybrid and C reference builds, and the export sets are unchanged. This also means the Rust port of these blocks will have no intentional difference.

@rdoupe
rdoupe added this pull request to the merge queue Nov 3, 2026
Merged via the queue into master with commit 761da5f Nov 3, 2026
42 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-extract-the-effect-par-564 branch November 3, 2026 21:59
@rdoupe rdoupe mentioned this pull request Nov 3, 2026
6 of 7 tasks
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Done in obs-rust Multiview Nov 4, 2026
@rdoupe rdoupe mentioned this pull request Nov 4, 2026
6 of 7 tasks
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