![]() |
libghostty
|
Convenience functions for allocating various types in WebAssembly builds. These are only available the libghostty-vt wasm module.
Ghostty relies on pointers to various types for ABI compatibility, and creating those pointers in Wasm can be tedious. These functions provide a purely additive set of utilities that simplify memory management in Wasm environments without changing the core C library API.
Here's a simple example of using the Wasm utilities with the key encoder:
Functions | |
| GHOSTTY_API GhosttySgrAttribute * | ghostty_wasm_alloc_sgr_attribute (void) |
| GHOSTTY_API void | ghostty_wasm_free_sgr_attribute (GhosttySgrAttribute *attr) |
| GHOSTTY_API void ** | ghostty_wasm_alloc_opaque (void) |
| GHOSTTY_API void | ghostty_wasm_free_opaque (void **ptr) |
| GHOSTTY_API uint8_t * | ghostty_wasm_alloc_u8_array (size_t len) |
| GHOSTTY_API void | ghostty_wasm_free_u8_array (uint8_t *ptr, size_t len) |
| GHOSTTY_API uint16_t * | ghostty_wasm_alloc_u16_array (size_t len) |
| GHOSTTY_API void | ghostty_wasm_free_u16_array (uint16_t *ptr, size_t len) |
| GHOSTTY_API uint8_t * | ghostty_wasm_alloc_u8 (void) |
| GHOSTTY_API void | ghostty_wasm_free_u8 (uint8_t *ptr) |
| GHOSTTY_API size_t * | ghostty_wasm_alloc_usize (void) |
| GHOSTTY_API void | ghostty_wasm_free_usize (size_t *ptr) |
| GHOSTTY_API void ** ghostty_wasm_alloc_opaque | ( | void | ) |
Allocate an opaque pointer. This can be used for any opaque pointer types such as GhosttyKeyEncoder, GhosttyKeyEvent, etc.
| GHOSTTY_API GhosttySgrAttribute * ghostty_wasm_alloc_sgr_attribute | ( | void | ) |
Allocate memory for an SGR attribute (WebAssembly only).
This is a convenience function for WebAssembly environments to allocate memory for an SGR attribute structure that can be passed to ghostty_sgr_next.
| GHOSTTY_API uint16_t * ghostty_wasm_alloc_u16_array | ( | size_t | len | ) |
Allocate an array of uint16_t values.
| len | Number of uint16_t elements to allocate |
| GHOSTTY_API uint8_t * ghostty_wasm_alloc_u8 | ( | void | ) |
Allocate a single uint8_t value.
| GHOSTTY_API uint8_t * ghostty_wasm_alloc_u8_array | ( | size_t | len | ) |
Allocate an array of uint8_t values.
| len | Number of uint8_t elements to allocate |
| GHOSTTY_API size_t * ghostty_wasm_alloc_usize | ( | void | ) |
Allocate a single size_t value.
| GHOSTTY_API void ghostty_wasm_free_opaque | ( | void ** | ptr | ) |
Free an opaque pointer allocated by ghostty_wasm_alloc_opaque().
| ptr | Pointer to free, or NULL (NULL is safely ignored) |
| GHOSTTY_API void ghostty_wasm_free_sgr_attribute | ( | GhosttySgrAttribute * | attr | ) |
Free memory for an SGR attribute (WebAssembly only).
Frees memory allocated by ghostty_wasm_alloc_sgr_attribute.
| attr | Pointer to the attribute structure to free |
| GHOSTTY_API void ghostty_wasm_free_u16_array | ( | uint16_t * | ptr, |
| size_t | len ) |
Free an array allocated by ghostty_wasm_alloc_u16_array().
| ptr | Pointer to the array to free, or NULL (NULL is safely ignored) |
| len | Length of the array (must match the length passed to alloc) |
| GHOSTTY_API void ghostty_wasm_free_u8 | ( | uint8_t * | ptr | ) |
Free a uint8_t allocated by ghostty_wasm_alloc_u8().
| ptr | Pointer to free, or NULL (NULL is safely ignored) |
| GHOSTTY_API void ghostty_wasm_free_u8_array | ( | uint8_t * | ptr, |
| size_t | len ) |
Free an array allocated by ghostty_wasm_alloc_u8_array().
| ptr | Pointer to the array to free, or NULL (NULL is safely ignored) |
| len | Length of the array (must match the length passed to alloc) |
| GHOSTTY_API void ghostty_wasm_free_usize | ( | size_t * | ptr | ) |
Free a size_t allocated by ghostty_wasm_alloc_usize().
| ptr | Pointer to free, or NULL (NULL is safely ignored) |