Skip to content

Move simple C shim outputs to MoonBit allocation - #410

Closed
peter-jerry-ye wants to merge 1 commit into
codex/wasm1-socket-ifname-bufferfrom
codex/wasm1-fill-return-shims
Closed

Move simple C shim outputs to MoonBit allocation#410
peter-jerry-ye wants to merge 1 commit into
codex/wasm1-socket-ifname-bufferfrom
codex/wasm1-fill-return-shims

Conversation

@peter-jerry-ye

@peter-jerry-ye peter-jerry-ye commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Part of #408. Stacked on #413.

Why

Several small C shims allocate returned String, Bytes, or arrays directly.
For Wasm1 reuse, MoonBit should own those visible allocations and C should only
fill caller-provided memory.

What

  • Move temporary path allocation and retry logic into MoonBit.
  • Move Unix and Windows current-environment allocation into MoonBit.
  • Move the dump-env helper to caller-provided output buffers.
  • Move Windows OS-string decode output allocation into MoonBit.

Why this is correct

Each shim now returns the actual required length. C copies into the
MoonBit-provided buffer only when it fits; otherwise MoonBit allocates the
reported size and retries. The Windows environment block keeps its full
double-null-terminated representation.

Review scope

This PR is limited to simple synchronous fill-return shims and test helper
bindings. TLS and thread-pool jobs are split into later PRs.

@coveralls

coveralls commented Jun 5, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 458

Warning

No base build found for commit 0808928 on codex/wasm1-socket-ifname-buffer.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 78.894%

Details

  • Patch coverage: 20 uncovered changes across 4 files (22 of 42 lines covered, 52.38%).

Uncovered Changes

File Changed Covered %
src/fs/tmpdir.mbt 12 4 33.33%
src/process/windows.mbt 10 4 40.0%
src/internal/os_string/os_string.mbt 12 8 66.67%
src/process/unix.mbt 8 6 75.0%

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 4269
Covered Lines: 3368
Line Coverage: 78.89%
Coverage Strength: 78902.64 hits per line

💛 - Coveralls

@peter-jerry-ye
peter-jerry-ye force-pushed the codex/wasm1-socket-buffers branch from e18aa04 to 4e89551 Compare June 5, 2026 09:38
@peter-jerry-ye
peter-jerry-ye force-pushed the codex/wasm1-fill-return-shims branch from f305d34 to 2a0abd7 Compare June 5, 2026 09:38
@peter-jerry-ye
peter-jerry-ye changed the base branch from codex/wasm1-socket-buffers to codex/wasm1-socket-ifname-buffer June 5, 2026 09:39
@Guest0x0

Guest0x0 commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

close via #415. Note that:

  • everything under test_programs don't need to support WASM, so no need to migrate them
  • @os_string would probably need separated #cfg for wasm anyway, so no need to migrate its current native code

@Guest0x0 Guest0x0 closed this Jun 8, 2026
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.

3 participants