Skip to content

refactor(common): extract gguf_mmap RAII wrapper as standalone PR#243

Merged
davide221 merged 2 commits into
Luce-Org:mainfrom
dusterbloom:refactor/extract-gguf-mmap
May 22, 2026
Merged

refactor(common): extract gguf_mmap RAII wrapper as standalone PR#243
davide221 merged 2 commits into
Luce-Org:mainfrom
dusterbloom:refactor/extract-gguf-mmap

Conversation

@dusterbloom
Copy link
Copy Markdown
Collaborator

Summary

Per @howard0su's review on #237 ("this worth a separate PR"): the gguf_mmap RAII wrapper for platform-conditional mmap of GGUF files is platform abstraction reusable by multiple loaders (target, draft, MTP head). Pulling it out of #237 into its own PR ahead of the loader refactor sequence.

Logically stacked on #241 (namespace rename) so this PR uses dflash::common from the start. Will diff cleanly against main once #241 merges; until then, the diff also includes the namespace rename commit.

What's in

  • dflash/src/common/gguf_mmap.h (219 lines, header-only, post cubic-P1 fixes from f6e8e94)
  • dflash/test/test_gguf_mmap.cpp — new unit test (5 cases, all passing)
  • CMakeLists wiring for the test target

Cubic P1 fixes preserved

  • open() is now idempotent: releases any prior mapping before re-opening, leaves the object in its default empty state on any failure path
  • Windows release() now calls CloseHandle() before clearing handle_ (was leaking the file-mapping HANDLE)

Test coverage

# Case Result
T1 open + read first bytes of a known file PASS
T2 open same instance twice (idempotency, no leak) PASS
T3 open non-existent path → false, object stays empty PASS
T4 explicit release() → object becomes empty PASS
T5 RAII destructor, scope exit, no crash PASS

What's not in

No consumers in this PR. The MTP / target / draft loaders that will use it land in later PRs of the sequence. This PR is the pure abstraction.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 140 files

Note: This PR contains a large number of files. cubic only reviews up to 100 files per PR, so some files may not have been reviewed. cubic prioritizes the most important files to review.
On a pro plan you can use ultrareview for larger PRs.

Re-trigger cubic

@dusterbloom dusterbloom marked this pull request as draft May 21, 2026 12:22
Per @howard0su's review on Luce-Org#237: gguf_mmap.h/.cpp are platform
abstraction (POSIX mmap / Windows MapViewOfFile) that will be reused
by multiple loaders. Extracting into a standalone PR ahead of the
loader refactor (target/draft/MTP heads all benefit).

Includes the cubic P1 fixes from f6e8e94:
- open() is now idempotent (releases prior mapping before re-opening,
  leaves object in default state on any failure path)
- Windows release() now calls CloseHandle() before clearing handle_

New: test_gguf_mmap unit test covers open/close, idempotency,
missing-file path, RAII destructor.

Stacked on Luce-Org#241 (uses dflash::common namespace from the start).
@dusterbloom dusterbloom force-pushed the refactor/extract-gguf-mmap branch from daeaa17 to 80e06a4 Compare May 21, 2026 19:22
@dusterbloom dusterbloom marked this pull request as ready for review May 21, 2026 19:23
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread dflash/test/test_gguf_mmap.cpp Outdated
Per cubic P3 on PR Luce-Org#243: T2's success check was tautological and
didn't verify that the error string is empty after a successful
open(). Replaced with assert(err.empty()).
@davide221 davide221 merged commit 3c5c99b into Luce-Org:main May 22, 2026
3 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