-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Allow usage of char slices in addition to null-terminated strings #53
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
Conversation
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.
These changes make sense to me.
For consistency, I think we also need to add accesskit_macos_add_focus_forwarder_to_window_class_with_length in the macos module.
We also have nul-terminated strings in accesskit_tree and accesskit_custom_action structs though.
Looking back, I think calling CStr::to_string_lossy was not a great idea as it wouldn't panic if given invalid UTF-8 strings, something that UI toolkit developers may not realize until an end-user finds replacement characters in their UI. I think we should panic instead and add a note in the documentation of every functions taking a string parameter that valid UTF-8 strings are expected. Something easy you can do in another PR if you're interested, otherwise I'll do it myself later.
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 didn't expect you to handle accesskit_custom_action as part of this PR, sorry if this wasn't clear. Please revert these changes.
You should add the same notice on the new functions:
Caller is responsible for freeing the memory pointed by `value`.
|
I don't see the comment here so maybe you figured it out yourself, just in case:
Users must never do that. This is bad for at least two reasons: there would be no way of knowing what would be freed exactly, but it would likely try to mess up the memory adjacent to the slice until a zero byte is encountered. Secondly, the slice would not have been allocated by Rust so there is a chance that it was allocated by a different memory allocator, that could have nasty consequences as well. |
|
I deleted the comment because I realized the better way to deal with I can remove |
|
I'd like you to remove the new constructor because I think the API for |
|
Thanks @TheZipCreator for this contribution. I'd like to have this for the next release so I'm doing the final changes myself. Please note that this pull request got closed by GitHub as I had to rebase your main branch. I'll add you as co-author on the other pull request. In the future, please do not open pull requests from the main branch of your fork. |
This makes it so you can use strings that don't necessarily end with a null terminator. Useful for C libraries that offer that kind of API, or for bindings to languages other than C through the C binding.
Note: I'm not a Rust programmer, so I'm not sure if my implementation is the best (or most correct) one, but it seems to work.