Avoid writing Go pointers to non Go memory #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, thank you for this wrapper! I've been using it on and off for a while, and for me it seems to work as intended for the most part. However, in some situations, I ended up with segmentation faults without any good explanation why.
Yesterday I decided to take a look by using cgo and gc debug flags, and found out that this wrapper passes in Go pointers to C. Passing Go pointers to C isn't allowed because Go's garbage collector may kick in at any time. I couldn't see any other backwards compatible way to do this except copying the slice contents into C memory.
I also did a best effort attempt to clean up C memory after use, although I am not aware of how all the options work. At least one of the pointers –
holelist
- were copied to the out struct, and that caused issues with double freeing. I wouldn't be surprised if this could be a problem with other allocated memory blocks. There's no double free with the default helper functions, but I guess other flags/options could trigger return values that would be double free'd. This would be a lot simpler if the functions calling triangle either gathered all input/output in a single struct, or did not expose cleanup. However, that would break backwards compatibility.Finally, Go complained so much about no Go module file that I added an empty one – hopefully that's fine.