Skip to content

Commit 1d92b78

Browse files
committed
Enable caller to decide where App is
1 parent 82e67b7 commit 1d92b78

File tree

6 files changed

+10
-14
lines changed

6 files changed

+10
-14
lines changed

src/app.zig

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ pub const App = struct {
2828
run_mode: RunMode,
2929
};
3030

31-
pub fn init(allocator: Allocator, config: Config) !*App {
32-
const app = try allocator.create(App);
33-
errdefer allocator.destroy(app);
34-
31+
pub fn init(allocator: Allocator, config: Config) !App {
3532
const loop = try allocator.create(Loop);
3633
errdefer allocator.destroy(loop);
3734

@@ -40,7 +37,7 @@ pub const App = struct {
4037

4138
const app_dir_path = getAndMakeAppDir(allocator);
4239

43-
app.* = .{
40+
var app: App = .{
4441
.loop = loop,
4542
.allocator = allocator,
4643
.telemetry = undefined,
@@ -49,7 +46,7 @@ pub const App = struct {
4946
.tls_verify_host = config.tls_verify_host,
5047
}),
5148
};
52-
app.telemetry = Telemetry.init(app, config.run_mode);
49+
app.telemetry = Telemetry.init(&app, config.run_mode);
5350

5451
return app;
5552
}
@@ -63,7 +60,6 @@ pub const App = struct {
6360
self.loop.deinit();
6461
allocator.destroy(self.loop);
6562
self.http_client.deinit();
66-
allocator.destroy(self);
6763
}
6864
};
6965

src/cdp/testing.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ const TestCDP = main.CDPT(struct {
138138
});
139139

140140
const TestContext = struct {
141-
app: *App,
141+
app: App,
142142
client: ?Client = null,
143143
cdp_: ?TestCDP = null,
144144
arena: std.heap.ArenaAllocator,
@@ -156,7 +156,7 @@ const TestContext = struct {
156156
self.client = Client.init(self.arena.allocator());
157157
// Don't use the arena here. We want to detect leaks in CDP.
158158
// The arena is only for test-specific stuff
159-
self.cdp_ = TestCDP.init(self.app, &self.client.?);
159+
self.cdp_ = TestCDP.init(&self.app, &self.client.?);
160160
}
161161
return &self.cdp_.?;
162162
}

src/main.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn main() !void {
7979
app.telemetry.record(.{ .run = {} });
8080

8181
const timeout = std.time.ns_per_s * @as(u64, opts.timeout);
82-
server.run(app, address, timeout) catch |err| {
82+
server.run(&app, address, timeout) catch |err| {
8383
log.err("Server error", .{});
8484
return err;
8585
};
@@ -99,7 +99,7 @@ pub fn main() !void {
9999
defer vm.deinit();
100100

101101
// browser
102-
var browser = Browser.init(app);
102+
var browser = Browser.init(&app);
103103
defer browser.deinit();
104104

105105
var session = try browser.newSession({});

src/main_unit_tests.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ fn serveCDP(address: std.net.Address) !void {
218218

219219
const server = @import("server.zig");
220220
wg.finish();
221-
server.run(app, address, std.time.ns_per_s * 2) catch |err| {
221+
server.run(&app, address, std.time.ns_per_s * 2) catch |err| {
222222
std.debug.print("CDP server error: {}", .{err});
223223
return err;
224224
};

src/telemetry/telemetry.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ test "telemetry: sends event to provider" {
160160
var app = testing.app(.{});
161161
defer app.deinit();
162162

163-
var telemetry = TelemetryT(MockProvider).init(app, .serve);
163+
var telemetry = TelemetryT(MockProvider).init(&app, .serve);
164164
defer telemetry.deinit();
165165
const mock = &telemetry.provider;
166166

src/testing.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ pub fn print(comptime fmt: []const u8, args: anytype) void {
156156
}
157157

158158
// dummy opts incase we want to add something, and not have to break all the callers
159-
pub fn app(_: anytype) *App {
159+
pub fn app(_: anytype) App {
160160
return App.init(allocator, .{ .run_mode = .serve }) catch unreachable;
161161
}
162162

0 commit comments

Comments
 (0)