Skip to content

add Windows platform support#3

Open
trvon wants to merge 2 commits intoLulzx:mainfrom
trvon:windows-support
Open

add Windows platform support#3
trvon wants to merge 2 commits intoLulzx:mainfrom
trvon:windows-support

Conversation

@trvon
Copy link

@trvon trvon commented Jan 6, 2026

I can clean up this pull request, but this enables windows builds based on my testing.

Summary by CodeRabbit

  • New Features
    • Added Windows-aware file handling and a new memory-backed document import for explicitly allocated data.
  • Bug Fixes
    • Ensures correct cleanup of file data across OSes by distinguishing allocated vs. memory-mapped storage.
  • Tests
    • Added a test covering the allocated-memory import and cleanup path.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings January 6, 2026 17:51
@coderabbitai
Copy link

coderabbitai bot commented Jan 6, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Adds OS-specific file handling: Windows uses allocated memory buffers and POSIX uses mmap. Document gains a data_is_allocated flag to record allocation type. File open/creation and close/deallocation paths branch by OS and allocation kind; new openFromMemoryOwnedAlloc path created for allocated buffers.

Changes

Cohort / File(s) Summary
OS-aware file handling & Document memory flags
src/root.zig
Add is_windows constant; add data_is_allocated field to Document; introduce openFromMemoryOwnedAlloc(...); adjust openWithConfig to choose allocated-read (Windows) vs mmap (POSIX); update openFromMemoryOwned initialization flags; change a resolver wrapper cast.
Deallocation & close logic
src/root.zig
Update close() to free via allocator on Windows; on POSIX free when data_is_allocated is true, otherwise munmap() for mmap'd data.
Tests
... (test file path)
Add test exercising the allocated-memory path and cleanup via openFromMemoryOwnedAlloc (Windows-style flow).

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 rgba(240,248,255,0.5)
    Note over FileOpen,POSIX: OS Detection & File Opening
    User->>FileOpen: openWithConfig()
    alt Windows System
        FileOpen->>Windows: read file into allocated buffer
        Windows->>Memory: allocator.alloc()/read
        Memory-->>Windows: allocated buffer
        Windows->>FileOpen: openFromMemoryOwnedAlloc(data_is_allocated = true)
    else POSIX System
        FileOpen->>POSIX: memory-map file
        POSIX->>Memory: mmap()
        Memory-->>POSIX: mapped region
        POSIX->>FileOpen: openFromMemoryOwned(data_is_allocated = false)
    end
    end

    rect rgba(255,240,245,0.5)
    Note over Close,Memory: Deallocation Path
    User->>Close: close()
    alt Windows System
        Close->>Memory: allocator.free(allocated buffer)
    else POSIX System
        alt data_is_allocated == true
            Close->>Memory: allocator.free(allocated buffer)
        else
            Close->>Memory: munmap(mapped region)
        end
    end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I chewed a bit of Zig today,

Alloc'd for Windows, mmap for the bay,
Flags set true or set to false,
Close hops in with tidy waltz,
A rabbit's nod to cross-platform play 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'add Windows platform support' accurately captures the main objective of the PR, which adds OS-aware memory handling and Windows-specific code paths to enable Windows builds.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a 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.

@Lulzx
Copy link
Owner

Lulzx commented Jan 12, 2026

can you take a look at the comments from copilot?

@trvon
Copy link
Author

trvon commented Jan 19, 2026

Working to address now, sorry for the late response

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants