mirror of
https://git.robbyzambito.me/zaprus
synced 2025-12-20 08:14: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 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 = .{
|
||||
|
||||
Reference in New Issue
Block a user