Skip to content

Fix factorial work distribution and update for Zig 0.16#3

Draft
mjackson wants to merge 3 commits into
fulgidus:mainfrom
mjackson:mjackson/zig-0-16-fixes
Draft

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

Conversation

@mjackson
Copy link
Copy Markdown

  • Fix the factorial work distribution bug that returned a slice backed by stack memory and assumed a fixed 8-thread limit.
  • Update the build script and command implementations for Zig 0.16's current build and stdlib APIs.
  • Replace the temporary compatibility shim with direct Zig 0.16 I/O calls in the command modules.

Copy link
Copy Markdown

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

Updates the ziglets CLI suite for Zig 0.16 APIs (notably the new std.Io I/O model and std.Build module setup) and addresses the factorial command’s work distribution implementation to avoid returning stack-backed slices / fixed thread limits.

Changes:

  • Migrate command modules from std.io.getStd* to Zig 0.16 std.Io readers/writers.
  • Rework factorial work distribution to allocate thread ranges dynamically.
  • Update build.zig and main entrypoint/arg handling to Zig 0.16 build + process init APIs.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/ziglets/writer.zig Updates file I/O and stdout printing to Zig 0.16 std.Io APIs.
src/ziglets/touch.zig Ports stdout + filesystem calls to std.Io APIs.
src/ziglets/pgen.zig Ports stdout writer typing and updates RNG usage.
src/ziglets/guess.zig Ports stdin/stdout I/O to Zig 0.16 std.Io interfaces.
src/ziglets/factorial.zig Allocates work ranges dynamically and ports stdout to std.Io.
src/ziglets/clock.zig Switches to std.Io.Clock and std.Io stdout writer usage.
src/ziglets/calculator.zig Ports I/O to std.Io and updates raw-mode flag handling.
src/main.zig Updates help output I/O and changes main signature + args parsing for Zig 0.16.
build.zig Migrates to module-based addExecutable / addTest wiring for Zig 0.16.

Comment thread src/ziglets/factorial.zig Outdated
Comment thread src/ziglets/writer.zig
Comment on lines +32 to +35
const n = try file_reader.interface.readSliceShort(buf); // Read the file content into the buffer, get the number of bytes read
var stdout_buffer: [0]u8 = undefined;
var stdout = std.Io.File.stdout().writer(io, &stdout_buffer);
try stdout.interface.print("file.txt content: {s}\n", .{buf[0..n]}); // Print the content of the file to standard output
Comment thread src/ziglets/pgen.zig
Comment on lines +165 to +169
const io = std.Io.Threaded.global_single_threaded.io();
var seed: u64 = undefined;
io.random(std.mem.asBytes(&seed));
var prng = std.Random.DefaultPrng.init(seed);
const random = prng.random();
Comment on lines 120 to +125
// Leggiamo un singolo carattere (ora senza bisogno di premere Enter)
const bytes_read = stdin.read(&buf) catch |err| {
try stdout.print("\nError durante la lettura: {s}\n", .{@errorName(err)});
return err;
const c = stdin.interface.takeByte() catch |err| switch (err) {
error.EndOfStream => return,
error.ReadFailed => {
try stdout.interface.print("\nError durante la lettura: {s}\n", .{@errorName(stdin.err.?)});
return stdin.err.?;
agreed

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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