Skip to content

Commit 65b9534

Browse files
andrewrkmlugg
authored andcommitted
tracy: protect source info via global constant
When the code is written this way, you get a compile error if the pointer given to Tracy does not have a static lifetime. This would have caught the regression in ziglang#13315.
1 parent 8537099 commit 65b9534

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

src/tracy.zig

+16-20
Original file line numberDiff line numberDiff line change
@@ -63,44 +63,40 @@ pub const Ctx = if (enable) ___tracy_c_zone_context else struct {
6363
pub inline fn trace(comptime src: std.builtin.SourceLocation) Ctx {
6464
if (!enable) return .{};
6565

66-
if (enable_callstack) {
67-
return ___tracy_emit_zone_begin_callstack(&.{
66+
const global = struct {
67+
const loc: ___tracy_source_location_data = .{
6868
.name = null,
6969
.function = src.fn_name.ptr,
7070
.file = src.file.ptr,
7171
.line = src.line,
7272
.color = 0,
73-
}, callstack_depth, 1);
73+
};
74+
};
75+
76+
if (enable_callstack) {
77+
return ___tracy_emit_zone_begin_callstack(&global.loc, callstack_depth, 1);
7478
} else {
75-
return ___tracy_emit_zone_begin(&.{
76-
.name = null,
77-
.function = src.fn_name.ptr,
78-
.file = src.file.ptr,
79-
.line = src.line,
80-
.color = 0,
81-
}, 1);
79+
return ___tracy_emit_zone_begin(&global.loc, 1);
8280
}
8381
}
8482

8583
pub inline fn traceNamed(comptime src: std.builtin.SourceLocation, comptime name: [:0]const u8) Ctx {
8684
if (!enable) return .{};
8785

88-
if (enable_callstack) {
89-
return ___tracy_emit_zone_begin_callstack(&.{
86+
const global = struct {
87+
const loc: ___tracy_source_location_data = .{
9088
.name = name.ptr,
9189
.function = src.fn_name.ptr,
9290
.file = src.file.ptr,
9391
.line = src.line,
9492
.color = 0,
95-
}, callstack_depth, 1);
93+
};
94+
};
95+
96+
if (enable_callstack) {
97+
return ___tracy_emit_zone_begin_callstack(&global.loc, callstack_depth, 1);
9698
} else {
97-
return ___tracy_emit_zone_begin(&.{
98-
.name = name.ptr,
99-
.function = src.fn_name.ptr,
100-
.file = src.file.ptr,
101-
.line = src.line,
102-
.color = 0,
103-
}, 1);
99+
return ___tracy_emit_zone_begin(&global.loc, 1);
104100
}
105101
}
106102

0 commit comments

Comments
 (0)