fix(merge): pin classic locale on CSV streams so integers can't get grouped#17
Merged
Conversation
…rouped
Floats are written via fmt (locale-independent), but the integer columns
(qpc_freq header, display_time, thread_id, qpc/gpu values) go through
std::ostream operator<<, which uses the stream's locale. No CSV stream was
ever imbued, so a host that installed a thousands-grouping global locale --
some middleware / Qt launchers do, via std::locale::global(std::locale("")) --
would emit "1,234,567", injecting spurious fields and corrupting both the
per-side and merged CSVs (and the byte-equivalence with analyze.py, whose
Python side is always locale-independent).
Imbue std::locale::classic() on every CSV read/write stream: the FrameCsvSink
/ GpuCsvSink writer, WriteMergedCsv's output, and the two per-row parse
stringstreams in ReadFrameCsv / ReadGpuCsv. analyze.py needs no change
(Python int()/str()/csv don't honor the C locale), so the two paths stay
byte-equivalent.
Adds a test that installs a grouping global locale (portable custom
std::numpunct, RAII-restored so it can't leak into other cases) and asserts
WriteMergedCsv still emits raw integers; it runs in the CI test binary.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Finding #6 (code review): CSV corruption under a non-"C" global locale
Floats are written via
fmt(locale-independent), but the integer columns — the# qpc_freq=header,display_time,thread_id, and the qpc/gpu values — go throughstd::ostream operator<<, which honors the stream's locale. No CSV stream was ever imbued. A host that installs a thousands-grouping global locale (some middleware / Qt launchers do, viastd::locale::global(std::locale(""))) would make us emit1,234,567, injecting spurious fields and corrupting both the per-side and merged CSVs — and breaking byte-equivalence withanalyze.py.Fix
imbue(std::locale::classic())on every CSV read/write stream:FrameCsvSink/GpuCsvSink)layer.cppensureOpenmerge.cppWriteMergedCsvmerge.cppReadFrameCsv/ReadGpuCsvstringstreamsanalyze.pyneeds no change — Python'sint()/str()/csvdon't honor the C locale — so the two paths stay byte-equivalent. (<locale>added topch.h+merge.cpp.)Test
New
test_merge.cppcase installs a grouping global locale (portable customstd::numpunct, RAII-restored so it can't leak into other cases), confirms the locale is active, then assertsWriteMergedCsvstill emits raw integers (1234567,89012,present;1,234,567/89,012absent). It runs in the CI test binary (which CI executes and fails on non-zero exit).Pure additions (+68, no deletions); no lines >120 cols.
🤖 Generated with Claude Code