aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-10-23 18:36:00 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-10-23 18:36:00 -0700
commitc01aa26bd3715f2426f45f67de944b3192293d37 (patch)
tree7d67cfa1c0a8668543ab96c451f3aa9142a1d622
parent46a6d50fdf4d26e8af22fb6a5207b9fab3d0777a (diff)
downloadzig-c01aa26bd3715f2426f45f67de944b3192293d37.tar.gz
zig-c01aa26bd3715f2426f45f67de944b3192293d37.zip
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 #13315.
-rw-r--r--src/tracy.zig36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/tracy.zig b/src/tracy.zig
index 10f2410091..08774f9bd3 100644
--- a/src/tracy.zig
+++ b/src/tracy.zig
@@ -63,44 +63,40 @@ pub const Ctx = if (enable) ___tracy_c_zone_context else struct {
pub inline fn trace(comptime src: std.builtin.SourceLocation) Ctx {
if (!enable) return .{};
- if (enable_callstack) {
- return ___tracy_emit_zone_begin_callstack(&.{
+ const global = struct {
+ const loc: ___tracy_source_location_data = .{
.name = null,
.function = src.fn_name.ptr,
.file = src.file.ptr,
.line = src.line,
.color = 0,
- }, callstack_depth, 1);
+ };
+ };
+
+ if (enable_callstack) {
+ return ___tracy_emit_zone_begin_callstack(&global.loc, callstack_depth, 1);
} else {
- return ___tracy_emit_zone_begin(&.{
- .name = null,
- .function = src.fn_name.ptr,
- .file = src.file.ptr,
- .line = src.line,
- .color = 0,
- }, 1);
+ return ___tracy_emit_zone_begin(&global.loc, 1);
}
}
pub inline fn traceNamed(comptime src: std.builtin.SourceLocation, comptime name: [:0]const u8) Ctx {
if (!enable) return .{};
- if (enable_callstack) {
- return ___tracy_emit_zone_begin_callstack(&.{
+ const global = struct {
+ const loc: ___tracy_source_location_data = .{
.name = name.ptr,
.function = src.fn_name.ptr,
.file = src.file.ptr,
.line = src.line,
.color = 0,
- }, callstack_depth, 1);
+ };
+ };
+
+ if (enable_callstack) {
+ return ___tracy_emit_zone_begin_callstack(&global.loc, callstack_depth, 1);
} else {
- return ___tracy_emit_zone_begin(&.{
- .name = name.ptr,
- .function = src.fn_name.ptr,
- .file = src.file.ptr,
- .line = src.line,
- .color = 0,
- }, 1);
+ return ___tracy_emit_zone_begin(&global.loc, 1);
}
}