1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 //! bindgen test for hpp
17 #![allow(clippy::approx_constant)]
18 #![allow(non_snake_case)]
19 mod c_ffi {
20 #![allow(dead_code)]
21 #![allow(non_upper_case_globals)]
22 #![allow(non_camel_case_types)]
23 include!(env!("BINDGEN_RS_FILE"));
24 }
25
26
bindgen_test_layout_C()27 fn bindgen_test_layout_C() {
28 const UNINIT: ::std::mem::MaybeUninit<c_ffi::C> =
29 ::std::mem::MaybeUninit::uninit();
30 let ptr = UNINIT.as_ptr();
31 println!(
32 "The mem size of c_ffi::C is {} usize",
33 ::std::mem::size_of::<c_ffi::C>()
34 );
35 println!(
36 "The align_of size of c_ffi::C is {} usize",
37 ::std::mem::align_of::<c_ffi::C>()
38 );
39 println!(
40 "The addr_of!((*ptr).c) as usize - ptr as usize is {} usize",
41 unsafe { ::std::ptr::addr_of!((*ptr).c) as usize - ptr as usize }
42 );
43 println!(
44 "The addr_of!((*ptr).ptr) as usize - ptr as usize is {} usize",
45 unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }
46 );
47 println!(
48 "The addr_of!((*ptr).arr) as usize - ptr as usize is {} usize",
49 unsafe { ::std::ptr::addr_of!((*ptr).arr) as usize - ptr as usize }
50 );
51 println!(
52 "The addr_of!((*ptr).d) as usize - ptr as usize is {} usize",
53 unsafe { ::std::ptr::addr_of!((*ptr).d) as usize - ptr as usize }
54 );
55 println!(
56 "The addr_of!((*ptr).other_ptr) as usize - ptr as usize is {} usize",
57 unsafe {
58 ::std::ptr::addr_of!((*ptr).other_ptr) as usize - ptr as usize
59 }
60 );
61 }
62
63
bindgen_test_layout_D()64 fn bindgen_test_layout_D() {
65 const UNINIT: ::std::mem::MaybeUninit<c_ffi::D> =
66 ::std::mem::MaybeUninit::uninit();
67 let ptr = UNINIT.as_ptr();
68 println!(
69 "The mem size of c_ffi::D is {} usize",
70 ::std::mem::size_of::<c_ffi::D>()
71 );
72 println!(
73 "The align_of size of c_ffi::D is {} usize",
74 ::std::mem::align_of::<c_ffi::D>()
75 );
76 println!(
77 "The addr_of!((*ptr).ptr) as usize - ptr as usize is {} usize",
78 unsafe { ::std::ptr::addr_of!((*ptr).ptr) as usize - ptr as usize }
79 );
80 }
81 impl Default for c_ffi::D {
default() -> Self82 fn default() -> Self {
83 let mut r = ::std::mem::MaybeUninit::<Self>::uninit();
84 unsafe {
85 ::std::ptr::write_bytes(r.as_mut_ptr(), 0, 1);
86 r.assume_init()
87 }
88 }
89 }
90
91 /// fn main()
main()92 fn main() {
93 bindgen_test_layout_C();
94 bindgen_test_layout_D()
95 }
96