-
-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
api/wasm: writeToStorage
defaults to true
, update wasmtic_pmem
signature from i(ii)
to i(iI)
#2362
api/wasm: writeToStorage
defaults to true
, update wasmtic_pmem
signature from i(ii)
to i(iI)
#2362
Conversation
…ure from i(ii) to i(iI)
Wait, why is value a 64 bit number - pmem stores and retrieves 32 bit numbers... it seems like the C code is correct and the Zig API needs to change, no? |
Because a i32 can not represent all u32 numbers + -1, I would personally be fine to have Line 578 in 5061bb2
int32_t , but I suspect others might need to be able to represent all uint32_t values.
Note It is the C code that specifies that it should be 64 bits.. due to not having a boolean for if a write should happen or not. Which in turn naturally forces the Zig API to pass in a i64 as the value.. but since there (If I understand it correctly, is a bug in how the signature is specified in Also note that it is The current template for C imports
|
WASM_IMPORT("pmem") | |
// Access or update the persistent memory. | |
uint32_t pmem(int32_t address, int64_t value); |
Segmentation fault (core dumped)
when calling pmem
(Both with -1
as the value and other values)
With a tic80
binary compiled with the corrected wasmtic_pmem
signature (i(iI)
) it no longer segfaults, and pmem(1, pmem(1,-1)+1);
work as expected (as long as the other bug has been corrected as well, that writeToStorage
wasn't set to true
)
@joshgoebel We can probably disregard that I used #include "tic80.h"
WASM_IMPORT("snprintf")
int snprintf(char* s, size_t n, const char* format, ...);
WASM_EXPORT("BOOT")
void BOOT() {
pmem(1, pmem(1,-1)+1);
}
WASM_EXPORT("TIC")
void TIC() {
cls(13);
char buf[20];
snprintf(buf, 20, "Started %d times", pmem(1,-1));
print(buf, 3, 3, 15, 0, 1, 1);
} Before this fix this results in tic80 --fs . --cli --cmd 'load wasmdemo.wasmp & import binary build/cart.wasm & save game.tic & exit'
tic80 --fs . --cmd 'load game.tic & run & exit' |
The goal here is to always maintain backwards compatibility. If someone is using the existing API, that should continue to work (bugs and all). I think the behavior here should be documented and one of two things happen:
|
@joshgoebel This wouldn't break any compatibility though? (since the function is currently broken in TIC-80, not sure that it has ever worked) (We are only talking about the "pmem" that is exported in WASM, This is strictly a bugfix. (Of two separate bugs: The first that it was impossible to write due to |
Looked through the repo history and these two bugs have been present in |
A valid signature itself can't be "broken". It might be buggy but if anyone has ever successfully linked against it, then changing it breaks their code. You're saying our shipping Zig library breaks out of the box, yes? Even that would be a compromise since it's quite possible to write WASM by hand. And also possible that individual users have patched their libraries to work with the existing buggy API - and just never reported back here. |
Correct me if I'm wrong but if linked correctly the existing binary API works, just limits you to 32 bit signed numbers other than -1. |
Disregard Zig for now, it is broken from C as well (as I noted above) Due to TIC-80/templates/c/src/tic80.h Line 323 in 5061bb2
(And changing value to a |
I believe my point is that it isn't valid. (to have a function with 128 bits of arguments be exported as only having 96) But maybe I've missed something fundamental in why this isn't working. |
No, I believe it to never have worked to call the exported Do you think otherwise? |
Another way to "fix" the problem of not being able to call the exported diff --git a/src/api/wasm.c b/src/api/wasm.c
index 5dfd20f3..f6142536 100644
--- a/src/api/wasm.c
+++ b/src/api/wasm.c
@@ -575,8 +575,8 @@ m3ApiRawFunction(wasmtic_pmem)
m3ApiReturnType (uint32_t)
m3ApiGetArg (int32_t, address)
- m3ApiGetArg (int64_t, value)
- bool writeToStorage;
+ m3ApiGetArg (int32_t, value)
+ bool writeToStorage = true;
tic_mem* tic = (tic_mem*)getWasmCore(runtime); |
The same issues can be seen with code written in
|
I noticed two issues in
src/api/wasm.c
when trying to callpmem
from a small Zig ⚡ program (compiling to.wasm
)writeToStorage
was never set totrue
(unless I've misunderstood the code that is)wasmtic_pmem
indicated that the arguments would be three 32 bit values:i(ii)
, and not two 32 bit (return value andaddress
) + one 64 bit value (forvalue
) as I expected:i(iI)
Related to issue #2360