diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-04-04 19:22:04 +0300 |
|---|---|---|
| committer | Can Celik <ogulcancelik@gmail.com> | 2026-04-05 01:23:06 +0300 |
| commit | 41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch) | |
| tree | 3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/lib/allocator | |
| parent | 55c138263e190a1e79d4b997bfb9397306c0ec1f (diff) | |
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/lib/allocator')
| -rw-r--r-- | vendor/libghostty-vt/src/lib/allocator/convenience.zig | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/lib/allocator/convenience.zig b/vendor/libghostty-vt/src/lib/allocator/convenience.zig new file mode 100644 index 00000000..0f5f88d2 --- /dev/null +++ b/vendor/libghostty-vt/src/lib/allocator/convenience.zig @@ -0,0 +1,59 @@ +//! This contains convenience functions for allocating various types. +//! +//! The primary use case for this is Wasm builds. Ghostty relies a lot on +//! pointers to various types for ABI compatibility and creating those pointers +//! in Wasm is tedious. This file contains a purely additive set of functions +//! that can be exposed to the Wasm module without changing the API from the +//! C library. +//! +//! Given these are convenience methods, they always use the default allocator. +//! If a caller is using a custom allocator, they have the expertise to +//! allocate these types manually using their custom allocator. + +// Get our default allocator at comptime since it is known. +const default = @import("../allocator.zig").default; +const alloc = default(null); + +pub const Opaque = *anyopaque; + +pub fn allocOpaque() callconv(.c) ?*Opaque { + return alloc.create(*anyopaque) catch return null; +} + +pub fn freeOpaque(ptr: ?*Opaque) callconv(.c) void { + if (ptr) |p| alloc.destroy(p); +} + +pub fn allocU8Array(len: usize) callconv(.c) ?[*]u8 { + const slice = alloc.alloc(u8, len) catch return null; + return slice.ptr; +} + +pub fn freeU8Array(ptr: ?[*]u8, len: usize) callconv(.c) void { + if (ptr) |p| alloc.free(p[0..len]); +} + +pub fn allocU16Array(len: usize) callconv(.c) ?[*]u16 { + const slice = alloc.alloc(u16, len) catch return null; + return slice.ptr; +} + +pub fn freeU16Array(ptr: ?[*]u16, len: usize) callconv(.c) void { + if (ptr) |p| alloc.free(p[0..len]); +} + +pub fn allocU8() callconv(.c) ?*u8 { + return alloc.create(u8) catch return null; +} + +pub fn freeU8(ptr: ?*u8) callconv(.c) void { + if (ptr) |p| alloc.destroy(p); +} + +pub fn allocUsize() callconv(.c) ?*usize { + return alloc.create(usize) catch return null; +} + +pub fn freeUsize(ptr: ?*usize) callconv(.c) void { + if (ptr) |p| alloc.destroy(p); +} |
