Skip to content

Replace strtok with thread-safe strtok_r in MPS parser#1088

Merged
rapids-bot[bot] merged 2 commits intoNVIDIA:mainfrom
rgsl888prabhu:fix/strtok-thread-safety-mps-parser
Apr 9, 2026
Merged

Replace strtok with thread-safe strtok_r in MPS parser#1088
rapids-bot[bot] merged 2 commits intoNVIDIA:mainfrom
rgsl888prabhu:fix/strtok-thread-safety-mps-parser

Conversation

@rgsl888prabhu
Copy link
Copy Markdown
Collaborator

Summary

Replace strtok() with strtok_r() in parse_string() to make MPS file parsing thread-safe. strtok uses internal static state, so concurrent parsing from multiple threads corrupts tokenization.

Testing

No new tests added. Existing MPS parser tests cover this code path.

Documentation

No documentation changes needed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rgsl888prabhu rgsl888prabhu requested a review from a team as a code owner April 9, 2026 16:26
@rgsl888prabhu rgsl888prabhu requested review from kaatish and mlubin April 9, 2026 16:26
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 45e1fe4d-77bc-47d9-97df-f3b0dc31e682

📥 Commits

Reviewing files that changed from the base of the PR and between 378add0 and e1b919b.

📒 Files selected for processing (1)
  • cpp/libmps_parser/src/mps_parser.cpp

📝 Walkthrough

Walkthrough

Replaced the non-reentrant strtok function with the reentrant strtok_r function in the parse_string method of the MPS parser. A saveptr context pointer is initialized to track tokenization state across newline-delimited line iterations.

Changes

Cohort / File(s) Summary
Strtok Reentrancy Fix
cpp/libmps_parser/src/mps_parser.cpp
Replaced strtok with strtok_r to improve thread safety. Added saveptr context pointer for managing tokenization state in the parse_string method.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: replacing strtok with thread-safe strtok_r in the MPS parser, which aligns with the primary objective of the pull request.
Description check ✅ Passed The description is directly related to the changeset, explaining the rationale for replacing strtok with strtok_r and addressing thread-safety concerns in MPS file parsing.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@rgsl888prabhu rgsl888prabhu self-assigned this Apr 9, 2026
@rgsl888prabhu rgsl888prabhu added non-breaking Introduces a non-breaking change improvement Improves an existing functionality labels Apr 9, 2026
@rgsl888prabhu
Copy link
Copy Markdown
Collaborator Author

/merge

@rapids-bot rapids-bot bot merged commit f5842df into NVIDIA:main Apr 9, 2026
108 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improves an existing functionality non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants