Files
ghostty/pkg/sentry/value.zig
Mitchell Hashimoto eccd07f009 pkg: replace @cImport with addTranslateC in pkg/
@cImport is going to disappear in Zig 0.17. Its deprecated in Zig 0.16.
Let's remove it now.

Replace @cImport with addTranslateC across pkg/ packages. Each
package now has a c_import.h header that is translated at build
time via addTranslateC and exposed as a "cimport" module import.

Converted packages:
- dcimgui
- fontconfig
- freetype
- glslang
- harfbuzz
- macos
- oniguruma
- opengl
- sentry
- spirv-cross
- wuffs

Omitted:
- gtk4-layer-shell - This has a bit more complexity with how it
  interacts with GTK headers, so I need to consider this a bit more.
- src/ - It'll be cleaner to do this separately.
2026-04-16 21:35:51 -07:00

76 lines
2.0 KiB
Zig

const std = @import("std");
const assert = std.debug.assert;
const c = @import("c");
const Level = @import("level.zig").Level;
/// sentry_value_t
pub const Value = struct {
/// The underlying value. This is a union that could be represented with
/// an extern union but I don't want to risk C ABI issues so we wrap it
/// in a struct.
value: c.sentry_value_t,
pub fn initMessageEvent(
level: Level,
logger: ?[]const u8,
message: []const u8,
) Value {
return .{ .value = c.sentry_value_new_message_event_n(
@intFromEnum(level),
if (logger) |v| v.ptr else null,
if (logger) |v| v.len else 0,
message.ptr,
message.len,
) };
}
pub fn initObject() Value {
return .{ .value = c.sentry_value_new_object() };
}
pub fn initString(value: []const u8) Value {
return .{ .value = c.sentry_value_new_string_n(value.ptr, value.len) };
}
pub fn initBool(value: bool) Value {
return .{ .value = c.sentry_value_new_bool(@intFromBool(value)) };
}
pub fn initInt32(value: i32) Value {
return .{ .value = c.sentry_value_new_int32(value) };
}
pub fn decref(self: Value) void {
c.sentry_value_decref(self.value);
}
pub fn incref(self: Value) Value {
c.sentry_value_incref(self.value);
}
pub fn isNull(self: Value) bool {
return c.sentry_value_is_null(self.value) != 0;
}
/// sentry_value_set_by_key_n
pub fn set(self: Value, key: []const u8, value: Value) void {
_ = c.sentry_value_set_by_key_n(
self.value,
key.ptr,
key.len,
value.value,
);
}
/// sentry_value_set_by_key_n
pub fn get(self: Value, key: []const u8) ?Value {
const val: Value = .{ .value = c.sentry_value_get_by_key_n(
self.value,
key.ptr,
key.len,
) };
if (val.isNull()) return null;
return val;
}
};