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

Make euclid types repr(C). #176

Merged
merged 1 commit into from Feb 7, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -33,6 +33,7 @@ use std::fmt;
/// another. See the `ScaleFactor` docs for an example.
// Uncomment the derive, and remove the macro call, once heapsize gets
// PhantomData<T> support.
#[repr(C)]
#[derive(RustcDecodable, RustcEncodable)]
pub struct Length<T, Unit>(pub T, PhantomData<Unit>);

This comment has been minimized.

@emilio

emilio Feb 7, 2017

Member

Note that this is safe, even though rustc will complain about it until rust-lang/rust#39462 lands.

Also, note that depending of the size of T, being Length a struct but T an integer/floating point value, passing Length as an argument instead of T may break the ABI in 32bit linux, etc, see the last comments in rust-lang/rfcs#1758.

I don't think you're going to pass Length directly through, right?


@@ -24,6 +24,9 @@
//! Client code typically creates a set of aliases for each type and doesn't need
//! to deal with the specifics of typed units further. For example:
//!
//! All euclid types are marked #[repr(C)] in order to facilitate exposing them to
//! foreign function interfaces (provided the underlying scalar type is also repr(C)).
//!
//! ```rust
//! use euclid::*;
//! pub struct ScreenSpace;
@@ -14,6 +14,7 @@ macro_rules! define_matrix {
$(pub $field:ident: T,)+
}
) => (
#[repr(C)]
$(#[$attr])*
pub struct $name<T, $($phantom),+> {

This comment has been minimized.

@emilio

emilio Feb 7, 2017

Member

Ditto regarding phantomdata.

$(pub $field: T,)+
@@ -36,6 +36,7 @@ use std::marker::PhantomData;
/// let one_foot: Length<f32, Inch> = Length::new(12.0);
/// let one_foot_in_mm: Length<f32, Mm> = one_foot * mm_per_inch;
/// ```
#[repr(C)]
#[derive(RustcDecodable, RustcEncodable)]
pub struct ScaleFactor<T, Src, Dst>(pub T, PhantomData<(Src, Dst)>);

This comment has been minimized.

@emilio

emilio Feb 7, 2017

Member

And ditto again, similarly to Length.


ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.