gpt4 book ai didi

go - LinkError : WebAssembly. instantiate() : Import #. .. 模块 ="env"函数 ="memcpy"错误:函数导入需要可调用

转载 作者:行者123 更新时间:2023-12-01 22:27:45 29 4
gpt4 key购买 nike

我正在构建一个 Go wasm 模块(用 TinyGo 编译),它编译得很好。但是当我尝试在浏览器中运行它时,我得到了上述错误。

最佳答案

使用 workaround post in the bug report 解决, 如果是使用 sha256.Sum 引起的,你可以修复这个错误。或 sha256.Write通过编辑 $GOROOT/src/crypto/sha256/sha256block.go 中的函数到:

func blockGeneric(dig *digest, p []byte) {
var w [64]uint32
h0, h1, h2, h3, h4, h5, h6, h7 := dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7]
for WorkAround1 := 0; WorkAround1 < len(p); WorkAround1 += chunk {
WorkAround2 := p[WorkAround1:]
//for len(p) >= chunk {
// Can interlace the computation of w with the
// rounds below if needed for speed.
for i := 0; i < 16; i++ {
j := i * 4
w[i] = uint32(WorkAround2[j])<<24 | uint32(WorkAround2[j+1])<<16 | uint32(WorkAround2[j+2])<<8 | uint32(WorkAround2[j+3])
}
for i := 16; i < 64; i++ {
v1 := w[i-2]
t1 := (v1>>17 | v1<<(32-17)) ^ (v1>>19 | v1<<(32-19)) ^ (v1 >> 10)
v2 := w[i-15]
t2 := (v2>>7 | v2<<(32-7)) ^ (v2>>18 | v2<<(32-18)) ^ (v2 >> 3)
w[i] = t1 + w[i-7] + t2 + w[i-16]
}

a, b, c, d, e, f, g, h := h0, h1, h2, h3, h4, h5, h6, h7

for i := 0; i < 64; i++ {
t1 := h + ((e>>6 | e<<(32-6)) ^ (e>>11 | e<<(32-11)) ^ (e>>25 | e<<(32-25))) + ((e & f) ^ (^e & g)) + _K[i] + w[i]

t2 := ((a>>2 | a<<(32-2)) ^ (a>>13 | a<<(32-13)) ^ (a>>22 | a<<(32-22))) + ((a & b) ^ (a & c) ^ (b & c))

h = g
g = f
f = e
e = d + t1
d = c
c = b
b = a
a = t1 + t2
}

h0 += a
h1 += b
h2 += c
h3 += d
h4 += e
h5 += f
h6 += g
h7 += h
//p = p[chunk:]
}

dig.h[0], dig.h[1], dig.h[2], dig.h[3], dig.h[4], dig.h[5], dig.h[6], dig.h[7] = h0, h1, h2, h3, h4, h5, h6, h7

}

关于go - LinkError : WebAssembly. instantiate() : Import #. .. 模块 ="env"函数 ="memcpy"错误:函数导入需要可调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58895956/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com