Closed konsumer closed 1 year ago
char *
by definition has no builtin length, if you want a length you can either pass one or do pascal-style strings. WASM strings are kinda a mess right now.
Yeh, for sure. I see that WASI includes length-param on all of their string-param functions, but I can generally get by with /0
-delimited strings, elsewhere. I was hoping to not have to change my import ABI, but that makes sense.
Like on wasm-side I can change to this, even though I was hoping I could avoid that:
uint32_t font_measure(uint32_t fontID, char* text, uint32_t textLength);
I would put the length first, but yea that would work. Also strlen if you null terminate.
WASM doesn't segment memory at all, you get a buffer. you can even write to NULL
😨... I'm gonna close this issue in a bit unless there's anything else relevant.
So it would look like this?
len = strlen(WEB49_INTERP_ADDR(void *, interp, textPtr, MAX_STRING_SIZE));
Like that macro copies the buffer, so I have to take MAX_STRING_SIZE
, right?
I have a function that takes a string param, like this:
That I am trying to expose, like this:
This works, but seems like the wrong way to me (using max-length of 512 to pull the whole thing.) Is this the right way to pull the string? Is there a better way to get the string-length up-front? Should I rewrite all functions that take string params to include length param, too?