Skip to content

Commit 796707c

Browse files
committed
Clean up
1 parent c6d5217 commit 796707c

File tree

5 files changed

+43
-29
lines changed

5 files changed

+43
-29
lines changed

src/bootstrap.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn mono_doorstop_bootstrap(mono_domain: *mono.Domain) void {
2525

2626
mono.addrs.thread_set_main.?(mono.addrs.thread_current.?());
2727

28-
var program_path_buf = util.paths.ProgramPathBuf{};
28+
var program_path_buf: util.paths.ProgramPathBuf = undefined;
2929
const app_path = program_path_buf.get();
3030
util.setEnv("DOORSTOP_PROCESS_PATH", app_path);
3131

@@ -192,7 +192,7 @@ fn il2cpp_doorstop_bootstrap() void {
192192

193193
coreclr.load(coreclr_module);
194194

195-
var program_path_buf = util.paths.ProgramPathBuf{};
195+
var program_path_buf: util.paths.ProgramPathBuf = undefined;
196196
const app_path = program_path_buf.get();
197197

198198
const target_dir = util.paths.getFolderName(os_char, config.target_assembly.?);

src/debug/env.zig

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const builtin = @import("builtin");
2+
const std = @import("std");
3+
4+
const root = @import("../root.zig");
5+
const alloc = root.alloc;
6+
const logger = root.logger;
7+
const util = root.util;
8+
9+
pub fn dumpProgramPath() void {
10+
var program_path_buf: util.paths.ProgramPathBuf = undefined;
11+
const app_path = program_path_buf.get();
12+
const app_dir = util.paths.getFolderName(util.os_char, app_path);
13+
logger.debug("Executable path: {}", .{util.fmtString(app_path)});
14+
logger.debug("Application dir: {}", .{util.fmtString(app_dir)});
15+
}
16+
17+
pub fn dumpWorkingDir() void {
18+
const working_dir = util.paths.getWorkingDir() catch |e| std.debug.panic("Failed to determine current working directory path: {}", .{e});
19+
defer alloc.free(working_dir);
20+
logger.debug("Working dir: {}", .{util.fmtString(working_dir)});
21+
}
22+
23+
pub fn dumpDoorstopPath(module: if (builtin.os.tag == .windows) std.os.windows.HMODULE else void) void {
24+
var doorstop_path_buf: util.paths.ModulePathBuf = undefined;
25+
const doorstop_path = doorstop_path_buf.get(switch (builtin.os.tag) {
26+
.windows => module,
27+
// on *nix we just need an address in the library
28+
else => &dumpDoorstopPath,
29+
}).?;
30+
31+
logger.debug("Doorstop library path: {}", .{util.fmtString(doorstop_path)});
32+
}

src/entrypoint.zig

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,10 @@ pub fn entrypoint(module: if (builtin.os.tag == .windows) std.os.windows.HMODULE
3535

3636
logger.debug("Doorstop started!", .{});
3737

38-
{
39-
var program_path_buf = util.paths.ProgramPathBuf{};
40-
const app_path = program_path_buf.get();
41-
const app_dir = util.paths.getFolderName(util.os_char, app_path);
42-
logger.debug("Executable path: {}", .{util.fmtString(app_path)});
43-
logger.debug("Application dir: {}", .{util.fmtString(app_dir)});
44-
}
45-
46-
{
47-
const working_dir = util.paths.getWorkingDir() catch |e| std.debug.panic("Failed to determine current working directory path: {}", .{e});
48-
defer alloc.free(working_dir);
49-
logger.debug("Working dir: {}", .{util.fmtString(working_dir)});
50-
}
51-
52-
var doorstop_path_buf = util.paths.ModulePathBuf{};
53-
const doorstop_path = doorstop_path_buf.get(switch (builtin.os.tag) {
54-
.windows => module,
55-
// on *nix we just need an address in the library
56-
else => &entrypoint,
57-
}).?;
58-
59-
logger.debug("Doorstop library path: {}", .{util.fmtString(doorstop_path)});
38+
const debug_env = @import("debug/env.zig");
39+
debug_env.dumpProgramPath();
40+
debug_env.dumpWorkingDir();
41+
debug_env.dumpDoorstopPath(module);
6042

6143
switch (builtin.os.tag) {
6244
// windows

src/hooks.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn hookBootConfigCommon() ?[*:0]const os_char {
2121

2222
const path = switch (builtin.os.tag) {
2323
.macos => blk: {
24-
var program_path_buf = util.paths.ProgramPathBuf{};
24+
var program_path_buf: util.paths.ProgramPathBuf = undefined;
2525
const program_path = program_path_buf.get();
2626
const app_folder = util.paths.getFolderName(u8, util.paths.getFolderName(u8, program_path));
2727

@@ -32,7 +32,7 @@ fn hookBootConfigCommon() ?[*:0]const os_char {
3232
) catch @panic("Out of memory");
3333
},
3434
else => blk: {
35-
var program_path_buf = util.paths.ProgramPathBuf{};
35+
var program_path_buf: util.paths.ProgramPathBuf = undefined;
3636
const program_path = program_path_buf.get();
3737
const file_name = util.paths.getFileName(os_char, program_path, false);
3838

@@ -185,7 +185,7 @@ fn redirectInit(
185185
// However, using handle seems to cause issues on some distros, so we pass
186186
// the resolved symbol instead.
187187
// TODO: document specific cases
188-
var buf = util.paths.ModulePathBuf{};
188+
var buf: util.paths.ModulePathBuf = undefined;
189189
const path = buf.get(switch (builtin.os.tag) {
190190
.windows => handle,
191191
else => std.c.dlsym(handle, name),

src/util/paths.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn folder_exists(file: [*:0]const os_char) bool {
3131
}
3232

3333
pub const ModulePathBuf = struct {
34-
buf: if (builtin.os.tag == .windows) [std.os.windows.PATH_MAX_WIDE]u16 else void = undefined,
34+
buf: if (builtin.os.tag == .windows) [std.os.windows.PATH_MAX_WIDE]u16 else void,
3535

3636
pub fn get(self: *@This(), module: ?util.Module(true)) ?[:0]const os_char {
3737
self.* = undefined;
@@ -109,7 +109,7 @@ pub fn getWorkingDir() ![:0]os_char {
109109
}
110110

111111
pub const ProgramPathBuf = struct {
112-
buf: if (builtin.os.tag == .windows) ModulePathBuf else [std.fs.max_path_bytes:0]u8 = undefined,
112+
buf: if (builtin.os.tag == .windows) ModulePathBuf else [std.fs.max_path_bytes:0]u8,
113113

114114
pub fn get(self: *@This()) [:0]const os_char {
115115
if (builtin.os.tag == .windows) {

0 commit comments

Comments
 (0)