-
Notifications
You must be signed in to change notification settings - Fork 26
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?
Conversation
📝 WalkthroughWalkthroughThe changes introduce OS-specific file handling to support both Windows and POSIX systems. A new Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant FileOpen as File Opening Logic
participant Windows as Windows Path
participant POSIX as POSIX Path
participant Memory as Memory Management
participant Close as Close/Deallocation
rect rgb(240, 248, 255)
Note over Windows,POSIX: OS Detection & File Opening
User->>FileOpen: openWithConfig()
alt Windows System
FileOpen->>Windows: Allocate memory buffer
Windows->>Memory: allocator.alloc()
Memory-->>Windows: Allocated memory
Windows->>FileOpen: openFromMemoryOwnedAlloc()
FileOpen->>FileOpen: Set data_is_allocated = true
else POSIX System
FileOpen->>POSIX: Memory map file
POSIX->>Memory: mmap()
Memory-->>POSIX: Mapped memory
FileOpen->>FileOpen: Set data_is_allocated = false
end
end
rect rgb(255, 240, 245)
Note over Windows,POSIX: Deallocation Path
User->>Close: close()
alt Windows System
Close->>Memory: allocator.free()
else POSIX System
alt data_is_allocated
Close->>Memory: allocator.free()
else mmap'd data
Close->>Memory: munmap()
end
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
Pre-merge checks✅ Passed checks (3 passed)
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (6)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Pull request overview
This PR adds Windows platform support to the ZPDF library by implementing an alternative file loading mechanism. Since Windows doesn't support POSIX mmap, the PR uses allocated memory with readAll for Windows while maintaining mmap for POSIX systems.
- Adds platform detection for Windows and conditional compilation paths
- Implements allocated memory approach for Windows file loading instead of mmap
- Updates cleanup logic to handle both mmap'd and allocated memory
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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); |
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 alignment parameter syntax appears incorrect. In Zig's alignedAlloc function, the second parameter should be a compile-time known alignment value (like std.mem.page_size), not an alignment enum. The correct syntax should be std.heap.page_size_min directly as the second parameter, not wrapped in .fromByteUnits(). This will likely cause a compilation error.
| 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); |
| // POSIX: check if allocated or mmap'd | ||
| if (self.data_is_allocated) { | ||
| self.allocator.free(aligned_ptr[0..self.data.len]); | ||
| } else { | ||
| std.posix.munmap(aligned_ptr[0..self.data.len]); | ||
| } |
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 cleanup logic has a potential bug. On non-Windows POSIX systems, if data_is_allocated is true, the code will call allocator.free(), but this field is only set to true in openFromMemoryOwnedAlloc which is Windows-only (lines 162, 206-226). This means the POSIX path at line 402-403 can never be taken. Either remove this unreachable code or document why POSIX might need allocated memory in the future.
| /// 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, |
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 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.
| 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); | ||
| errdefer allocator.free(data); | ||
| const bytes_read = try file.readAll(data); | ||
| if (bytes_read != size) { | ||
| return error.UnexpectedEof; | ||
| } | ||
| return openFromMemoryOwnedAlloc(allocator, data, config); |
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.
|
can you take a look at the comments from copilot? |
I can clean up this pull request, but this enables windows builds based on my testing.
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.