fix(windows): use _wfopen for non-ASCII project paths
Fixes #700
What does this PR do?
On Windows, fopen uses the ANSI/system codepage and silently returns NULL when the file path contains non-ASCII characters (accented letters, CJK, etc.). The indexer's directory traversal already uses wide Win32 APIs (FindFirstFileW), so File nodes are created correctly, but the subsequent file-read/parse phase calls fopen with the UTF-8 path, which
fails silently. tree-sitter never receives the source, so no Function/Class/Method nodes are extracted for any file whose
absolute path contains a non-ASCII character.
Add cbm_fopen(path, mode) to compat_fs:
- Windows: converts the UTF-8 path to UTF-16LE via the existing
cbm_utf8_to_widehelper (win_utf8.h) and delegates to_wfopen. - POSIX: plain
fopenpassthrough, no behaviour change.
Replace every fopen call that receives a user project file path:
pass_parallel, pass_definitions, pass_calls, pass_semantic,
pass_usages, pass_lsp_cross, pass_pkgmap, pass_k8s,
pass_envscan, path_alias (×2), artifact, discover/language,
discover/gitignore, discover/discover, discover/userconfig,
mcp/mcp.c (read_file_lines and adr.md reader), 18 call sites
across 17 files.
Checklist
- [x] Every commit is signed off (
git commit -s) : required, CI rejects unsigned commits. - [ ] Tests pass locally (
make -f Makefile.cbm test) : full suite requires ASan + 64-bit toolchain unavailable in this environment; the fix was verified with a targeted harness: created a realcbm-test-césar\hello.pyfixture via Win32 wide-char APIs, confirmed plainfopenreturnsNULLfor that path (bug reproduced), then confirmedcbm_fopenopens and reads it correctly. 7 cases including NULL path, missing file, write+round-trip, and non-ASCII in both directory and filename, all passing. - [ ] Lint passes (
make -f Makefile.cbm lint-ci) : clang-tidy unavailable in this environment; please run in CI - [ ] New behavior is covered by a test (reproduce-first for bug fixes) : no test added to
tests/; the affected code paths are Windows-only and not currently covered by the test suite
Huge thanks for opening this PR and for the work you put into it.
The maintainer shop is currently full, so this may sit for a bit before it gets a proper review. We will come back to this as soon as possible with real feedback; I wanted to make sure it did not sit unacknowledged in the meantime.