fix: use _wfopen on Windows to support non-ASCII (CJK/U...) file paths#637
Open
maxniu1 wants to merge 1 commit into
Open
fix: use _wfopen on Windows to support non-ASCII (CJK/U...) file paths#637maxniu1 wants to merge 1 commit into
maxniu1 wants to merge 1 commit into
Conversation
On Windows, fopen() uses the active ANSI codepage (e.g. GBK on zh-CN, Shift-JIS on ja-JP, CP1251 on ru-RU) rather than UTF-8. When a repository path contains non-ASCII characters — Chinese, Japanese, Korean, Cyrillic, Arabic, accented Latin (é, ü, ñ), etc. — every file's tree-sitter definitions pass fails (defs=0, errors=N for all files), producing a knowledge graph with only File/Folder nodes and zero code intelligence. The codebase already has the infrastructure for UTF-8→wide conversion (win_utf8.h: cbm_utf8_to_wide/cbm_wide_to_utf8) and uses it correctly for directory enumeration (FindFirstFileW), mkdir (_wmkdir), and unlink (_wunlink). But fopen() for reading file content was missed. Fix: - Add cbm_fopen() to compat_fs.h / compat_fs.c - Windows: uses _wfopen() with wide-char path - POSIX: delegates to fopen() - Replace fopen(path, "rb") with cbm_fopen(path, "rb") in the 3 pipeline files that read source files for tree-sitter parsing: pass_parallel.c, pass_calls.c, pass_definitions.c Fixes DeusData#636
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.
Summary
On Windows,
fopen()uses the active ANSI codepage (e.g. GBK on zh-CN, Shift-JIS on ja-JP, CP1251 on ru-RU) rather than UTF-8. When a repository path contains characters outside ASCII-7 — any non-English language: Chinese, Japanese, Korean, Cyrillic, Arabic, accented Latin (é/ü/ñ), Thai, Hebrew, Devanagari, etc. — every file's tree-sitter definitions pass fails (defs=0,errors=Nfor all files). The resulting knowledge graph contains only File/Folder nodes with zero code intelligence.The existing directory-enumeration code in
compat_fs.calready handles this correctly viaFindFirstFileW/_wmkdir/_wunlinkwith wide-character paths. This PR applies the same pattern to file reading for tree-sitter parsing.Changes
src/foundation/compat_fs.hcbm_fopen()src/foundation/compat_fs.ccbm_fopen():_wfopenon Windows,fopenon POSIXsrc/pipeline/pass_parallel.cfopen→cbm_fopensrc/pipeline/pass_calls.cfopen→cbm_fopensrc/pipeline/pass_definitions.cfopen→cbm_fopenAll three pipeline files had a duplicated
read_file()static function. Each now callscbm_fopen()instead of rawfopen().Testing
Before (v0.8.1)
After (this PR)
Tested on a 41-file TypeScript/JS/Python/CSS project with CJK directory names (
F:/.../智能体/智能体原型/). Full index: 245 nodes, 347 edges, 197ms.Related