Skip to content

Commit 85c45ce

Browse files
committed
fix aligment differences in x32 and x64
1 parent 10ae9fd commit 85c45ce

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

iceoryx2/src/service/static_config/message_type_details.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ mod tests {
151151
use super::*;
152152
use iceoryx2_bb_testing::assert_that;
153153

154+
#[cfg(target_pointer_width = "32")]
155+
const ALIGNMENT: usize = 4;
156+
#[cfg(target_pointer_width = "64")]
157+
const ALIGNMENT: usize = 8;
158+
154159
#[test]
155160
fn test_from() {
156161
#[repr(C)]
@@ -166,19 +171,19 @@ mod tests {
166171
variant: TypeVariant::FixedSize,
167172
type_name: "i32".to_string(),
168173
size: 4,
169-
alignment: 4,
174+
alignment: 4, // i32 uses 4 bytes, so its aliment is always 4 no matter x32 or x64.
170175
},
171176
user_header: TypeDetail{
172177
variant: TypeVariant::FixedSize,
173178
type_name: "i64".to_string(),
174179
size: 8,
175-
alignment: 8,
180+
alignment: ALIGNMENT,
176181
},
177182
payload: TypeDetail{
178183
variant: TypeVariant::FixedSize,
179184
type_name: "iceoryx2::service::static_config::message_type_details::tests::test_from::MyPayload".to_string(),
180185
size: 16,
181-
alignment: 8,
186+
alignment: ALIGNMENT,
182187
},
183188
};
184189
assert_that!(sut, eq expected);
@@ -189,7 +194,7 @@ mod tests {
189194
variant: TypeVariant::FixedSize,
190195
type_name: "i32".to_string(),
191196
size: 4,
192-
alignment: 4,
197+
alignment: ALIGNMENT,
193198
},
194199
user_header: TypeDetail {
195200
variant: TypeVariant::FixedSize,
@@ -201,7 +206,7 @@ mod tests {
201206
variant: TypeVariant::Dynamic,
202207
type_name: "&[iceoryx2::service::static_config::message_type_details::tests::test_from::MyPayload]".to_string(),
203208
size: 16,
204-
alignment: 8,
209+
alignment: ALIGNMENT,
205210
},
206211
};
207212
assert_that!(sut, eq expected);

iceoryx2/tests/service_static_config_tests.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ mod service_static_config_message_type_details {
1515
use iceoryx2::service::static_config::message_type_details::{TypeDetail, TypeVariant};
1616
use iceoryx2_bb_testing::assert_that;
1717

18+
#[cfg(target_pointer_width = "32")]
19+
const ALIGNMENT: usize = 4;
20+
#[cfg(target_pointer_width = "64")]
21+
const ALIGNMENT: usize = 8;
22+
1823
#[test]
1924
fn test_internal_new() {
2025
#[repr(C)]
@@ -33,7 +38,7 @@ mod service_static_config_message_type_details {
3338
variant: TypeVariant::FixedSize,
3439
type_name: "i64".to_string(),
3540
size: 8,
36-
alignment: 8,
41+
alignment: ALIGNMENT,
3742
};
3843

3944
assert_that!(sut, eq expected);
@@ -44,7 +49,7 @@ mod service_static_config_message_type_details {
4449
type_name: "iceoryx2::service::static_config::message_type_details::TypeDetail"
4550
.to_string(),
4651
size: 48,
47-
alignment: 8,
52+
alignment: ALIGNMENT,
4853
};
4954

5055
assert_that!(sut, eq expected);

0 commit comments

Comments
 (0)