Skip to content

Commit

Permalink
Generate ptr::null rather than zero literal
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird committed Nov 19, 2017
1 parent 5e0cf9c commit 430fb0e
Show file tree
Hide file tree
Showing 189 changed files with 1,233 additions and 905 deletions.
2 changes: 1 addition & 1 deletion src/codegen/mod.rs
Expand Up @@ -1791,7 +1791,7 @@ impl CodeGenerator for CompInfo {
Some(quote! {
assert_eq!(
unsafe {
&(*(0 as *const #canonical_ident)).#field_name as *const _ as usize
&(*(::#prefix::ptr::null::<#canonical_ident>())).#field_name as *const _ as usize
},
#field_offset,
concat!("Offset of field: ", stringify!(#canonical_ident), "::", stringify!(#field_name))
Expand Down
32 changes: 20 additions & 12 deletions tests/expectations/tests/16-byte-alignment.rs
Expand Up @@ -44,7 +44,8 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(0 as *const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)).dport as *const _ as usize
&(*(::std::ptr::null::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>())).dport as *const _
as usize
},
0usize,
concat!(
Expand All @@ -56,7 +57,8 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(0 as *const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)).sport as *const _ as usize
&(*(::std::ptr::null::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>())).sport as *const _
as usize
},
2usize,
concat!(
Expand All @@ -80,7 +82,9 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() {
concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1))
);
assert_eq!(
unsafe { &(*(0 as *const rte_ipv4_tuple__bindgen_ty_1)).sctp_tag as *const _ as usize },
unsafe {
&(*(::std::ptr::null::<rte_ipv4_tuple__bindgen_ty_1>())).sctp_tag as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
Expand Down Expand Up @@ -108,7 +112,7 @@ fn bindgen_test_layout_rte_ipv4_tuple() {
concat!("Alignment of ", stringify!(rte_ipv4_tuple))
);
assert_eq!(
unsafe { &(*(0 as *const rte_ipv4_tuple)).src_addr as *const _ as usize },
unsafe { &(*(::std::ptr::null::<rte_ipv4_tuple>())).src_addr as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
Expand All @@ -118,7 +122,7 @@ fn bindgen_test_layout_rte_ipv4_tuple() {
)
);
assert_eq!(
unsafe { &(*(0 as *const rte_ipv4_tuple)).dst_addr as *const _ as usize },
unsafe { &(*(::std::ptr::null::<rte_ipv4_tuple>())).dst_addr as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
Expand Down Expand Up @@ -173,7 +177,8 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(0 as *const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)).dport as *const _ as usize
&(*(::std::ptr::null::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>())).dport as *const _
as usize
},
0usize,
concat!(
Expand All @@ -185,7 +190,8 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(0 as *const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)).sport as *const _ as usize
&(*(::std::ptr::null::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>())).sport as *const _
as usize
},
2usize,
concat!(
Expand All @@ -209,7 +215,9 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() {
concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1))
);
assert_eq!(
unsafe { &(*(0 as *const rte_ipv6_tuple__bindgen_ty_1)).sctp_tag as *const _ as usize },
unsafe {
&(*(::std::ptr::null::<rte_ipv6_tuple__bindgen_ty_1>())).sctp_tag as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
Expand Down Expand Up @@ -237,7 +245,7 @@ fn bindgen_test_layout_rte_ipv6_tuple() {
concat!("Alignment of ", stringify!(rte_ipv6_tuple))
);
assert_eq!(
unsafe { &(*(0 as *const rte_ipv6_tuple)).src_addr as *const _ as usize },
unsafe { &(*(::std::ptr::null::<rte_ipv6_tuple>())).src_addr as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
Expand All @@ -247,7 +255,7 @@ fn bindgen_test_layout_rte_ipv6_tuple() {
)
);
assert_eq!(
unsafe { &(*(0 as *const rte_ipv6_tuple)).dst_addr as *const _ as usize },
unsafe { &(*(::std::ptr::null::<rte_ipv6_tuple>())).dst_addr as *const _ as usize },
16usize,
concat!(
"Offset of field: ",
Expand Down Expand Up @@ -277,7 +285,7 @@ fn bindgen_test_layout_rte_thash_tuple() {
concat!("Size of: ", stringify!(rte_thash_tuple))
);
assert_eq!(
unsafe { &(*(0 as *const rte_thash_tuple)).v4 as *const _ as usize },
unsafe { &(*(::std::ptr::null::<rte_thash_tuple>())).v4 as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
Expand All @@ -287,7 +295,7 @@ fn bindgen_test_layout_rte_thash_tuple() {
)
);
assert_eq!(
unsafe { &(*(0 as *const rte_thash_tuple)).v6 as *const _ as usize },
unsafe { &(*(::std::ptr::null::<rte_thash_tuple>())).v6 as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
Expand Down
32 changes: 20 additions & 12 deletions tests/expectations/tests/16-byte-alignment_1_0.rs
Expand Up @@ -87,7 +87,8 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(0 as *const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)).dport as *const _ as usize
&(*(::std::ptr::null::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>())).dport as *const _
as usize
},
0usize,
concat!(
Expand All @@ -99,7 +100,8 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(0 as *const rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1)).sport as *const _ as usize
&(*(::std::ptr::null::<rte_ipv4_tuple__bindgen_ty_1__bindgen_ty_1>())).sport as *const _
as usize
},
2usize,
concat!(
Expand Down Expand Up @@ -128,7 +130,9 @@ fn bindgen_test_layout_rte_ipv4_tuple__bindgen_ty_1() {
concat!("Alignment of ", stringify!(rte_ipv4_tuple__bindgen_ty_1))
);
assert_eq!(
unsafe { &(*(0 as *const rte_ipv4_tuple__bindgen_ty_1)).sctp_tag as *const _ as usize },
unsafe {
&(*(::std::ptr::null::<rte_ipv4_tuple__bindgen_ty_1>())).sctp_tag as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
Expand Down Expand Up @@ -156,7 +160,7 @@ fn bindgen_test_layout_rte_ipv4_tuple() {
concat!("Alignment of ", stringify!(rte_ipv4_tuple))
);
assert_eq!(
unsafe { &(*(0 as *const rte_ipv4_tuple)).src_addr as *const _ as usize },
unsafe { &(*(::std::ptr::null::<rte_ipv4_tuple>())).src_addr as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
Expand All @@ -166,7 +170,7 @@ fn bindgen_test_layout_rte_ipv4_tuple() {
)
);
assert_eq!(
unsafe { &(*(0 as *const rte_ipv4_tuple)).dst_addr as *const _ as usize },
unsafe { &(*(::std::ptr::null::<rte_ipv4_tuple>())).dst_addr as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
Expand Down Expand Up @@ -221,7 +225,8 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(0 as *const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)).dport as *const _ as usize
&(*(::std::ptr::null::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>())).dport as *const _
as usize
},
0usize,
concat!(
Expand All @@ -233,7 +238,8 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1() {
);
assert_eq!(
unsafe {
&(*(0 as *const rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1)).sport as *const _ as usize
&(*(::std::ptr::null::<rte_ipv6_tuple__bindgen_ty_1__bindgen_ty_1>())).sport as *const _
as usize
},
2usize,
concat!(
Expand Down Expand Up @@ -262,7 +268,9 @@ fn bindgen_test_layout_rte_ipv6_tuple__bindgen_ty_1() {
concat!("Alignment of ", stringify!(rte_ipv6_tuple__bindgen_ty_1))
);
assert_eq!(
unsafe { &(*(0 as *const rte_ipv6_tuple__bindgen_ty_1)).sctp_tag as *const _ as usize },
unsafe {
&(*(::std::ptr::null::<rte_ipv6_tuple__bindgen_ty_1>())).sctp_tag as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
Expand Down Expand Up @@ -290,7 +298,7 @@ fn bindgen_test_layout_rte_ipv6_tuple() {
concat!("Alignment of ", stringify!(rte_ipv6_tuple))
);
assert_eq!(
unsafe { &(*(0 as *const rte_ipv6_tuple)).src_addr as *const _ as usize },
unsafe { &(*(::std::ptr::null::<rte_ipv6_tuple>())).src_addr as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
Expand All @@ -300,7 +308,7 @@ fn bindgen_test_layout_rte_ipv6_tuple() {
)
);
assert_eq!(
unsafe { &(*(0 as *const rte_ipv6_tuple)).dst_addr as *const _ as usize },
unsafe { &(*(::std::ptr::null::<rte_ipv6_tuple>())).dst_addr as *const _ as usize },
16usize,
concat!(
"Offset of field: ",
Expand Down Expand Up @@ -330,7 +338,7 @@ fn bindgen_test_layout_rte_thash_tuple() {
concat!("Size of: ", stringify!(rte_thash_tuple))
);
assert_eq!(
unsafe { &(*(0 as *const rte_thash_tuple)).v4 as *const _ as usize },
unsafe { &(*(::std::ptr::null::<rte_thash_tuple>())).v4 as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
Expand All @@ -340,7 +348,7 @@ fn bindgen_test_layout_rte_thash_tuple() {
)
);
assert_eq!(
unsafe { &(*(0 as *const rte_thash_tuple)).v6 as *const _ as usize },
unsafe { &(*(::std::ptr::null::<rte_thash_tuple>())).v6 as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
Expand Down
42 changes: 28 additions & 14 deletions tests/expectations/tests/accessors.rs
Expand Up @@ -28,7 +28,7 @@ fn bindgen_test_layout_SomeAccessors() {
concat!("Alignment of ", stringify!(SomeAccessors))
);
assert_eq!(
unsafe { &(*(0 as *const SomeAccessors)).mNoAccessor as *const _ as usize },
unsafe { &(*(::std::ptr::null::<SomeAccessors>())).mNoAccessor as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
Expand All @@ -38,7 +38,7 @@ fn bindgen_test_layout_SomeAccessors() {
)
);
assert_eq!(
unsafe { &(*(0 as *const SomeAccessors)).mBothAccessors as *const _ as usize },
unsafe { &(*(::std::ptr::null::<SomeAccessors>())).mBothAccessors as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
Expand All @@ -48,7 +48,7 @@ fn bindgen_test_layout_SomeAccessors() {
)
);
assert_eq!(
unsafe { &(*(0 as *const SomeAccessors)).mUnsafeAccessors as *const _ as usize },
unsafe { &(*(::std::ptr::null::<SomeAccessors>())).mUnsafeAccessors as *const _ as usize },
8usize,
concat!(
"Offset of field: ",
Expand All @@ -58,7 +58,9 @@ fn bindgen_test_layout_SomeAccessors() {
)
);
assert_eq!(
unsafe { &(*(0 as *const SomeAccessors)).mImmutableAccessor as *const _ as usize },
unsafe {
&(*(::std::ptr::null::<SomeAccessors>())).mImmutableAccessor as *const _ as usize
},
12usize,
concat!(
"Offset of field: ",
Expand Down Expand Up @@ -110,7 +112,7 @@ fn bindgen_test_layout_AllAccessors() {
concat!("Alignment of ", stringify!(AllAccessors))
);
assert_eq!(
unsafe { &(*(0 as *const AllAccessors)).mBothAccessors as *const _ as usize },
unsafe { &(*(::std::ptr::null::<AllAccessors>())).mBothAccessors as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
Expand All @@ -120,7 +122,7 @@ fn bindgen_test_layout_AllAccessors() {
)
);
assert_eq!(
unsafe { &(*(0 as *const AllAccessors)).mAlsoBothAccessors as *const _ as usize },
unsafe { &(*(::std::ptr::null::<AllAccessors>())).mAlsoBothAccessors as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
Expand Down Expand Up @@ -168,7 +170,9 @@ fn bindgen_test_layout_AllUnsafeAccessors() {
concat!("Alignment of ", stringify!(AllUnsafeAccessors))
);
assert_eq!(
unsafe { &(*(0 as *const AllUnsafeAccessors)).mBothAccessors as *const _ as usize },
unsafe {
&(*(::std::ptr::null::<AllUnsafeAccessors>())).mBothAccessors as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
Expand All @@ -178,7 +182,9 @@ fn bindgen_test_layout_AllUnsafeAccessors() {
)
);
assert_eq!(
unsafe { &(*(0 as *const AllUnsafeAccessors)).mAlsoBothAccessors as *const _ as usize },
unsafe {
&(*(::std::ptr::null::<AllUnsafeAccessors>())).mAlsoBothAccessors as *const _ as usize
},
4usize,
concat!(
"Offset of field: ",
Expand Down Expand Up @@ -231,7 +237,9 @@ fn bindgen_test_layout_ContradictAccessors() {
concat!("Alignment of ", stringify!(ContradictAccessors))
);
assert_eq!(
unsafe { &(*(0 as *const ContradictAccessors)).mBothAccessors as *const _ as usize },
unsafe {
&(*(::std::ptr::null::<ContradictAccessors>())).mBothAccessors as *const _ as usize
},
0usize,
concat!(
"Offset of field: ",
Expand All @@ -241,7 +249,9 @@ fn bindgen_test_layout_ContradictAccessors() {
)
);
assert_eq!(
unsafe { &(*(0 as *const ContradictAccessors)).mNoAccessors as *const _ as usize },
unsafe {
&(*(::std::ptr::null::<ContradictAccessors>())).mNoAccessors as *const _ as usize
},
4usize,
concat!(
"Offset of field: ",
Expand All @@ -251,7 +261,9 @@ fn bindgen_test_layout_ContradictAccessors() {
)
);
assert_eq!(
unsafe { &(*(0 as *const ContradictAccessors)).mUnsafeAccessors as *const _ as usize },
unsafe {
&(*(::std::ptr::null::<ContradictAccessors>())).mUnsafeAccessors as *const _ as usize
},
8usize,
concat!(
"Offset of field: ",
Expand All @@ -261,7 +273,9 @@ fn bindgen_test_layout_ContradictAccessors() {
)
);
assert_eq!(
unsafe { &(*(0 as *const ContradictAccessors)).mImmutableAccessor as *const _ as usize },
unsafe {
&(*(::std::ptr::null::<ContradictAccessors>())).mImmutableAccessor as *const _ as usize
},
12usize,
concat!(
"Offset of field: ",
Expand Down Expand Up @@ -312,7 +326,7 @@ fn bindgen_test_layout_Replaced() {
concat!("Alignment of ", stringify!(Replaced))
);
assert_eq!(
unsafe { &(*(0 as *const Replaced)).mAccessor as *const _ as usize },
unsafe { &(*(::std::ptr::null::<Replaced>())).mAccessor as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
Expand Down Expand Up @@ -351,7 +365,7 @@ fn bindgen_test_layout_Wrapper() {
concat!("Alignment of ", stringify!(Wrapper))
);
assert_eq!(
unsafe { &(*(0 as *const Wrapper)).mReplaced as *const _ as usize },
unsafe { &(*(::std::ptr::null::<Wrapper>())).mReplaced as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
Expand Down
2 changes: 1 addition & 1 deletion tests/expectations/tests/annotation_hide.rs
Expand Up @@ -42,7 +42,7 @@ fn bindgen_test_layout_NotAnnotated() {
concat!("Alignment of ", stringify!(NotAnnotated))
);
assert_eq!(
unsafe { &(*(0 as *const NotAnnotated)).f as *const _ as usize },
unsafe { &(*(::std::ptr::null::<NotAnnotated>())).f as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
Expand Down

0 comments on commit 430fb0e

Please sign in to comment.