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

hdf: Add support for pointers in NewDataTypeFromType() #15

Merged
merged 2 commits into from May 3, 2018

Conversation

donkahlero
Copy link
Collaborator

This small patch introduces support for pointers to datatypes in the
NewDataTypeFromType function. This enables support for different use
cases, e.g. usage with google.com/gopacket

Co-authored-by: Gustaf Johansson gustaf.j@gmail.com

Copy link
Member

@sbinet sbinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR!

@@ -466,6 +466,9 @@ func NewDataTypeFromType(t reflect.Type) (*Datatype, error) {
}
dt = &cdt.Datatype

case reflect.Ptr:
return NewDataTypeFromType(t.Elem())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if t is *int, this will return the HDF5 DataType for int.
shouldn't we instead return the HDF5 DataType that describes a pointer to int ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type specification is in line with the current implementation of Append:
https://github.com/gonum/hdf5/blob/master/h5pt.go#L193-L195

	case reflect.Ptr:
		ptrVal := rp.Elem()
		cData = unsafe.Pointer(&ptrVal)

If you propose to use H5T_STD_REF_OBJ as a type of *int and then add the actual int to a separate file location the Append function (possibly among many others) would need to be refactored as well.
The change as is now, prevents a panic in default and works as intended.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah. right you are :)

could we add a test exercizing this new code path?
thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the test cases. I think they are testing now the stuff that should be tested.

@donkahlero
Copy link
Collaborator Author

Have you had time to check it out @sbinet? 👻 I think there will be another patch coming in shortly, as well... Support for arrays/slices and nested struct appends. But I want to have that one closed first 😄

Copy link
Member

@sbinet sbinet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with small nit.

@kortschak ?

h5t_test.go Outdated
@@ -65,48 +68,62 @@ func TestStructDatatype(t *testing.T) {

// Test that the type can be constructed and that the number of
// members is as expected.
dtypes := make([]*Datatype, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we usually spell this out as:

var dtypes []*Datatype

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is really pressing, I can obviously fix that one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do.

@donkahlero
Copy link
Collaborator Author

Alrighty. Amended the commit. Is now aligned with your usual spelling.
Do I also need to update the contributors thing for @gustafj or can that wait for the next PR?

@sbinet
Copy link
Member

sbinet commented Apr 25, 2018

Alrighty. Amended the commit. Is now aligned with your usual spelling.

thanks :)

Do I also need to update the contributors thing for @gustafj or can that wait for the next PR?

If I am not mistaken, @gustafj did commit something in the first commit, so, yeah, both of you will need to send a PR against gonum/gonum

@donkahlero
Copy link
Collaborator Author

As I am already in there, it will just be him. Will fix shortly :) Thx!

donkahlero and others added 2 commits April 25, 2018 17:58
This small patch introduces support for pointers to datatypes in the
NewDataTypeFromType function. This enables support for different use
cases, e.g. usage with google.com/gopacket

Co-authored-by: Gustaf Johansson <gustaf@pinon.se>
implementation.

As the current implementation does not allow the usage of H5T_STD_REF_OBJ, these
tests only test for the case of pointers to values in computer memory
(opposed to pointers that point to a location inside an HDF5 file).

Co-authored-by: Gustaf Johansson <gustaf@pinon.se>
@donkahlero
Copy link
Collaborator Author

PR added. + I fixed the commits. :)

@donkahlero
Copy link
Collaborator Author

Just a quick reminder @sbinet :))
Thanks once again that you are so open for the PRs!

@sbinet
Copy link
Member

sbinet commented May 3, 2018

Actually, we are now waiting on @kortschak :)

If he doesn't but by Monday (when I come back from holidays) I'll merge this in.

Copy link
Member

@kortschak kortschak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't realise you were waiting for me.

@sbinet sbinet merged commit 35a19a8 into gonum:master May 3, 2018
@sbinet
Copy link
Member

sbinet commented May 3, 2018

No worries.

@donkahlero donkahlero deleted the ptr_support branch May 8, 2018 07:11
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

Successfully merging this pull request may close these issues.

None yet

4 participants