Skip to content

Port hex_string_to_int from C to Rust#2141

Open
Anayo-Anyafulu wants to merge 1 commit intoCCExtractor:masterfrom
Anayo-Anyafulu:hex-string-to-int-clean
Open

Port hex_string_to_int from C to Rust#2141
Anayo-Anyafulu wants to merge 1 commit intoCCExtractor:masterfrom
Anayo-Anyafulu:hex-string-to-int-clean

Conversation

@Anayo-Anyafulu
Copy link

@Anayo-Anyafulu Anayo-Anyafulu commented Feb 25, 2026

[IMPROVEMENT] Port hex_string_to_int from C to Rust

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

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • I have considered, and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  • I give this submission freely, and claim no ownership to its content.
  • I have mentioned this change in the changelog. (not needed — too minor)

My familiarity with the project is as follows (check one):

  • I have never used CCExtractor.
  • I have used CCExtractor just a couple of times.
  • I absolutely love CCExtractor, but have not contributed previously.
  • I am an active contributor to CCExtractor.

Clean port of hex_string_to_int from C to Rust, following the same pattern as #2139.

Changes

  • src/rust/lib_ccxr/src/util/hex.rs — Rust implementation reusing hex_char_to_val
  • src/rust/src/libccxr_exports/util.rs — FFI export with added null check
  • src/lib_ccx/utility.c#ifndef DISABLE_RUST guard added

Note: The Rust version now accepts uppercase hex (A-F), which is an intentional improvement over the original C version that only accepted lowercase (a-f).

Testing

All 48 Rust unit tests passing locally.

@Anayo-Anyafulu
Copy link
Author

The DVB, General, and Options test failures are pre-existing and unrelated to this change. These same categories fail on master. All build checks and format checks are passing

Copy link
Contributor

@cfsmp3 cfsmp3 left a comment

Choose a reason for hiding this comment

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

Thanks for the port — the implementation is correct and tests pass. A few things to fix before merging:

  1. Null check needed: ccxr_hex_string_to_int calls CStr::from_ptr() without checking if the pointer is null first. Please add a null guard.

  2. Squash commits: 7 commits is too many for this change. Please squash into 1-2 meaningful commits.

  3. Unrelated change: There's a blank line removal in utility.c that's not related to this PR. Please revert it.

  4. Uppercase hex: The new Rust version accepts uppercase (A-F) while the C version only accepts lowercase (a-f). This is fine as an improvement, but please mention it in the PR description so it's documented as an intentional behavior change.

Once these are addressed this is ready to merge. Also note: #2139 will be closed in favor of this PR.

@Anayo-Anyafulu
Copy link
Author

@cfsmp3

Thanks for the review! I'll address all four points — adding the null guard, squashing the commits, reverting the unrelated blank line in utility.c, and updating the PR description to document the uppercase hex behavior change. Will push the fixes shortly.

@cfsmp3 cfsmp3 mentioned this pull request Feb 28, 2026
7 tasks
@Anayo-Anyafulu Anayo-Anyafulu force-pushed the hex-string-to-int-clean branch from 079b2e2 to 28c895f Compare March 1, 2026 16:03
@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit c3c5d9c...:
Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 6/7
DVD 3/3
DVR-MS 2/2
General 25/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 80/86
Teletext 21/21
WTV 13/13
XDS 34/34

Your PR breaks these cases:

  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2...
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65...
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b...
  • ccextractor --out=spupng c83f765c66...
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9...

It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you).

Check the result page for more info.

@ccextractor-bot
Copy link
Collaborator

CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit 8de778a...:
Report Name Tests Passed
Broken 13/13
CEA-708 14/14
DVB 7/7
DVD 3/3
DVR-MS 2/2
General 27/27
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 86/86
Teletext 21/21
WTV 13/13
XDS 34/34

Congratulations: Merging this PR would fix the following tests:

  • ccextractor --autoprogram --out=srt --latin1 --quant 0 85271be4d2..., Last passed: Never
  • ccextractor --autoprogram --out=ttxt --latin1 --ucla dab1c1bd65..., Last passed: Never
  • ccextractor --out=srt --latin1 --autoprogram 29e5ffd34b..., Last passed: Never
  • ccextractor --out=spupng c83f765c66..., Last passed: Never
  • ccextractor --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotbefore 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsnotafter 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatleast 1 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never
  • ccextractor --startcreditsforatmost 2 --startcreditstext "CCextractor Start crdit Testing" c4dd893cb9..., Last passed: Never

All tests passed completely.

Check the result page for more info.

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.

3 participants