Skip to content

Support Windows storage I/O primitives#16

Merged
loreste merged 1 commit into
loreste:mainfrom
attahn:feat/windows-direct-io
Jul 22, 2026
Merged

Support Windows storage I/O primitives#16
loreste merged 1 commit into
loreste:mainfrom
attahn:feat/windows-direct-io

Conversation

@attahn

@attahn attahn commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Adds native Windows support for descriptor I/O, memory maps, and WAL-backed storage primitives. Unbuffered reads and writes use aligned buffers so ordinary Mako strings work while retaining the operating system's size and offset requirements.

Tests: cargo test --bin mako; storage_portable_io_test; windows_direct_io_test.

Upstream main currently has a Windows task-result CI regression covered by #14; any matching crew_fan failure is unrelated to this change.

Summary by CodeRabbit

  • New Features

    • Added Windows support for direct file I/O, memory-mapped files, file allocation, and write-ahead logs.
    • Enabled storage transactions with WAL logging across platforms.
    • Improved unbuffered read/write alignment handling.
  • Bug Fixes

    • Read-only memory maps now reject writes safely instead of faulting.
    • Added validation for memory-map and page read/write boundaries.
  • Documentation

    • Updated runtime, Direct I/O, memory-map, and storage documentation.
    • Clarified that only the HTTP engine remains POSIX-only.
  • Tests

    • Added portable storage and Windows I/O integration coverage.

@attahn

attahn commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai[bot] review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

@attahn: I’ll review the changes.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cad676db-5203-448c-9260-d26af424115b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The runtime adds Windows direct I/O, memory mapping, and WAL support, strengthens mapping and page validation, adds portable and Windows integration tests, wires them into CI, and updates documentation and release notes.

Changes

Cross-platform storage I/O

Layer / File(s) Summary
Windows direct I/O primitives
runtime/mako_dio.h
Windows file, direct I/O, and memory-mapped operations now use functional runtime implementations.
Memory-map and page validation
runtime/mako_dio.h
Mapping writability and bounds checks are enforced, with stricter page read/write validation.
Portable WAL and store commits
runtime/mako_dio.h
WAL append, sync, sizing, random-access reads, and close operations use shared file primitives; store commits log attached WAL transactions on all platforms.
Integration coverage and documentation
examples/testing/*, examples/ci/*, .github/workflows/ci.yml, docs/*, README.md, CHANGELOG.md
Portable and Windows storage tests are added to CI, and runtime capability and API documentation is updated.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant StorageTest
  participant MakoRuntime
  participant StorageFile
  StorageTest->>MakoRuntime: open and write storage data
  MakoRuntime->>StorageFile: perform direct I/O
  StorageFile-->>MakoRuntime: return operation status
  MakoRuntime-->>StorageTest: return read/write results
Loading

Suggested reviewers: loreste

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.95% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding native Windows support for storage I/O primitives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@runtime/mako_dio.h`:
- Around line 273-293: Update mako_file_read_exact so it returns an empty string
whenever the read loop completes with total less than count, freeing the
allocated buffer first; only null-terminate and return the buffer after exactly
count bytes have been read, preserving the existing handling for invalid inputs,
allocation failure, and read errors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 80c2381d-cfcb-4a3d-b959-02d56c9659bf

📥 Commits

Reviewing files that changed from the base of the PR and between ba73948 and 600266f.

📒 Files selected for processing (8)
  • .github/workflows/ci.yml
  • CHANGELOG.md
  • README.md
  • docs/BUILTINS.md
  • docs/STDLIB.md
  • examples/ci/windows_direct_io_test.mko
  • examples/testing/storage_portable_io_test.mko
  • runtime/mako_dio.h

Comment thread runtime/mako_dio.h
Comment on lines +273 to +293
static inline MakoString mako_file_read_exact(int64_t fd, int64_t count) {
if (fd < 0 || fd > INT_MAX || count <= 0 || (uint64_t)count >= (uint64_t)SIZE_MAX) {
return mako_str_from_cstr("");
}
char *buf = (char *)malloc((size_t)count + 1);
if (!buf) return mako_str_from_cstr("");
size_t total = 0;
while (total < (size_t)count) {
size_t remaining = (size_t)count - total;
unsigned int chunk = remaining > 0x7ffff000U ? 0x7ffff000U : (unsigned int)remaining;
int got = _read((int)fd, buf + total, chunk);
if (got <= 0) break;
total += (size_t)got;
}
if (total == 0) {
free(buf);
return mako_str_from_cstr("");
}
buf[total] = 0;
return (MakoString){buf, total};
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Compare with the POSIX implementation and inspect callers' expectations.
rg -nP -C3 '\bmako_file_read_exact\b'

Repository: loreste/mako

Length of output: 150


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map the target file and nearby symbols first.
ast-grep outline runtime/mako_dio.h --view expanded || true

printf '\n--- file slice ---\n'
sed -n '240,330p' runtime/mako_dio.h

printf '\n--- related reads/searches ---\n'
rg -n -C 3 'mako_file_read_exact|_read\(|read_exact|short-read|EOF' runtime . || true

Repository: loreste/mako

Length of output: 50369


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the header around the function and search for any call sites or docs.
sed -n '1,240p' runtime/mako_dio.h
printf '\n--- targeted search ---\n'
grep -RIn --exclude-dir=.git --exclude='*.min.*' -E '\bmako_file_read_exact\b|read_exact|exact bytes|short read' .

Repository: loreste/mako

Length of output: 10403


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the POSIX implementation of mako_file_read_exact and nearby comments.
sed -n '760,815p' runtime/mako_dio.h

printf '\n--- docs contract ---\n'
sed -n '200,220p' docs/STDLIB.md
printf '\n--- builtin docs ---\n'
sed -n '310,330p' docs/BUILTINS.md
printf '\n--- example usage ---\n'
sed -n '1,40p' examples/testing/storage_portable_io_test.mko

printf '\n--- codegen call site ---\n'
sed -n '15090,15115p' src/codegen/mod.rs

Repository: loreste/mako

Length of output: 7226


file_read_exact returns partial data on EOF/short reads
This helper returns a non-empty truncated buffer when _read stops early, so it does not actually guarantee count bytes. That contradicts the “exact” contract and can let callers continue on incomplete data; return empty/error on short reads, or rename/document it as best-effort.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@runtime/mako_dio.h` around lines 273 - 293, Update mako_file_read_exact so it
returns an empty string whenever the read loop completes with total less than
count, freeing the allocated buffer first; only null-terminate and return the
buffer after exactly count bytes have been read, preserving the existing
handling for invalid inputs, allocation failure, and read errors.

@loreste
loreste merged commit f3f4798 into loreste:main Jul 22, 2026
10 of 12 checks passed
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