-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(go): avoid using
unsafe.Pointer
for passing handles (#195)
Functions that receive a `void*` in the C world must be called with an `unsafe.Pointer` from the Go world. However, we are not really passing a pointer, but a "handle", and coercing a handle into an `unsafe.Pointer` is problematic (`go vet` complains with "possible misuse of unsafe.Pointer", and it could cause a panic as described in https://i.hsfzxjy.site/invalid-pointer-will-bite-you/). The solution is introducing small C stub functions that receive an `uintptr_t` instead of a `void*`, and the call the original function, casting the `uintptr_t` into `void*`.
- Loading branch information
Showing
4 changed files
with
50 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,4 +72,4 @@ func Example_compilerAndScanner() { | |
// Output: | ||
// rule foo matched | ||
// rule bar matched | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters