Skip to content

libobs: Move the effect parser passes to own file - #3599

Merged
rdoupe merged 4 commits into
masterfrom
fix/rust-port-extract-the-effect-par-585
Nov 4, 2026
Merged

rdoupe merged 4 commits into
masterfrom
fix/rust-port-extract-the-effect-par-585

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #3598

What and why

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

  • test: Characterize the effect parser passes: a new test_effect_parser_passes (cmocka) calls ep_init(), ep_parse() and ep_free() on 57 fixed effect texts and pins, written out and compared whole, the techniques (each pass's name and every token of its vertex and pixel programs, the zeroed end token included), the params and functions kept after them, every error and warning with its row, column and level, and the allocations still held after ep_free(). It covers well-formed techniques (one or two passes, named and unnamed, the _shader and _program spellings, empty passes and techniques, two commands for one program, multi-line with tabs, the compile warning, a call of any tokens or none), malformed passes (a missing ; before }, an unknown command, a missing =, a stray ;, a missing {, a second name), malformed techniques (an entry other than a pass, a missing {, no ; after it, a missing or bad name, a stray } before it) and text cut short at each step. Odd but real results are marked "characterized, not endorsed": among them, a missing ; before a pass's } drops the whole technique and what follows it, and an entry other than a pass ends the technique. A technique cut off after its name, or without { and with no ; after it, left its name 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 passes to own file: ep_parse_pass_command_call(), ep_parse_pass_command(), ep_parse_pass() and ep_parse_technique() move, as written, from libobs/graphics/effect-parser.c.h into the new libobs/graphics/effect-parser-passes.c.h. ep_parse() calls ep_parse_technique(), so it loses its static and is declared in a new internal graphics/effect-parser-passes.h (a private adapter, not a new public API; effect-parser.h stays as it is); the pass and command helpers stay static. The file has its own live unity group, libobs.effect-parser-passes (graphics module), with a precompiled header of effect-parser-passes.h only, so the port can later move its include into a ported group. docs/rust-port/naming.md lists it under obs-graphics. test_effect_parser_blocks and its _rust variant, which compile effect-parser.c.h into themselves, compile the moved file beside it.
  • test: Expect the effect technique name to free and libobs: Free effect technique names on all paths: ep_parse_technique() returned without freeing the technique's name when the text ends right after the name, and when a technique without { has no ; after it: one allocation per malformed technique, which LeakSanitizer reports (4 allocations) from the new test when it is built with ASan. It now frees the technique on those two returns; the return points, tokens read and techniques kept are unchanged, so the effect loads or fails as before. The test expects leaked 0 in those four 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, as written in place, and the moved ones, each set compiled in its own file with logging wrappers around every call it makes (every token call, cf_adderror() and its expecting and syntax-error forms, bstrdup_n(), strref_cmp(), cf_token_clear(), the pass and technique init and free helpers and every da_push_back()), run on the real cf parser over the same 200,000 effect texts (well-formed techniques with 1/64 to 29/64 of their tokens dropped, replaced or joined by others, a quarter cut short), with the techniques kept, the errors and the live allocations logged after each: identical logs (6,346,815 lines) 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 technique name to free (77d4364). test_effect_parser_passes fails technique_errors, eof and mixed (4 cases differ: leaked 1 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 effect technique names on all paths (2efedae). test_effect_parser_passes passes 5/5, and built with ASan and UBSan it has no LeakSanitizer report. test_effect_parser_passes, 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_number_defaults, test_shader_param_names, test_shader_param_values_steps, test_shader_parser_blocks, test_shader_sampler_convert) pass 16/16 on the C build and 19/19 (with the _rust variants) on the hybrid libobs and on libobs-c-reference, 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_technique is local (t) in each. Runs were on 2efedae. ./unittest ran on the same commits before their rebase onto current master (no change to these files) and passed: 6450 and 912 Rust tests, Tier 2 718/718 against libobs-c-reference and 718/718 against the hybrid libobs. The local gate could not stamp this head here, so PR CI runs the full suite.
  • 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 4 commits November 3, 2026 21:24
The effect parser's passes and techniques have no C test of their own:
the effect tests load whole effects through a device.
test_effect_parser_passes calls ep_init(), ep_parse() and ep_free() on
fixed effect texts and pins, written out and compared whole, the
techniques (name, each pass's name, and every token of its vertex and
pixel programs, the zeroed end token included), the params and
functions kept after them, every error and warning with its row,
column and level, and the allocations still held after ep_free().

57 texts: well-formed techniques (one or two passes, named and unnamed,
the _shader and _program spellings, an empty pass or technique, two
commands for one program, multi-line with tabs, the compile warning, a
call of any tokens or none), malformed passes (a missing ';' before
'}', an unknown command, a missing '=', a stray ';', a missing '{', a
second name), malformed techniques (an entry other than a pass, a
missing '{', no ';' after it, a missing or bad name, a stray '}'
before it) and text cut short at each step. Odd but real results are
marked "characterized, not endorsed". Among them: a technique cut off
after its name, or without '{' and with no ';' after it, leaves its
name 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
blocks, lifecycle, parameter type and number files) and links libobs
for the rest, as test_effect_parser_blocks does. Every 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: it runs on every platform. It passes, none skipped, against
the C, hybrid and C reference libobs.

Refs #3598.
Behaviour-neutral extraction before the Rust port. The effect parser's
passes and techniques move, as written, into the new
libobs/graphics/effect-parser-passes.c.h:

- ep_parse_pass_command_call() and ep_parse_pass_command();
- ep_parse_pass();
- ep_parse_technique().

ep_parse() calls ep_parse_technique(), so it loses its static and is
declared in a new internal graphics/effect-parser-passes.h, a private
adapter and not a new public API; the pass and command helpers stay
static in the new file. Nothing else changes: ep_parse() calls it on
the same "technique" token, in the same place.

The new file has its own live group, libobs.effect-parser-passes (in
the graphics module), with a precompiled header of
effect-parser-passes.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, ep_parse_technique local (t) in each.
test_effect_parser_passes, test_effect_parser_blocks and
test_effect_parser_blocks_rust compile 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 in its own
file with logging wrappers around every call it makes
(cf_next_token(), cf_next_valid_token(), cf_token_is(),
cf_go_to_token(), cf_go_to_valid_token(), cf_next_token_should_be(),
cf_peek_valid_token(), cf_next_name(), cf_adderror() and its
expecting and syntax-error forms, bstrdup_n(), strref_cmp(),
cf_token_clear(), the pass and technique init and free helpers and
every da_push_back()), run on the real cf parser over the same
200,000 effect texts (well-formed techniques with 1/64 to 29/64 of
their tokens dropped, replaced or joined by others, a quarter cut
short), with the techniques kept, the errors and the live allocations
logged after each: identical logs (6,346,815 lines) in 8 builds (GCC
and Clang, -O0 and -O2, with and without ASan and UBSan without
recovery). Sixteen planted mutants (a pass not freed on either
failure path, a command spelling, vertex tokens into the pixel
program, the compile warning as an error, no end token, a '}' in a
call taken as the end of the text, any failed command ending the
pass, a wrong skip token for the name, for a technique without '{', for
an unknown command and for a missing '=', the pass's '}' or the error
path's token not stepped over, a pass name cut short, the technique's
name freed at end of text) all differ.

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

Refs #3598.

Co-authored-by: Lain <[email protected]>
ep_parse_technique() returns without freeing the technique's name when
the text ends right after the name, and when a technique without '{'
has no ';' after it. test_effect_parser_passes pinned those as
"leaked 1", and LeakSanitizer reports the same 4 allocations at exit
when the test is built with ASan, so the test fails the asan job as it
stands.

Expect "leaked 0" in those four cases instead. They fail until the
parser frees the name.

Refs #3598.
ep_parse_technique() returns without freeing the technique's name when
the text ends right after the name, and when a technique without '{'
has no ';' after it. Each such technique leaked one allocation; the
effect fails to load either way.

Free the technique on those two returns, as the error path does. The
return points, the tokens read and the techniques kept are unchanged.
test_effect_parser_passes passes with "leaked 0" and has no
LeakSanitizer report.

Refs #3598.
@rdoupe
rdoupe force-pushed the fix/rust-port-extract-the-effect-par-585 branch from 34c1991 to 2efedae Compare November 4, 2026 02:28
@rdoupe
rdoupe marked this pull request as ready for review November 4, 2026 02:42
@rdoupe
rdoupe requested a review from zackees as a code owner November 4, 2026 02:42
@rdoupe
rdoupe added this pull request to the merge queue Nov 4, 2026
Merged via the queue into master with commit 658cbf1 Nov 4, 2026
44 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-extract-the-effect-par-585 branch November 4, 2026 02:59
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.

1 participant