Skip to content

Commit 70dd7bd

Browse files
committed
fix aligment differences in x32 and x64
1 parent 8d7d833 commit 70dd7bd

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
@@ -143,6 +143,11 @@ mod tests {
143143
use super::*;
144144
use iceoryx2_bb_testing::assert_that;
145145

146+
#[cfg(target_pointer_width = "32")]
147+
const ALIGNMENT: usize = 4;
148+
#[cfg(target_pointer_width = "64")]
149+
const ALIGNMENT: usize = 8;
150+
146151
#[test]
147152
fn test_from() {
148153
#[repr(C)]
@@ -158,19 +163,19 @@ mod tests {
158163
variant: TypeVariant::FixedSize,
159164
type_name: "i32".to_string(),
160165
size: 4,
161-
alignment: 4,
166+
alignment: 4, // i32 uses 4 bytes, so its aliment is always 4 no matter x32 or x64.
162167
},
163168
user_header: TypeDetail{
164169
variant: TypeVariant::FixedSize,
165170
type_name: "i64".to_string(),
166171
size: 8,
167-
alignment: 8,
172+
alignment: ALIGNMENT,
168173
},
169174
payload: TypeDetail{
170175
variant: TypeVariant::FixedSize,
171176
type_name: "iceoryx2::service::static_config::message_type_details::tests::test_from::MyPayload".to_string(),
172177
size: 16,
173-
alignment: 8,
178+
alignment: ALIGNMENT,
174179
},
175180
};
176181
assert_that!(sut, eq expected);
@@ -181,7 +186,7 @@ mod tests {
181186
variant: TypeVariant::FixedSize,
182187
type_name: "i32".to_string(),
183188
size: 4,
184-
alignment: 4,
189+
alignment: ALIGNMENT,
185190
},
186191
user_header: TypeDetail {
187192
variant: TypeVariant::FixedSize,
@@ -193,7 +198,7 @@ mod tests {
193198
variant: TypeVariant::Dynamic,
194199
type_name: "&[iceoryx2::service::static_config::message_type_details::tests::test_from::MyPayload]".to_string(),
195200
size: 16,
196-
alignment: 8,
201+
alignment: ALIGNMENT,
197202
},
198203
};
199204
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)