Skip to content
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

glib: Add various IntoStrV impls #977

Merged
merged 1 commit into from Feb 10, 2023
Merged

Conversation

sdroege
Copy link
Member

@sdroege sdroege commented Feb 10, 2023

And don't copy any strings in the ones for containers of already NUL-terminated strings.

Fixes #976

And don't copy any strings in the ones for containers of already
`NUL`-terminated strings.

Fixes gtk-rs#976
@@ -1151,7 +1241,8 @@ impl<const N: usize> IntoStrV for [GString; N] {
let mut strs = ptrs.add(self.len() + 1) as *mut c_char;

for (i, item) in self.iter().enumerate() {
ptr::copy_nonoverlapping(item.as_ptr(), strs, item.len() + 1);
ptr::copy_nonoverlapping(item.as_ptr() as *const _, strs, item.len());
*strs.add(item.len()) = 0;
*ptrs.add(i) = strs;
strs = strs.add(item.len() + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we care about alignment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

char arrays have an alignment of 1 so that's fine here. But that's exactly why the pointers come first and afterwards the characters :)

@sdroege sdroege merged commit 14b4563 into gtk-rs:master Feb 10, 2023
@sdroege sdroege deleted the more-intostrv-impls branch February 10, 2023 19:01
@pbor pbor added backported PR was backported to the current stable branch and removed needs-backport PR needs backporting to the current stable branch labels Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported PR was backported to the current stable branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST] Add more implementations of IntoStrV, IntoOptionalGStr etc
3 participants