String in scalar dataset does not appear to work
- Dominant language
- Go
- Stars
- 135
- Forks
- 34
- PR merge metrics
- No merged PRs in 30d
Description
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/hdf5@v0.0.0-20200504100616-496fefe91614/h5d_dataset.go:130 +0x38b
gonum.org/v1/hdf5.(*Dataset).Write(...)
gonum.org/v1/hdf5@v0.0.0-20200504100616-496fefe91614/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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in h5d_dataset.go at Dataset.WriteSubset, which the stack trace identifies as the failing entry point, and compare its handling of the scalar string passed through Dataset.Write. The issue is resolved when the supplied example writes the scalar string without the reflect panic and the resulting dataset can be used successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100