-
Notifications
You must be signed in to change notification settings - Fork 186
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
datasource: Allow setting smaller static strings #2832
datasource: Allow setting smaller static strings #2832
Conversation
d5c7b42
to
730edf2
Compare
Hmm... I think we need to add errors to the IMHO this isn't best practice in the first place (editing a statically sized string), but if we allow it, we should at least make sure it's reported if it didn't succeed. |
I totally agree. What do you think about the
I don't see any reason why we should block this. I feel there are use cases where this is valuable. |
Yeah, let's do it - better now than later. I was a bit worried about returning two values, because it might not be compatible with all languages that would compile to WASM - but I think it's better to have a clean implementation on the host and let the guest APIs worry about getting it right there.
I agree, we shouldn't block this. |
730edf2
to
8c0db4e
Compare
Updated the PR to return errors. The code is not as clean as before, but we need it. |
8c0db4e
to
bb9e21d
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.
Thanks for addressing the errors - it's indeed not as clean looking as before, but - well - I guess cleaner working. 🤷
pkg/datasource/accessors.go
Outdated
if len(b) < 1 { | ||
return | ||
return ErrFieldTooShort |
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.
Do you think there are cases when it makes sense to read a Uint8 from something that's larger than 1 byte without specifying an additional offset? Otherwise maybe it's cleaner to just return ErrInvalidFieldLength
and check for len(b) != 1
. Also for the other types.
(Usually I'm not into restricting users from doing weird stuff, but here I don't know...)
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.
Added that check as well. At this point, I'm wondering if we should just check the type of the field instead... (but I'll hold that discussion for a bit).
bb9e21d
to
154c61c
Compare
Update all functions to also return a value, this helps to have a better error handling. Signed-off-by: Mauricio Vásquez <mauriciov@microsoft.com>
There are cases when an operator needs to change the value of a static string (coming from ebpf for instance). This commit ipt improves the logic to allow the operator calling the PutString() method with a string that is smaller than the buffer size. Signed-off-by: Mauricio Vásquez <mauriciov@microsoft.com>
154c61c
to
95117b3
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.
LGTM, thanks for cleaning this up!
type InvalidFieldLengthErr struct { | ||
Expected int | ||
Actual int | ||
} |
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.
Nice!
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 took me quite few iterations to reach this! Glad to see you liked it!
There are cases when an operator needs to change the value of a static string (coming from ebpf for instance). This commit ipt improves the logic to allow the operator calling the PutString() method with a string that is smaller than the buffer size.
I found this issue / limitation when trying to update the name field in wasm in #2823. That PR implements a workaround for it, but IMO it needs to be handled directly in the accessor.
@flyth any opinions on this one?