authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-11-24 01:02:25 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-11-24 01:02:25 -08:00
log271e7f758da34d2865cec4220e009bff6baccb92
treebb5e04773efa8b1a0e379737a9a2f808e4c6a8be
parente545025a089e4512a95c147ba4a2773553817c74

util: make random_string not need an allocator anymore


7 files changed, 8 insertions(+), 8 deletions(-)

src/cmd/aquila/install.zig+1-1
......@@ -20,7 +20,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
2020 defer f.close();
2121 const w = f.writer();
2222 const init = @import("../init.zig");
23 try init.writeExeManifest(w, try u.random_string(gpa, 48), "zigmod_installation", null, null);
23 try init.writeExeManifest(w, &u.random_string(48), "zigmod_installation", null, null);
2424 }
2525
2626 // add to ~/zigmod.yml for later
src/cmd/aquila/update.zig+1-1
......@@ -20,7 +20,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
2020 defer f.close();
2121 const w = f.writer();
2222 const init = @import("../init.zig");
23 try init.writeExeManifest(w, try u.random_string(gpa, 48), "zigmod_installation", null, null);
23 try init.writeExeManifest(w, &u.random_string(48), "zigmod_installation", null, null);
2424 }
2525 u.assert(args.len == 0, "zigmod aq update accepts no parameters", .{});
2626
src/cmd/init.zig+1-1
......@@ -26,7 +26,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
2626 const stdin = std.io.getStdIn().reader();
2727 const cwd = std.fs.cwd();
2828
29 const id = try inquirer.answer(stdout, "ID (this gets autogenerated):", string, "{s}", try u.random_string(gpa, 48));
29 const id = try inquirer.answer(stdout, "ID (this gets autogenerated):", string, "{s}", &u.random_string(48));
3030
3131 const ptype = try inquirer.forEnum(stdout, stdin, "Are you making an application or a library?", gpa, enum { exe, lib }, null);
3232
src/common.zig+1-1
......@@ -277,7 +277,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
277277 dd.for_build = d.for_build;
278278 const save = dd;
279279 if (d.type != .local) dd.clean_path = extras.trimPrefix(modpath, cachepath)[1..];
280 if (dd.id.len == 0) dd.id = try u.random_string(options.alloc, 48);
280 if (dd.id.len == 0) dd.id = &u.random_string(48);
281281 if (d.name.len > 0) dd.name = d.name;
282282 if (d.main.len > 0) dd.main = d.main;
283283 if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs;
src/util/funcs.zig+2-2
......@@ -97,11 +97,11 @@ pub fn last(in: []string) !string {
9797
9898const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";
9999
100pub fn random_string(alloc: std.mem.Allocator, len: usize) !string {
100pub fn random_string(comptime len: usize) [len]u8 {
101101 const now: u64 = @intCast(std.time.nanoTimestamp());
102102 var rand = std.rand.DefaultPrng.init(now);
103103 var r = rand.random();
104 var buf = try alloc.alloc(u8, len);
104 var buf: [len]u8 = undefined;
105105 var i: usize = 0;
106106 while (i < len) : (i += 1) {
107107 buf[i] = alphabet[r.int(usize) % alphabet.len];
src/util/modfile.zig+1-1
......@@ -62,7 +62,7 @@ pub const ModFile = struct {
6262 }
6363
6464 return Self{
65 .id = if (id.len == 0) try u.random_string(alloc, 48) else id,
65 .id = if (id.len == 0) &u.random_string(48) else id,
6666 .name = name,
6767 .main = main,
6868 .c_include_dirs = try mapping.get_string_array(alloc, "c_include_dirs"),
src/util/module.zig+1-1
......@@ -40,7 +40,7 @@ pub const Module = struct {
4040 }
4141 return Module{
4242 .type = dep.type,
43 .id = if (dep.id.len > 0) dep.id else try u.random_string(alloc, 48),
43 .id = if (dep.id.len > 0) dep.id else &u.random_string(48),
4444 .name = dep.name,
4545 .main = dep.main,
4646 .c_include_dirs = dep.c_include_dirs,