interp: fix reading from external global

This fixes https://github.com/tinygo-org/tinygo/issues/3020.
Этот коммит содержится в:
Ayke van Laethem 2022-09-15 16:18:15 +02:00 коммит произвёл Ron Evans
родитель 5f96d2b784
коммит 9e4e182615
3 изменённых файлов: 9 добавлений и 0 удалений

Просмотреть файл

@ -369,6 +369,11 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
nBytes := uint32(operands[3].Uint()) nBytes := uint32(operands[3].Uint())
dstObj := mem.getWritable(dst.index()) dstObj := mem.getWritable(dst.index())
dstBuf := dstObj.buffer.asRawValue(r) dstBuf := dstObj.buffer.asRawValue(r)
if mem.get(src.index()).buffer == nil {
// Looks like the source buffer is not defined.
// This can happen with //extern or //go:embed.
return nil, mem, r.errorAt(inst, errUnsupportedRuntimeInst)
}
srcBuf := mem.get(src.index()).buffer.asRawValue(r) srcBuf := mem.get(src.index()).buffer.asRawValue(r)
copy(dstBuf.buf[dst.offset():dst.offset()+nBytes], srcBuf.buf[src.offset():]) copy(dstBuf.buf[dst.offset():dst.offset()+nBytes], srcBuf.buf[src.offset():])
dstObj.buffer = dstBuf dstObj.buffer = dstBuf

3
testdata/embed/embed.go предоставленный
Просмотреть файл

@ -20,9 +20,12 @@ var (
//go:embed a/b/.hidden //go:embed a/b/.hidden
var hidden string var hidden string
var helloStringBytes = []byte(helloString)
func main() { func main() {
println("string:", strings.TrimSpace(helloString)) println("string:", strings.TrimSpace(helloString))
println("bytes:", strings.TrimSpace(string(helloBytes))) println("bytes:", strings.TrimSpace(string(helloBytes)))
println("[]byte(string):", strings.TrimSpace(string(helloStringBytes)))
println("files:") println("files:")
readFiles(".") readFiles(".")
} }

1
testdata/embed/out.txt предоставленный
Просмотреть файл

@ -1,5 +1,6 @@
string: hello world! string: hello world!
bytes: hello world! bytes: hello world!
[]byte(string): hello world!
files: files:
- a - a
- a/b - a/b