[PR #4011] [CLOSED] [Benchmark] tools/strata_bench.py: read CMakeLists.txt as UTF-8, not the locale's code page (fixes #2792) #4875

Closed
opened 2026-11-07 16:31:01 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4011
Author: @SuperDistance
Created: 10/24/2026
Status: ❌ Closed

Base: main ← Head: pr/bench-utf8


📝 Commits (2)

  • ae5aa79 tools/strata_bench.py: read CMakeLists.txt as UTF-8, not with the locale's code page (#2792)
  • ffa5ac5 tools/strata_bench.py: name no locale; the test reads the version under every Windows ANSI code page

📊 Changes

2 files changed (+20 additions, -1 deletions)

View changed files

📝 tools/strata_bench.py (+2 -1)
📝 tools/test_strata_bench.py (+18 -0)

📄 Description

Problem and result

tools/strata_bench.py (BENCH.bat, ./bench.sh) reads CMakeLists.txt with Path.read_text() and no encoding. On Windows, Python then decodes the file with the locale's code page instead of UTF-8. CMakeLists.txt is UTF-8 and has non-ASCII text (line 3), so on many Windows locales the benchmark stops with a UnicodeDecodeError before it measures anything. On this PC (Windows 11, code page 936) the 0.2.4.1 tool stopped with 'gbk' codec can't decode byte 0xa7 in position 74. With this change the file is read as UTF-8 whatever the locale, and the tool runs.

How main 7dd5cf18's CMakeLists.txt reads under each Windows ANSI code page (its bytes decoded with Python 3.12):

  • UnicodeDecodeError: cp874, cp936, cp949, cp950, cp1253, cp1255, cp1257, cp1258.
  • Decodes, with garbled characters only in a comment: cp932, cp1250, cp1251, cp1252, cp1254, cp1256.

Linux and macOS default to UTF-8 and are not affected.

Fixes #2792 (Lithivm, closed in the 0.2.0 tracker reset; the bug is still in main 7dd5cf18). This is the fix suggested there, and the same read setup.py already does: (ROOT / "CMakeLists.txt").read_text(encoding="utf-8").

Approach

  • project_version() passes encoding="utf-8". The file's other reads already pass an encoding; the two without one read /proc/meminfo and /proc/cpuinfo on Linux.
  • tools/test_strata_bench.py: a test that makes Path.read_text default to each of the 14 Windows ANSI code pages in turn. It writes a CMakeLists.txt with non-ASCII text and expects the version back under every one.

Validation

Passed:

  • python tools/test_strata_bench.py on main 7dd5cf18 + this PR (ffa5ac5e), Windows 11, Python 3.12.14: 18 tests OK.
  • The new test against main's strata_bench.py fails under 5 of the 14 code pages (cp874, cp932, cp936, cp949, cp950), each with a UnicodeDecodeError. Its sample text differs from the real file's line 3, so the code pages that fail differ from the list above.
  • The real case, on this PC's own code page (cp936) without PYTHONUTF8: project_version() returns 0.1.49.2 with this change, and raises UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 74 with main's file. Earlier, with PYTHONUTF8=1 (the workaround from #2792), the 0.2.4.1 tool ran to the end against a local server on 2x RTX 5090.

Failed: none observed.

Not run: Windows set to the other code pages (they were checked only by decoding the file, as above); a full benchmark run with this change (only project_version() touches the file).

Limits

None known. Only the version string read changes.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4011 **Author:** [@SuperDistance](https://github.com/SuperDistance) **Created:** 10/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/bench-utf8` --- ### 📝 Commits (2) - [`ae5aa79`](https://github.com/Niko1221/Strata/commit/ae5aa79bdeb2335cc850dadddc79d399f75f74bc) tools/strata_bench.py: read CMakeLists.txt as UTF-8, not with the locale's code page (#2792) - [`ffa5ac5`](https://github.com/Niko1221/Strata/commit/ffa5ac5e201e340fb6cfeaa8d3c0faaf76290c50) tools/strata_bench.py: name no locale; the test reads the version under every Windows ANSI code page ### 📊 Changes **2 files changed** (+20 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `tools/strata_bench.py` (+2 -1) 📝 `tools/test_strata_bench.py` (+18 -0) </details> ### 📄 Description ## Problem and result `tools/strata_bench.py` (`BENCH.bat`, `./bench.sh`) reads `CMakeLists.txt` with `Path.read_text()` and no encoding. On Windows, Python then decodes the file with the locale's code page instead of UTF-8. `CMakeLists.txt` is UTF-8 and has non-ASCII text (line 3), so on many Windows locales the benchmark stops with a `UnicodeDecodeError` before it measures anything. On this PC (Windows 11, code page 936) the 0.2.4.1 tool stopped with `'gbk' codec can't decode byte 0xa7 in position 74`. With this change the file is read as UTF-8 whatever the locale, and the tool runs. How main 7dd5cf18's `CMakeLists.txt` reads under each Windows ANSI code page (its bytes decoded with Python 3.12): - `UnicodeDecodeError`: cp874, cp936, cp949, cp950, cp1253, cp1255, cp1257, cp1258. - Decodes, with garbled characters only in a comment: cp932, cp1250, cp1251, cp1252, cp1254, cp1256. Linux and macOS default to UTF-8 and are not affected. ## Related discussion Fixes #2792 (Lithivm, closed in the 0.2.0 tracker reset; the bug is still in main 7dd5cf18). This is the fix suggested there, and the same read `setup.py` already does: `(ROOT / "CMakeLists.txt").read_text(encoding="utf-8")`. ## Approach - `project_version()` passes `encoding="utf-8"`. The file's other reads already pass an encoding; the two without one read `/proc/meminfo` and `/proc/cpuinfo` on Linux. - `tools/test_strata_bench.py`: a test that makes `Path.read_text` default to each of the 14 Windows ANSI code pages in turn. It writes a `CMakeLists.txt` with non-ASCII text and expects the version back under every one. ## Validation **Passed:** - `python tools/test_strata_bench.py` on main 7dd5cf18 + this PR (ffa5ac5e), Windows 11, Python 3.12.14: 18 tests OK. - The new test against main's `strata_bench.py` fails under 5 of the 14 code pages (cp874, cp932, cp936, cp949, cp950), each with a `UnicodeDecodeError`. Its sample text differs from the real file's line 3, so the code pages that fail differ from the list above. - The real case, on this PC's own code page (cp936) without `PYTHONUTF8`: `project_version()` returns `0.1.49.2` with this change, and raises `UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 74` with main's file. Earlier, with `PYTHONUTF8=1` (the workaround from #2792), the 0.2.4.1 tool ran to the end against a local server on 2x RTX 5090. **Failed:** none observed. **Not run:** Windows set to the other code pages (they were checked only by decoding the file, as above); a full benchmark run with this change (only `project_version()` touches the file). ## Limits None known. Only the version string read changes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:31:01 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4875
No description provided.