Skip to content

util: Move os_generate_formatted_filename into platform-filename.c - #1510

Merged
zackees merged 1 commit into
obs-rust:masterfrom
rdoupe:refactor/platform-filename-move
Oct 20, 2026
Merged

zackees merged 1 commit into
obs-rust:masterfrom
rdoupe:refactor/platform-filename-move

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Refs #262 (slice 5, filenames).

What and why

Behavior-neutral extraction before the Rust port, as the testing policy asks for a partial-file port: os_generate_formatted_filename and its statics valid_string, replace_text and erase_ch move verbatim from libobs/util/platform.c.h into libobs/util/platform-filename.c.h. No Rust, no signature, header or behavior change.

  • Build: the new file joins the existing libobs.platform unity group and libobs-platform.pch.h.
  • Oracle: rust/obs-c-oracle/oracle/platform.c includes it too (os_generate_formatted_filename was already renamed oracle_os_generate_formatted_filename there), so the oracle still runs the real C. The obs_get_video_info stub's comment in platform_host.c points at the new file.
  • Test build: test_formatted_filename compiles the C into the test so its fixtures replace libobs's. It now compiles platform-filename.c instead of platform.c and utf8.c, which the moved code does not need (CMake and the Cargo C-test manifest).
  • Ifdef ratchet: the moved code has no host conditionals, only the __GNUC__/__clang__ pragma guard.

test_formatted_filename goes from 5 cases to 17 and becomes a full characterization. Nothing depends on the clock, time zone or locale: the test's time() replaces libc's for the compiled-in file and returns a fixed instant, the group setup sets TZ=OBS-5:30 (UTC+05:30, so local and UTC dates and hours differ) and the C locale, and the obs_get_video_info fixture is now set per case and counts its calls. The 5 existing cases are unchanged. New cases:

  • every date and time specifier on its own: %CCYY %YY %MM %DD %hh %mm %ss and the strftime ones %a %A %b %B %d %H %I %m %M %p %S %y %Y %z %Z, all in local time;
  • %s (Unix time), which is not in the specifier table;
  • %FPS, %CRES, %ORES, %VF; %FPS with integer, NTSC and odd rates, fps_den 0, and UINT32_MAX; %VF names;
  • how the video info is read: once per call, before the format is looked at, even for a format with no video specifier;
  • table order and longest match (%YYY is 25Y, %sss is 03s, %FPSS is 30S), case sensitivity, and an expansion is never scanned again (%%CCYY is %CCYY);
  • %%, a trailing %, and unknown specifiers, strftime ones outside the table included (%q, %e, %c, %T, %F, %CRE, a % before a multibyte character): the % is dropped and the rest kept;
  • spaces: kept, or all of them turned into underscores, replacements included; the extension keeps its spaces, tabs are kept;
  • the extension: empty and NULL add no dot, a leading dot is kept, specifiers in it are not expanded;
  • an empty or NULL format, or one that expands to nothing, returns NULL (.mkv with an extension);
  • the 255-byte limit applies after expansion and cuts into the extension.

Two cases are characterized, not endorsed:

localtime() is not thread-safe (noted on #262). This PR only pins behavior; the port can use localtime_r as a recorded intentional difference.

RED → GREEN

  • No RED commit: this is a move plus a characterization test, which passes on the moved code. The move is byte-for-byte (platform.c.h before = platform.c.h after + platform-filename.c.h minus its license and include). The test also passes against the v0.1.0-beta.20261018 release's libobs.so.30, both the C one and the obs-studio-rust/ one.
  • Local, two build trees (ENABLE_RUST_LIBOBS=OFF and ON). Each runs the cmocka tests against libobs and against libobs-with-rust:
Lane libobs libobs-with-rust Exported symbols
C (ENABLE_RUST_LIBOBS=OFF) 322/322 322/322 IDENTICAL (1766)
Rust (ENABLE_RUST_LIBOBS=ON) 322/322 322/322 IDENTICAL (1766)

7 frontend tests (test_config_migration_*, test_virtual_cam_shutdown) were not built in these trees: I built only the cmocka-tests, libobs and libobs-with-rust targets. Nothing was skipped.

  • test_formatted_filename: 17/17 in all four, 20 repeated runs in each mode, and with TZ/LC_ALL set to other zones and locales in the environment.
  • test_formatted_filename compiles the C into the test, so it characterizes the C source only, as the testing policy says for this test; it cannot exercise the Rust swap.
  • ./lint (ci/local_gate.py --lane lint): passed (42 s)
  • Real app: not applicable (no behavior change).

Windows/macOS: PR CI scopes this Linux-only. test_formatted_filename is not built under MSVC. macOS builds it, but this PR's paths don't select the macOS lane; the port PR touches rust/obs-util/src/platform/, so its CI runs the macOS Tier 2 lane with this test there.

Checklist

  • Base is master
  • 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
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): not applicable
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): not applicable (no port here)

Behavior-neutral extraction before the Rust port:
os_generate_formatted_filename and its statics valid_string, replace_text
and erase_ch move verbatim from libobs/util/platform.c.h into
libobs/util/platform-filename.c.h, in the same libobs.platform unity
group and precompiled header. The oracle compiles both files.
test_formatted_filename now compiles platform-filename.c instead of
platform.c and utf8.c, which the moved code does not need. No host
conditionals move.

test_formatted_filename becomes a full characterization. A fixed clock
(the test's time() replaces libc's for the compiled-in file), a fixed TZ
(UTC+05:30) and the C locale make every case exact, and the
obs_get_video_info fixture becomes configurable and counts its calls.
New cases: every date and time specifier, %s, %FPS (integer and
fractional rates), %CRES, %ORES, %VF, table order and longest match,
%% and unknown specifiers, space replacement, the extension, an empty or
NULL format, and the 255-byte limit after expansion and on the
extension. Characterized, not endorsed: %FPS keeps two decimals for a
whole rate when fps_den > 1 (50/2 is "25.00"), and the result of
obs_get_video_info is not checked, so with no video the fields are used
as the call left them.

Refs obs-rust#262
@rdoupe
rdoupe requested a review from zackees as a code owner October 20, 2026 08:04
@zackees
zackees enabled auto-merge October 20, 2026 08:12

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinator review: behaviour-neutral move. test_formatted_filename.c is edited, but all five existing cases stay registered with their assertions unchanged; the edits are the fixture (now compiling platform-filename.c) and new characterization cases. Auto-merge on.

@zackees
zackees added this pull request to the merge queue Oct 20, 2026
Merged via the queue into obs-rust:master with commit a174b2b Oct 20, 2026
25 checks passed
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