Skip to content

Commit

Permalink
feat: add glib.ext.new
Browse files Browse the repository at this point in the history
  • Loading branch information
ianprime0509 committed Jul 13, 2024
1 parent 9df5aa3 commit 787a447
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions extensions/glib2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ pub fn create(comptime T: type) *T {
return @ptrCast(@alignCast(glib.malloc(@sizeOf(T))));
}

/// Creates a heap-allocated copy of `value` using `glib.malloc`. `T` must not
/// be zero-sized or aligned more than `std.c.max_align_t`.
pub inline fn new(comptime T: type, value: T) *T {
const new_value = create(T);
new_value.* = value;
return new_value;
}

/// Destroys a value created using `create`.
pub fn destroy(ptr: anytype) void {
const type_info = @typeInfo(@TypeOf(ptr));
Expand Down

0 comments on commit 787a447

Please sign in to comment.