authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 03:52:27 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 03:52:27 -07:00
loga8590c12cf668eb7becd862fc10cd8f77ad003a5
tree886ca2bc46c5528400174b6ccf3848fd632a3860
parent2e97ffbdeda9c737f12b819fbf052b629cfbd6bd

remove global allocator from u.random_string


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

src/cmd/aquila/install.zig+1-1
......@@ -18,7 +18,7 @@ pub fn execute(args: [][]u8) !void {
1818 defer f.close();
1919 const w = f.writer();
2020 const init = @import("../init.zig");
21 try init.writeExeManifest(w, try u.random_string(48), "zigmod_installation", null, null);
21 try init.writeExeManifest(w, try u.random_string(gpa, 48), "zigmod_installation", null, null);
2222 }
2323
2424 // add to ~/zig.mod for later
src/cmd/init.zig+1-1
......@@ -26,7 +26,7 @@ pub fn execute(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(48));
29 const id = try inquirer.answer(stdout, "ID (this gets autogenerated):", string, "{s}", try u.random_string(gpa, 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
......@@ -263,7 +263,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
263263 dd.dep = d.*;
264264 const save = dd;
265265 if (d.type != .local) dd.clean_path = u.trim_prefix(modpath, cachepath)[1..];
266 if (dd.id.len == 0) dd.id = try u.random_string(48);
266 if (dd.id.len == 0) dd.id = try u.random_string(gpa, 48);
267267 if (d.name.len > 0) dd.name = d.name;
268268 if (d.main.len > 0) dd.main = d.main;
269269 if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs;
src/util/funcs.zig+2-2
......@@ -170,11 +170,11 @@ pub fn last(in: []string) !string {
170170
171171const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";
172172
173pub fn random_string(len: usize) !string {
173pub fn random_string(alloc: *std.mem.Allocator, len: usize) !string {
174174 const now = @intCast(u64, std.time.nanoTimestamp());
175175 var rand = std.rand.DefaultPrng.init(now);
176176 const r = &rand.random;
177 var buf = try gpa.alloc(u8, len);
177 var buf = try alloc.alloc(u8, len);
178178 var i: usize = 0;
179179 while (i < len) : (i += 1) {
180180 buf[i] = alphabet[r.int(usize) % alphabet.len];
src/util/modfile.zig+1-1
......@@ -53,7 +53,7 @@ pub const ModFile = struct {
5353 }
5454
5555 return Self{
56 .id = if (id.len == 0) try u.random_string(48) else id,
56 .id = if (id.len == 0) try u.random_string(alloc, 48) else id,
5757 .name = name,
5858 .main = main,
5959 .c_include_dirs = try mapping.get_string_array(alloc, "c_include_dirs"),
src/util/module.zig+1-1
......@@ -38,7 +38,7 @@ pub const Module = struct {
3838 return Module{
3939 .alloc = alloc,
4040 .is_sys_lib = false,
41 .id = if (dep.id.len > 0) dep.id else try u.random_string(48),
41 .id = if (dep.id.len > 0) dep.id else try u.random_string(alloc, 48),
4242 .name = dep.name,
4343 .main = dep.main,
4444 .c_include_dirs = dep.c_include_dirs,