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 {...@@ -18,7 +18,7 @@ pub fn execute(args: [][]u8) !void {
18 defer f.close();18 defer f.close();
19 const w = f.writer();19 const w = f.writer();
20 const init = @import("../init.zig");20 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);
22 }22 }
2323
24 // add to ~/zig.mod for later24 // add to ~/zig.mod for later
src/cmd/init.zig+1-1
...@@ -26,7 +26,7 @@ pub fn execute(args: [][]u8) !void {...@@ -26,7 +26,7 @@ pub fn execute(args: [][]u8) !void {
26 const stdin = std.io.getStdIn().reader();26 const stdin = std.io.getStdIn().reader();
27 const cwd = std.fs.cwd();27 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
31 const ptype = try inquirer.forEnum(stdout, stdin, "Are you making an application or a library?", gpa, enum { exe, lib }, null);31 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...@@ -263,7 +263,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
263 dd.dep = d.*;263 dd.dep = d.*;
264 const save = dd;264 const save = dd;
265 if (d.type != .local) dd.clean_path = u.trim_prefix(modpath, cachepath)[1..];265 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);
267 if (d.name.len > 0) dd.name = d.name;267 if (d.name.len > 0) dd.name = d.name;
268 if (d.main.len > 0) dd.main = d.main;268 if (d.main.len > 0) dd.main = d.main;
269 if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs;269 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 {...@@ -170,11 +170,11 @@ pub fn last(in: []string) !string {
170170
171const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";171const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";
172172
173pub fn random_string(len: usize) !string {173pub fn random_string(alloc: *std.mem.Allocator, len: usize) !string {
174 const now = @intCast(u64, std.time.nanoTimestamp());174 const now = @intCast(u64, std.time.nanoTimestamp());
175 var rand = std.rand.DefaultPrng.init(now);175 var rand = std.rand.DefaultPrng.init(now);
176 const r = &rand.random;176 const r = &rand.random;
177 var buf = try gpa.alloc(u8, len);177 var buf = try alloc.alloc(u8, len);
178 var i: usize = 0;178 var i: usize = 0;
179 while (i < len) : (i += 1) {179 while (i < len) : (i += 1) {
180 buf[i] = alphabet[r.int(usize) % alphabet.len];180 buf[i] = alphabet[r.int(usize) % alphabet.len];
src/util/modfile.zig+1-1
...@@ -53,7 +53,7 @@ pub const ModFile = struct {...@@ -53,7 +53,7 @@ pub const ModFile = struct {
53 }53 }
5454
55 return Self{55 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,
57 .name = name,57 .name = name,
58 .main = main,58 .main = main,
59 .c_include_dirs = try mapping.get_string_array(alloc, "c_include_dirs"),59 .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 {...@@ -38,7 +38,7 @@ pub const Module = struct {
38 return Module{38 return Module{
39 .alloc = alloc,39 .alloc = alloc,
40 .is_sys_lib = false,40 .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),
42 .name = dep.name,42 .name = dep.name,
43 .main = dep.main,43 .main = dep.main,
44 .c_include_dirs = dep.c_include_dirs,44 .c_include_dirs = dep.c_include_dirs,