vt: simplify ghostty_type_json to return null-terminated string

The function previously took a size_t* out-parameter for the string
length. Since the JSON blob is now null-terminated, the len parameter
is unnecessary. Remove it from the Zig implementation, C header, and
the WASM example consumer which no longer needs to allocate and free
a usize just to read the length.
This commit is contained in:
Mitchell Hashimoto
2026-03-30 10:12:07 -07:00
parent 6479d90ca5
commit 0c38e8be60
3 changed files with 14 additions and 19 deletions

View File

@@ -138,12 +138,11 @@
wasmMemory = wasmInstance.exports.memory;
// Load the type layout JSON from the library
const lenPtr = wasmInstance.exports.ghostty_wasm_alloc_usize();
const jsonPtr = wasmInstance.exports.ghostty_type_json(lenPtr);
const jsonLen = new DataView(wasmMemory.buffer).getUint32(lenPtr, true);
wasmInstance.exports.ghostty_wasm_free_usize(lenPtr);
const jsonBytes = new Uint8Array(wasmMemory.buffer, jsonPtr, jsonLen);
typeLayout = JSON.parse(new TextDecoder().decode(jsonBytes));
const jsonPtr = wasmInstance.exports.ghostty_type_json();
const jsonStr = new TextDecoder().decode(
new Uint8Array(wasmMemory.buffer, jsonPtr, wasmMemory.buffer.byteLength - jsonPtr)
).split('\0')[0];
typeLayout = JSON.parse(jsonStr);
return true;
} catch (e) {