-
Notifications
You must be signed in to change notification settings - Fork 29
add Windows platform support #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,8 +11,10 @@ | |||||
|
|
||||||
| const std = @import("std"); | ||||||
| const builtin = @import("builtin"); | ||||||
| const native_os = builtin.os.tag; | ||||||
|
|
||||||
| const is_wasm = builtin.cpu.arch == .wasm32 or builtin.cpu.arch == .wasm64; | ||||||
| const is_windows = native_os == .windows; | ||||||
|
|
||||||
| // Internal modules | ||||||
| pub const parser = @import("parser.zig"); | ||||||
|
|
@@ -95,8 +97,10 @@ pub const ParseError = struct { | |||||
| pub const Document = struct { | ||||||
| /// Memory-mapped file data (zero-copy base) | ||||||
| data: []const u8, | ||||||
| /// Whether we own the data (mmap'd) | ||||||
| /// Whether we own the data (mmap'd or allocated) | ||||||
| owns_data: bool, | ||||||
| /// Whether data was allocated (Windows) vs mmap'd (POSIX) | ||||||
| data_is_allocated: bool = false, | ||||||
|
|
||||||
| /// Cross-reference table | ||||||
| xref_table: XRefTable, | ||||||
|
|
@@ -147,20 +151,30 @@ pub const Document = struct { | |||||
| const stat = try file.stat(); | ||||||
| const size = stat.size; | ||||||
|
|
||||||
| // Memory map the file | ||||||
| const data = try std.posix.mmap( | ||||||
| null, | ||||||
| size, | ||||||
| std.posix.PROT.READ, | ||||||
| .{ .TYPE = .PRIVATE }, | ||||||
| file.handle, | ||||||
| 0, | ||||||
| ); | ||||||
|
|
||||||
| return openFromMemoryOwned(allocator, data, config); | ||||||
| if (comptime is_windows) { | ||||||
| // Windows: read file into allocated memory (no mmap support) | ||||||
| const data = try allocator.alignedAlloc(u8, .fromByteUnits(std.heap.page_size_min), size); | ||||||
|
||||||
| const data = try allocator.alignedAlloc(u8, .fromByteUnits(std.heap.page_size_min), size); | |
| const data = try allocator.alignedAlloc(u8, std.heap.page_size_min, size); |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new Windows-specific file loading path (lines 154-162) lacks test coverage. The repository has comprehensive test suites (integration_test.zig, etc.), but there are no tests validating that Windows file loading and cleanup work correctly. Consider adding platform-specific tests or conditional tests that exercise this path when compiling for Windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new data_is_allocated field has a default value of false, but this field is not initialized in the openFromMemory method (around line 234-246). While the default will apply, it would be clearer and more consistent with the other initialization blocks to explicitly set this field to false, especially since owns_data is already being set to false.