Skip to content

[codex] Fix factorial work distribution and update for Zig 0.16#2

Closed
mjackson wants to merge 2 commits into
fulgidus:mainfrom
mjackson:codex/zig-0-16-fixes
Closed

[codex] Fix factorial work distribution and update for Zig 0.16#2
mjackson wants to merge 2 commits into
fulgidus:mainfrom
mjackson:codex/zig-0-16-fixes

Conversation

@mjackson
Copy link
Copy Markdown

What changed

This PR fixes a real bug in the factorial implementation and updates the project to build cleanly with Zig 0.16.

Why it changed

The repo no longer built with the current Zig toolchain because both the build API and several stdlib APIs had changed.

While updating the code, I also found a separate bug in factorial.zig: the work distribution logic returned a slice backed by stack memory and also assumed a maximum of 8 threads even though the thread count is user-controlled.

Impact

  • zig build now succeeds on Zig 0.16
  • zig build test now succeeds on Zig 0.16
  • factorial work distribution no longer uses invalid memory or overruns a fixed-size stack buffer when more than 8 threads are requested

Root cause

  • The build script and command modules targeted older Zig APIs such as root_source_file, std.io.getStdOut, std.fs.cwd, and older process/random helpers.
  • The factorial work range code constructed a slice from a local array and returned it, which made the caller read invalid memory after the function returned.

Validation

  • zig build
  • zig build test

@mjackson
Copy link
Copy Markdown
Author

Superseded by #3 from the correctly prefixed branch.

@mjackson mjackson closed this Apr 18, 2026
@mjackson mjackson deleted the codex/zig-0-16-fixes branch April 18, 2026 21:26
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.

1 participant