mirror of
https://git.robbyzambito.me/zaprus
synced 2025-12-20 16:24:50 +00:00
Move dba to top level scope
This makes it so references to it are lazily compiled, so I can throw a compileError if it is referenced in the wrong mode.
This commit is contained in:
12
src/main.zig
12
src/main.zig
@@ -1,6 +1,11 @@
|
|||||||
const is_debug = builtin.mode == .Debug;
|
const is_debug = builtin.mode == .Debug;
|
||||||
const base64Enc = std.base64.Base64Encoder.init(std.base64.standard_alphabet_chars, '=');
|
const base64Enc = std.base64.Base64Encoder.init(std.base64.standard_alphabet_chars, '=');
|
||||||
const base64Dec = std.base64.Base64Decoder.init(std.base64.standard_alphabet_chars, '=');
|
const base64Dec = std.base64.Base64Decoder.init(std.base64.standard_alphabet_chars, '=');
|
||||||
|
var dba: DebugAllocator =
|
||||||
|
if (is_debug)
|
||||||
|
DebugAllocator.init
|
||||||
|
else
|
||||||
|
@compileError("Should not use debug allocator in release mode");
|
||||||
|
|
||||||
/// Type tag for SaprusMessage union.
|
/// Type tag for SaprusMessage union.
|
||||||
/// This is the first value in the actual packet sent over the network.
|
/// This is the first value in the actual packet sent over the network.
|
||||||
@@ -148,12 +153,11 @@ const SaprusMessage = union(SaprusPacketType) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
var dba: ?DebugAllocator = if (comptime is_debug) DebugAllocator.init else null;
|
defer if (is_debug) {
|
||||||
defer if (dba) |*d| {
|
_ = dba.deinit();
|
||||||
_ = d.deinit();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var gpa = if (dba) |*d| d.allocator() else std.heap.smp_allocator;
|
var gpa = if (is_debug) dba.allocator() else std.heap.smp_allocator;
|
||||||
|
|
||||||
const msg = SaprusMessage{
|
const msg = SaprusMessage{
|
||||||
.relay = .{
|
.relay = .{
|
||||||
|
|||||||
Reference in New Issue
Block a user