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:
2025-04-03 21:16:43 -04:00
parent e24220c98b
commit 88b2734886

View File

@@ -1,6 +1,11 @@
const is_debug = builtin.mode == .Debug;
const base64Enc = std.base64.Base64Encoder.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.
/// 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 {
var dba: ?DebugAllocator = if (comptime is_debug) DebugAllocator.init else null;
defer if (dba) |*d| {
_ = d.deinit();
defer if (is_debug) {
_ = dba.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{
.relay = .{