Repository navigation
libobs: Move the effect parser passes to own file - #3599
Merged
Merged
Conversation
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
force-pushed
the
fix/rust-port-extract-the-effect-par-585
branch
from
November 4, 2026 02:28
34c1991 to
2efedae
Compare
rdoupe
marked this pull request as ready for review
November 4, 2026 02:42
This was referenced Nov 4, 2026
This was referenced Nov 4, 2026
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 #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 newtest_effect_parser_passes(cmocka) callsep_init(),ep_parse()andep_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 afterep_free(). It covers well-formed techniques (one or two passes, named and unnamed, the_shaderand_programspellings, empty passes and techniques, two commands for one program, multi-line with tabs, thecompilewarning, 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 afterep_free(); the last two commits fix that (below).ep_parse()andep_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 keepsep_parse()from callingep_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()andep_parse_technique()move, as written, fromlibobs/graphics/effect-parser.c.hinto the newlibobs/graphics/effect-parser-passes.c.h.ep_parse()callsep_parse_technique(), so it loses itsstaticand is declared in a new internalgraphics/effect-parser-passes.h(a private adapter, not a new public API;effect-parser.hstays as it is); the pass and command helpers staystatic. The file has its own live unity group,libobs.effect-parser-passes(graphics module), with a precompiled header ofeffect-parser-passes.honly, so the port can later move its include into a ported group.docs/rust-port/naming.mdlists it underobs-graphics.test_effect_parser_blocksand its_rustvariant, which compileeffect-parser.c.hinto themselves, compile the moved file beside it.test: Expect the effect technique name to freeandlibobs: 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 expectsleaked 0in 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 everyda_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
test: Expect the effect technique name to free(77d4364).test_effect_parser_passesfailstechnique_errors,eofandmixed(4 cases differ:leaked 1whereleaked 0is expected). The extraction itself has no RED: the characterization test passes on master's code and after the move, unchanged.libobs: Free effect technique names on all paths(2efedae).test_effect_parser_passespasses 5/5, and built with ASan and UBSan it has no LeakSanitizer report.test_effect_parser_passes,test_effect_parser_blocksand 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_rustvariants) on the hybridlibobsand onlibobs-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_techniqueis local (t) in each. Runs were on 2efedae../unittestran 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 againstlibobs-c-referenceand 718/718 against the hybridlibobs. The local gate could not stamp this head here, so PR CI runs the full suite.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change; the leak fix only lowers the shutdown leak count for malformed effect files)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)