Repository navigation
libobs: Move the effect parser blocks to own file - #3561
Conversation
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.
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.
|
The asan failure here comes from the PR's own test, so a rerun will not clear it. Two ways through:
|
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.
|
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.
On 0224c6f, |
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 newtest_effect_parser_blocks(cmocka) callsep_init(),ep_parse()andep_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 afterep_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 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 blocks to own file:ep_parse_struct_var(),ep_parse_struct(),ep_parse_sampler_state_item()andep_parse_sampler_state()move, as written, fromlibobs/graphics/effect-parser.c.hinto the newlibobs/graphics/effect-parser-blocks.c.h. The two thatep_parse()calls lose theirstaticand are declared in a new internalgraphics/effect-parser-blocks.h(a private adapter, not a new public API;effect-parser.hstays as it is); the item and variable helpers staystatic. The file has its own live unity group,libobs.effect-parser-blocks(graphics module), with a precompiled header ofeffect-parser-blocks.honly, so the port can later move its include into a ported group.docs/rust-port/naming.mdlists it underobs-graphics. Two follow-up commits sort the new group intomodules.d/graphics.jsonandLIBOBS_SOURCES.json.test: Expect the effect sampler items to freeandlibobs: 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 expectsleaked 0in 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 everyda_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
test: Expect the effect sampler items to free(a246568).test_effect_parser_blocksfailssampler_errors,sampler_eofandmixed(6 cases differ:leaked 1orleaked 2whereleaked 0is expected). The extraction itself has no RED: the characterization test passes on master's code and after the move, unchanged.libobs: Free the effect sampler item on all paths(0224c6f).test_effect_parser_blockspasses 7/7, and under ASan and UBSan with leak detection on it has no LeakSanitizer report.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_parser_blocks,test_shader_number_defaults) pass 12/12 on the C build and 14/14 (with_rustvariants) on the hybridlibobsand onlibobs-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_structandep_parse_sampler_stateare local (t) in each.--test-diff: 6366 Rust tests passed. The tests above and the export comparison ran on 0224c6f;./unittestran on a4e52e8 (the same code, one source-list line earlier) and passed (6366 and 912 Rust tests; Tier 2 712/712 againstlibobs-c-referenceand 712/712 against the hybridlibobs).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)