-
Notifications
You must be signed in to change notification settings - Fork 721
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
sys: add type safe Pointer wrapper #1670
Conversation
d6fc75b
to
1fc7a4f
Compare
The breaking change is due to replacing ebpf.MapID and ProgramID with a type alias. |
1fc7a4f
to
ae08243
Compare
c11a8e0
to
427cfcd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this! More type safety more better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this allow us to unexport sys.Pointer
? Ie. if it needs to be used outside of the package, it needs to be wrapped in an (Unsafe/Typed/String/XYZ)Pointer. Then we make sure UAPI no longer takes any sys.Pointer
s.
I still see a bunch of sys.Pointer
uses in the map API; I'd argue those should all be sys.UnsafePointer
s instead, to be converted to typed pointers before returning.
Add TypedPointer which is a type safe wrapper around Pointer. This relieves users of the generated bindings from knowing which types are expected. This should make it less likely that we cause a hard to debug panic or crash due to the kernel overwriting runtime memory. sys.Pointer still exists because there are some cases where we legitimately don't know what type to point at, for example the link info APIs. Map APIs are also unchanged for now because they don't benefit much from converting to TypedPointer[byte]. The trick to include "_ [0]*T" in TypedPointer is taken from atomic.Pointer in the Go stdlib. Signed-off-by: Lorenz Bauer <[email protected]>
427cfcd
to
fde0d85
Compare
Discussed face to face: UnsafePointer is a constructor, not a type. We still need |
Add TypedPointer which is a type safe wrapper around Pointer. This relieves users of the generated bindings from knowing which types are expected. This should make it less likely that we cause a hard to debug panic or crash due to the kernel overwriting runtime memory.
sys.Pointer still exists because there are some cases where we legitimately don't know what type to point at, for example the link info APIs. Map APIs are also unchanged for now because they don't benefit much from converting to TypedPointer[byte].