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

Support deriving copy for large array #874

Merged
merged 2 commits into from
Aug 1, 2017
Merged

Support deriving copy for large array #874

merged 2 commits into from
Aug 1, 2017

Conversation

WiSaGaN
Copy link
Contributor

@WiSaGaN WiSaGaN commented Aug 1, 2017

Fixes #56

@@ -178,6 +194,7 @@ fn bindgen_test_layout_WithDtor() {
stringify ! ( b ) ));
}
#[repr(C)]
#[derive(Copy)]
pub struct IncompleteArrayNonCopiable {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what to do with this. Change the name?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should really be kept non-copiable though... That's a huge footgun, because incomplete arrays tend to be used to allocate to the end of the object, and copying it would lose the trailing information.

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

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

Well, that was easier than what I'd have expected... r=me

}
#[repr(C)]
pub struct ST<T> {
pub large_array: [T; 33usize],
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, so why did this suddenly start working? There have been multiple refactors of the derive debug code, @fitzgen, do you know which one could cause this?

Copy link
Member

Choose a reason for hiding this comment

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

@emilio I'm unsure what "this" that suddenly started working is? We aren't deriving Debug here, which it seems like you're implying, so I am confused.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant that the length check was effectively fixing that, so it eventually became unneeded, and I wondered if you knew off-hand why :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my memory, deriving Copy was working before bindgen gained the ability to derive Debug. It may as well just be that the implementor treat all derive the same, while not knowing Copy is a special trait to the compiler in regard to large array derive. Should be able to verify this aginst the commit history, but a bit tedious...

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

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

Hmm, actually...

@@ -178,6 +194,7 @@ fn bindgen_test_layout_WithDtor() {
stringify ! ( b ) ));
}
#[repr(C)]
#[derive(Copy)]
pub struct IncompleteArrayNonCopiable {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should really be kept non-copiable though... That's a huge footgun, because incomplete arrays tend to be used to allocate to the end of the object, and copying it would lose the trailing information.

@@ -38,7 +38,7 @@ impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
}
impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
#[repr(C, packed)]
#[derive(Debug, Default, Copy)]
Copy link
Contributor Author

@WiSaGaN WiSaGaN Aug 1, 2017

Choose a reason for hiding this comment

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

Actually bindgen derived Copy for incomplete array even before this change. The reason some of the structs with incomplete array in previous tests have not been deriving Copy is that they also contain large arrays...
This will disallow previous allowed deriving of Copy though if it contains an incomplete array.
So this pull requests now actually makes two conceptually different changes.

Copy link
Member

Choose a reason for hiding this comment

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

Then this was a pretty egregious bug; pretty sad we didn't catch that :(

Definitely shouldn't be deriving Copy for incomplete arrays, as we have no idea what the correct thing to do in the scenario is...

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, we could discern incomplete arrays vs zero-sized arrays that get used as a field separator, but seems safer to just avoid it for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think before variable length array (the name used for incomplete array) gets into C99, zero-sized array is used as a hack to achieve the same effect? If so, maybe we should not assume zero-sized array is not used as incomplete array?

@emilio
Copy link
Contributor

emilio commented Aug 1, 2017

@bors-servo r+

@bors-servo
Copy link

📌 Commit 06b3893 has been approved by emilio

@bors-servo
Copy link

⌛ Testing commit 06b3893 with merge e9b270e...

bors-servo pushed a commit that referenced this pull request Aug 1, 2017
Support deriving copy for large array

Fixes #56
@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: emilio
Pushing e9b270e to master...

@bors-servo bors-servo merged commit 06b3893 into rust-lang:master Aug 1, 2017
@emilio
Copy link
Contributor

emilio commented Aug 1, 2017

Thanks, btw!

@WiSaGaN
Copy link
Contributor Author

WiSaGaN commented Aug 1, 2017

Pleasure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants