From 9b8076e179b1590e3525bd0220cdcf50253188e8 Mon Sep 17 00:00:00 2001 From: Jameson Ernst Date: Sun, 1 Mar 2015 12:50:17 -0800 Subject: [PATCH] Add #[repr(C)] to structs likely to be used in ffi --- src/structs/iso.rs | 3 +++ src/structs/mat.rs | 7 +++++++ src/structs/pnt.rs | 7 +++++++ src/structs/quat.rs | 2 ++ src/structs/rot.rs | 3 +++ src/structs/vec.rs | 7 +++++++ 6 files changed, 29 insertions(+) diff --git a/src/structs/iso.rs b/src/structs/iso.rs index fb790688..5d5e6a92 100644 --- a/src/structs/iso.rs +++ b/src/structs/iso.rs @@ -23,6 +23,7 @@ use quickcheck::{Arbitrary, Gen}; /// /// This is the composition of a rotation followed by a translation. /// Isometries conserve angles and distances, hence do not allow shearing nor scaling. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Debug, Copy)] pub struct Iso2 { /// The rotation applicable by this isometry. @@ -35,6 +36,7 @@ pub struct Iso2 { /// /// This is the composition of a rotation followed by a translation. /// Isometries conserve angles and distances, hence do not allow shearing nor scaling. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Debug, Copy)] pub struct Iso3 { /// The rotation applicable by this isometry. @@ -46,6 +48,7 @@ pub struct Iso3 { /// Four dimensional isometry. /// /// Isometries conserve angles and distances, hence do not allow shearing nor scaling. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Debug, Copy)] pub struct Iso4 { /// The rotation applicable by this isometry. diff --git a/src/structs/mat.rs b/src/structs/mat.rs index 5def5f5b..493250ff 100644 --- a/src/structs/mat.rs +++ b/src/structs/mat.rs @@ -21,6 +21,7 @@ use quickcheck::{Arbitrary, Gen}; /// Special identity matrix. All its operation are no-ops. +#[repr(C)] #[derive(Eq, PartialEq, RustcDecodable, Clone, Debug, Copy)] pub struct Identity; @@ -33,6 +34,7 @@ impl Identity { } /// Square matrix of dimension 1. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Mat1 { pub m11: N @@ -79,6 +81,7 @@ arbitrary_impl!(Mat1, m11); rand_impl!(Mat1, m11); /// Square matrix of dimension 2. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Mat2 { pub m11: N, pub m21: N, @@ -129,6 +132,7 @@ arbitrary_impl!(Mat2, m11, m12, m21, m22); rand_impl!(Mat2, m11, m12, m21, m22); /// Square matrix of dimension 3. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Mat3 { pub m11: N, pub m21: N, pub m31: N, @@ -221,6 +225,7 @@ rand_impl!(Mat3, ); /// Square matrix of dimension 4. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Mat4 { pub m11: N, pub m21: N, pub m31: N, pub m41: N, @@ -333,6 +338,7 @@ rand_impl!(Mat4, ); /// Square matrix of dimension 5. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Mat5 { pub m11: N, pub m21: N, pub m31: N, pub m41: N, pub m51: N, @@ -461,6 +467,7 @@ rand_impl!(Mat5, ); /// Square matrix of dimension 6. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Mat6 { pub m11: N, pub m21: N, pub m31: N, pub m41: N, pub m51: N, pub m61: N, diff --git a/src/structs/pnt.rs b/src/structs/pnt.rs index 4dfde695..cca26e5d 100644 --- a/src/structs/pnt.rs +++ b/src/structs/pnt.rs @@ -19,6 +19,7 @@ use quickcheck::{Arbitrary, Gen}; /// Point of dimension 0. +#[repr(C)] #[derive(Eq, PartialEq, Clone, Debug, Copy)] pub struct Pnt0(pub PhantomData); @@ -37,6 +38,7 @@ impl Pnt0 { } /// Point of dimension 1. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Pnt1 { /// First component of the point. @@ -77,6 +79,7 @@ arbitrary_pnt_impl!(Pnt1, x); rand_impl!(Pnt1, x); /// Point of dimension 2. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Pnt2 { /// First component of the point. @@ -119,6 +122,7 @@ arbitrary_pnt_impl!(Pnt2, x, y); rand_impl!(Pnt2, x, y); /// Point of dimension 3. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Pnt3 { /// First component of the point. @@ -163,6 +167,7 @@ arbitrary_pnt_impl!(Pnt3, x, y, z); rand_impl!(Pnt3, x, y, z); /// Point of dimension 4. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Pnt4 { /// First component of the point. @@ -209,6 +214,7 @@ arbitrary_pnt_impl!(Pnt4, x, y, z, w); rand_impl!(Pnt4, x, y, z, w); /// Point of dimension 5. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Pnt5 { /// First component of the point. @@ -257,6 +263,7 @@ arbitrary_pnt_impl!(Pnt5, x, y, z, w, a); rand_impl!(Pnt5, x, y, z, w, a); /// Point of dimension 6. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Pnt6 { /// First component of the point. diff --git a/src/structs/quat.rs b/src/structs/quat.rs index 98afa714..509c42f1 100644 --- a/src/structs/quat.rs +++ b/src/structs/quat.rs @@ -20,6 +20,7 @@ use quickcheck::{Arbitrary, Gen}; /// A quaternion. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Quat { /// The scalar component of the quaternion. @@ -158,6 +159,7 @@ impl + BaseFloat> Div> for Quat { /// A unit quaternion that can represent a 3D rotation. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct UnitQuat { q: Quat diff --git a/src/structs/rot.rs b/src/structs/rot.rs index 95e75786..aec6f9d6 100644 --- a/src/structs/rot.rs +++ b/src/structs/rot.rs @@ -16,6 +16,7 @@ use quickcheck::{Arbitrary, Gen}; /// Two dimensional rotation matrix. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Debug, Hash, Copy)] pub struct Rot2 { submat: Mat2 @@ -101,6 +102,7 @@ impl> Arbitrary for Rot2 { * 3d rotation */ /// Three dimensional rotation matrix. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Debug, Hash, Copy)] pub struct Rot3 { submat: Mat3 @@ -306,6 +308,7 @@ impl Arbitrary for Rot3 { /// Four dimensional rotation matrix. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Debug, Hash, Copy)] pub struct Rot4 { submat: Mat4 diff --git a/src/structs/vec.rs b/src/structs/vec.rs index f8a52c00..be3cf7f2 100644 --- a/src/structs/vec.rs +++ b/src/structs/vec.rs @@ -21,6 +21,7 @@ use quickcheck::{Arbitrary, Gen}; /// Vector of dimension 0. +#[repr(C)] #[derive(Eq, PartialEq, Clone, Debug, Copy)] pub struct Vec0(pub PhantomData); @@ -39,6 +40,7 @@ impl Vec0 { } /// Vector of dimension 1. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Vec1 { /// First component of the vector. @@ -90,6 +92,7 @@ arbitrary_impl!(Vec1, x); rand_impl!(Vec1, x); /// Vector of dimension 2. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Vec2 { /// First component of the vector. @@ -143,6 +146,7 @@ arbitrary_impl!(Vec2, x, y); rand_impl!(Vec2, x, y); /// Vector of dimension 3. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Vec3 { /// First component of the vector. @@ -199,6 +203,7 @@ rand_impl!(Vec3, x, y, z); /// Vector of dimension 4. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Vec4 { /// First component of the vector. @@ -256,6 +261,7 @@ arbitrary_impl!(Vec4, x, y, z, w); rand_impl!(Vec4, x, y, z, w); /// Vector of dimension 5. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Vec5 { /// First component of the vector. @@ -315,6 +321,7 @@ arbitrary_impl!(Vec5, x, y, z, w, a); rand_impl!(Vec5, x, y, z, w, a); /// Vector of dimension 6. +#[repr(C)] #[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Debug, Copy)] pub struct Vec6 { /// First component of the vector.