Skip to content

[IMPROVEMENT] Port get_file_extension, get_basename, and create_outfilename to Rust - #2432

Open
Neo-matrix-coder wants to merge 1 commit into
CCExtractor:masterfrom
Neo-matrix-coder:port-output-file-utils
Open

Neo-matrix-coder wants to merge 1 commit into
CCExtractor:masterfrom
Neo-matrix-coder:port-output-file-utils

Conversation

@Neo-matrix-coder

@Neo-matrix-coder Neo-matrix-coder commented Oct 27, 2026 •

Copy link
Copy Markdown

In raising this pull request, I confirm the following (please check boxes):

Reason for this PR:

  • This PR adds new functionality.
  • This PR fixes a bug that I have personally experienced or that a real user has reported and for which a sample exists.
  • This PR is porting code from C to Rust.

Sanity check:

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • If the PR adds new functionality, I've added it to the changelog. If it's just a bug fix, I have NOT added it to the changelog.
  • I am NOT adding new C code unless it's to fix an existing, reproducible bug.

Repro instructions:

This is a pure C-to-Rust port preserving existing behavior (no bug fix sample required). You can verify the port and run all unit tests via:

cargo test --manifest-path src/rust/lib_ccxr/Cargo.toml
cargo test --manifest-path src/rust/Cargo.toml


Summary of Changes

This PR ports get_file_extension, get_basename, and create_outfilename from src/lib_ccx/utility.c to idiomatic Rust in lib_ccxr and exposes C-FFI bindings in ccx_rust, following the 5-step workflow in docs/Rust_migration_guide.md:

  1. Idiomatic Rust (src/rust/lib_ccxr):
    • Added #[repr(u32)] and FromRepr to OutputFormat in src/rust/lib_ccxr/src/common/constants.rs and implemented OutputFormat::extension(&self) -> Option<&'static str>.
    • Implemented get_basename (preserving directory prefixes while stripping the final extension after the last path separator) and create_outfilename in src/rust/lib_ccxr/src/util/mod.rs.
    • Updated the C-to-Rust conversion tables in module documentation.
  2. C-FFI Layer (src/rust/src/libccxr_exports/util.rs):
    • Implemented ccxr_get_file_extension returning pointers from static null-terminated C-string literals (c"...").
    • Implemented ccxr_get_basename and ccxr_create_outfilename with # Safety documentation, null-pointer handling, and valid heap allocation for empty results.
  3. C Integration (src/lib_ccx/utility.c):
    • Connected get_file_extension, get_basename, and create_outfilename to their ccxr_* equivalents inside #ifndef DISABLE_RUST blocks (prototypes declared alongside each wrapper), preserving the original C fallback under #else.
  4. Testing:
    • Added unit tests in lib_ccxr and libccxr_exports covering all 17 OutputFormat variants, invalid discriminants, relative/absolute/Windows paths, compound extensions, hidden files, empty strings, and null pointers.

@Neo-matrix-coder
Neo-matrix-coder force-pushed the port-output-file-utils branch 4 times, most recently from 2a6a32e to 024dbd4 Compare October 27, 2026 19:37
@Neo-matrix-coder

Copy link
Copy Markdown
Author

CI note: the 7 Linux jobs fail at Install dependencies (libgpac-dev has no installation candidate on the runner), before this PR's code is checked out. The Format sourcecode / format job reports clang-format diffs only in ccx_decoders_isdb.c and mp4.c, which this PR doesn't modify. Rust fmt/clippy, test_rust, and the macOS, Docker and Windows builds pass. The same failures show up on other open PRs (e.g. #2436, #2435).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant