Skip to content

Rewrite in Zig#144

Open
jstrieb wants to merge 77 commits intomasterfrom
zig
Open

Rewrite in Zig#144
jstrieb wants to merge 77 commits intomasterfrom
zig

Conversation

@jstrieb
Copy link
Copy Markdown
Owner

@jstrieb jstrieb commented Mar 29, 2026

Before merging, I will need to do some history revision to clean things up. One of the changes on this branch moves the generated files to their own branch, and I will need to manually fix some stuff up in accordance with that.

Comment on lines +16 to +17
const arena = try allocator.create(std.heap.ArenaAllocator);
arena.* = std.heap.ArenaAllocator.init(allocator);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not var arena = std.heap.ArenaAllocator.init(allocator);?

}

var writer = try std.Io.Writer.Allocating.initCapacity(
self.arena.allocator(),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is an arena really the right model here? I imagine you'll make a lot of http requests whose responses are fairly disposable, but whose memory footprint will grow the arena over time without freeing anything until very late in the program lifespan.

);
errdefer writer.deinit();
const status = (try (self.client.fetch(.{
.location = .{ .url = url },
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

shouldn't you specify .method = POST here?

.payload = body,
.headers = headers,
}) catch |err| switch (err) {
error.HttpConnectionClosing => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

personally I would be making a private inner version of get/post since these two functions are so similar


fn overview(
arena: *std.heap.ArenaAllocator,
stats: anytype,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

it's interesting, you seem to prefer anonymous structs much more than me. I would probably have a single Overview struct instead of accepting anytype. I generally think type-first which could be seen as a limitation in languages where I can't annotate as heavily as I may want.

} else null;
defer if (excluded_langs) |excluded| allocator.free(excluded);

var stats: Statistics = undefined;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why use the = undefined pattern here but the labeled breaks above?

) ![]const u8 {
const a = arena.allocator();
var out_data = template;
// Vulnerable to template injection. In practice, this should never happen.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Another idea is to just use std.fmt.print. So convert your templates to use {[lang_list]s} syntax and you can just do std.fmt.print and pass the stats struct directly

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I didn't know you could pass named arguments like that. That's very interesting and much better than what I'm doing...

fn get_basic_info(
client: *HttpClient,
allocator: std.mem.Allocator,
) !struct { []u32, []const u8, ?[]const u8 } {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

personally it would bother me not having these named for the caller

Comment on lines +512 to +513
.ok => {},
.accepted => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this works out pretty nicely

}
return;
}
} else {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

so this would be hit when months = 1 and the limit is still exceeded? Interesting, I guess this works

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