-
Notifications
You must be signed in to change notification settings - Fork 33
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
hdf5: figure out how to resolve the Go pointer to Go pointer issue #12
Comments
for gopy, I opted for the following:
|
In gopy, you still required I do not see how this approach fixes the problem though. The runtime will call the cgo pointer check at some point, and any pointer hiding just pushes the problem into harder to debug areas. The issue that raised this is the @ianlancetaylor, do you have any suggestions for how to deal with this kind of a problem. The relevant type is |
yes, |
@kortschak If Python does not examine the contents of the Go value, and doesn't do anything with it other than pass it back to Go, then it seems to me that the scheme that @sbinet outlines will work. You can see a roughly similar scheme at https://github.com/swig/swig/blob/master/Lib/go/goruntime.swg#L418 , used to pass Go values through C++ code. |
The issue here is not with python, but with HDF5. The HDF5 routine needs to read the data pointed to by the Go pointer in pointer in order to be able to serialise it in the HDF5 file. The HDF5 call in the Go wrapper passes what is essentially an opaque pointer with another parameter explaining how to handle it. The HDF5 code does not call back into Go. |
OK, if I understand that correctly, then the only way to handle it is to copy the data into memory allocated by |
That's what I thought. This is going to be unpleasant. |
@ianlancetaylor, to follow this up, I'd like to clarify the position on having a C pointer, backed by an allocation be Concretely:
If this is OK, it would solve partially the problem, unless there is nesting, at which point we really just need to recursively copy the data to C-allocated memory (which I think is what we will have to do in the long run). |
That is not OK, because it is never OK to store a Go pointer into C memory (where the definition of a Go pointer is a pointer to memory allocated by the Go memory allocator, and the definition of C memory is memory allocated by the C memory allocator). It may or may not help to read https://github.com/golang/proposal/blob/master/design/12416-cgo-pointers.md . |
Thanks. I figured that, but wanted to check. I guess that leaves us with the task of writing a generic deep copy function from Go to C memory. I have read that proposal in the past, but probably should re-read it. |
@sbinet @TacoVox While I was looking at the finalizer problem I was also consider what we will do here. We need a deep copy routine for moving Go<->C, but we don't always need to use it; in the case of structs of arrays or structs of simple types there is no need for the copy. I added some code to the The read operation is more complicated since we don't start with a known Go data structure; the first operation is an Does this sound reasonable? The copy should be reasonably straightforward since we are not handling map types. It's just a walk and retaining a map of visited |
SGTM 👍 |
The
GODEBUG=cgocheck=0
incantation is untenable in the long run. So we need to sort out how to deal with types holding pointers.It is not clear to me how to deal with this using the current approach to calling HDF5 functions where entire values are simply handed off to the library. But anything else involves significant reengineering/reimplementation of the HDF5 code in Go.
Note that the example in the tests that fails this runtime check is already incorrect, since the string field that causes the failure is not correctly round-tripped anyway.
The text was updated successfully, but these errors were encountered: