hdf5
hdf5 copied to clipboard
String in scalar dataset does not appear to work
Hi,
When I try to run this code:
package main
import (
"fmt"
"gonum.org/v1/hdf5"
)
func main() {
hf, err := hdf5.CreateFile("my_string.h5", hdf5.F_ACC_TRUNC)
if err != nil {
fmt.Println("Failed to open file", err)
return
}
dSpaceScalar, err := hdf5.CreateDataspace(hdf5.S_SCALAR)
if err != nil {
fmt.Println("Failed to create dataset", err)
return
}
dSet, err := hf.CreateDataset("string_dataset", hdf5.T_GO_STRING, dSpaceScalar)
if err != nil {
fmt.Println("Failed to create dataset", err)
return
}
someText := "once upon a time"
err = dSet.Write(someText)
if err != nil {
fmt.Println("Failed to write dataset:")
return
}
dSet.Close()
dSpaceScalar.Close()
hf.Close()
fmt.Println("All good. Closed everything")
return
}
I get this error:
./teststring
panic: reflect.Value.UnsafeAddr of unaddressable value
goroutine 1 [running]:
reflect.Value.UnsafeAddr(...)
reflect/value.go:1972
gonum.org/v1/hdf5.(*Dataset).WriteSubset(0xc000098360, 0x4be3c0, 0xc000098370, 0x0, 0x0, 0x0, 0x0)
gonum.org/v1/[email protected]/h5d_dataset.go:130 +0x38b
gonum.org/v1/hdf5.(*Dataset).Write(...)
gonum.org/v1/[email protected]/h5d_dataset.go:154
main.main()
This may be related to this comment in your readme:
Known problems
support for structs with slices and strings as fields is broken
but this obviously isn't a field of a structure.
Thanks,
Matt
I'm not sure how to deal with this. If &someText
is passed in we can get the address of the reflect value, but then we crash with a SEGentering into the C code a few lines down. It's deeper than that too, this is not just a string issue; if I replace someText
with the equivalent byte slice we get the same issues.
/cc @sbinet
It may or may not be useful to know, but it seems that writing attributes as strings seems to work OK, only writing them as dataset fails.