Skip to content

fix(windows): use _wfopen for non-ASCII project paths#703

Merged
DeusData merged 1 commit into
DeusData:mainfrom
ShauryaaSharma:fix/windows-non-ascii-700
Jul 1, 2026
Merged

fix(windows): use _wfopen for non-ASCII project paths#703
DeusData merged 1 commit into
DeusData:mainfrom
ShauryaaSharma:fix/windows-non-ascii-700

Conversation

@ShauryaaSharma

Copy link
Copy Markdown
Contributor

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_wide helper (win_utf8.h) and delegates to _wfopen.
  • POSIX: plain fopen passthrough, 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

  • 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 real cbm-test-césar\hello.py fixture via Win32 wide-char APIs, confirmed plain fopen returns NULL for that path (bug reproduced), then confirmed cbm_fopen opens 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

Standard fopen on Windows uses the ANSI/system codepage and silently
fails to open files whose absolute path contains non-ASCII characters
(accented, CJK, etc.). This causes the pipeline to skip parsing those
files entirely — File nodes are created by directory traversal (which
already uses wide Win32 APIs) but tree-sitter never receives the source,
so no Function/Class/Method nodes are extracted.

Add cbm_fopen(path, mode) to compat_fs:
- Windows: converts the UTF-8 path to UTF-16LE via cbm_utf8_to_wide
  (existing helper in win_utf8.h) and calls _wfopen.
- POSIX: delegates to fopen (no-op change, paths are already UTF-8).

Replace every fopen call that operates on user project file paths:
- src/pipeline/pass_parallel.c    (primary indexing path)
- src/pipeline/pass_definitions.c
- src/pipeline/pass_calls.c
- src/pipeline/pass_semantic.c
- src/pipeline/pass_usages.c
- src/pipeline/pass_lsp_cross.c
- src/pipeline/pass_pkgmap.c
- src/pipeline/pass_k8s.c
- src/pipeline/pass_envscan.c
- src/pipeline/path_alias.c       (tsconfig detection)
- src/pipeline/artifact.c
- src/discover/language.c         (content-sniff for language detection)
- src/discover/gitignore.c
- src/discover/discover.c
- src/discover/userconfig.c
- src/mcp/mcp.c                   (read_file_lines, adr.md reader)

Fixes DeusData#700

Signed-off-by: ShauryaaSharma <shauryasofficial27@gmail.com>
@ShauryaaSharma ShauryaaSharma force-pushed the fix/windows-non-ascii-700 branch from 24cc5f6 to 98218a2 Compare June 29, 2026 19:33
@DeusData DeusData added bug Something isn't working windows Windows-specific issues parsing/quality Graph extraction bugs, false positives, missing edges priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. labels Jun 29, 2026
@DeusData

DeusData commented Jul 1, 2026

Copy link
Copy Markdown
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working parsing/quality Graph extraction bugs, false positives, missing edges priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. windows Windows-specific issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: File parsing fails silently on Windows when project path contains accented/non-ASCII characters

2 participants