kelindar/binary

cannot use l (variable of type int) as uintptr value in assignment

gggrafff opened this issue · 3 comments

Hello!
I'm trying to compile encoding+deconidng code to wasi targert with tinygo 0.30.0 and have the following errors:

$ make
tinygo build -o main.wasm -target ./target.json -opt=2 -gc=precise .
# github.com/kelindar/binary
../../../../go/pkg/mod/github.com/kelindar/binary@v1.0.18/convert.go:24:19: cannot use l (variable of type int) as uintptr value in assignment
../../../../go/pkg/mod/github.com/kelindar/binary@v1.0.18/convert.go:25:19: cannot use l (variable of type int) as uintptr value in assignment
make: *** [Makefile:17: main.wasm] Error 1

My target.json:

{
    "inherits": [ "wasi" ],
    "ldflags": [
        "--initial-memory=2097152",
        "--max-memory=67108864",
        "-zstack-size=65536"
    ]
}

It looks like an easy problem, let's fix it :-)

Oh, I took a closer look, probably this is a tinygo problem, because their SliceHeader implementation differs from the standard one
But if you have an idea how to make a portable code, please let me know

tinygo-org/tinygo#3372
tinygo-org/tinygo#1284
tinygo-org/tinygo-site#346

UPD:
It looks like unsafe.Slice is more portable option of unsafe.SliceHeader. Maybe we can use it?

Sounds great, feel free to submit a PR 🙏🏻

Which version of golang you are using?
unsafe.Slice is a new feature, if your go is old, we need something like this: https://stackoverflow.com/a/59210739/12903113

UPD: I see: https://github.com/kelindar/binary/blob/3a4b1f08e35cb98743e5ce84572f3a92aca97e1c/go.mod#L3C1-L3C8