Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String in scalar dataset does not appear to work #79

Open
darkstar007 opened this issue Mar 31, 2021 · 2 comments
Open

String in scalar dataset does not appear to work #79

darkstar007 opened this issue Mar 31, 2021 · 2 comments

Comments

@darkstar007
Copy link

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

@kortschak
Copy link
Member

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

@darkstar007
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants