I was just trying get started with the library iterating over a file and printing the values. Got very a very odd error message. I have distilled it down to this:
package main
import (
"fmt"
"sndfile"
)
const bufferSize = 1024
func main() {
// The location of a test file shipped with sndfile
inp := "/Users/joe/personal/go/src/sndfile/test/funky.aiff"
var info sndfile.Info
soundFile, err := sndfile.Open(inp, sndfile.Read, &info)
if err != nil {
return
}
defer soundFile.Close()
numRead := int64(-1)
realBufferSize := bufferSize * info.Channels
buffer := make([]float32, realBufferSize)
for numRead != 0 {
numRead, err = soundFile.ReadItems(buffer)
fmt.Println("LOOP")
}
}
$ go run /tmp/breaking.go
LOOP
unexpected fault address 0x3f000000
throw: fault
[signal 0xb code=0x1 addr=0x3f000000 pc=0x8e47]
goroutine 1 [running]:
fmt.(*fmt).padString(0xf84005a048, 0x9ea8c, 0x4, 0x9ea8c)
/usr/local/go/src/pkg/fmt/format.go:138 +0x106
fmt.(*fmt).fmt_s(0xf84005a048, 0x9ea8c, 0x4, 0x61288)
/usr/local/go/src/pkg/fmt/format.go:285 +0x60
fmt.(*pp).fmtString(0xf84005a000, 0x9ea8c, 0xf800000004, 0x76, 0x4, ...)
/usr/local/go/src/pkg/fmt/print.go:533 +0xf1
fmt.(*pp).printField(0xf84005a000, 0x61288, 0xf840030270, 0x76, 0x0, ...)
/usr/local/go/src/pkg/fmt/print.go:776 +0xa9d
fmt.(*pp).doPrint(0xf84005a000, 0x2577f70, 0x100000001, 0x101, 0x106fa0, ...)
/usr/local/go/src/pkg/fmt/print.go:1110 +0x1f5
fmt.Fprintln(0xf84002fbd0, 0xf84003d008, 0x2577f70, 0x100000001, 0xf84003d008, ...)
/usr/local/go/src/pkg/fmt/print.go:279 +0x6c
fmt.Println(0x2577f70, 0x100000001, 0x504f4f4c00000004, 0x0, 0x0, ...)
/usr/local/go/src/pkg/fmt/print.go:289 +0x7b
main.main()
/tmp/breaking.go:32 +0x209
goroutine 2 [syscall]:
created by runtime.main
/private/tmp/bindist454984655/go/src/pkg/runtime/proc.c:221
exit status 2
There is some kind of problem when fmt.Println is called in the second run of the loop. Mac OS 10.6.8, go1.0.2, libsndfile latest from macports.
I am completely puzzled by this. I can't form a connection between using unsafe C functions and the fmt library. I've had a look at the gosndfile code and can't see anything obviously wrong. The line in question, /usr/local/go/src/pkg/fmt/format.go:138, is this:
Perhaps there's a per-go-routine allocated buffer that's being overwritten? Perhaps the const text "LOOP" is being scribbled over? I can only guess.
If you remove the fmt.Println the sample runs fine.