Skip to content

Commit b544933

Browse files
fix layout output
1 parent 341b6eb commit b544933

File tree

7 files changed

+91
-4
lines changed

7 files changed

+91
-4
lines changed

asttoc/src/cppmm_ast_write_rustsys.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,21 @@ impl Default for {} {{
221221
}}
222222
)",
223223
node_record->name, node_record->size / 8);
224+
225+
out.print(R"(
226+
impl {0} {{
227+
pub fn layout() -> std::alloc::Layout {{
228+
unsafe {{
229+
std::alloc::Layout::from_size_align(
230+
{1}_sizeof(),
231+
{1}_alignof(),
232+
).unwrap()
233+
}}
234+
}}
235+
}}
236+
)",
237+
node_record->name, pystring::slice(node_record->name, 0, -2));
238+
224239
} else { // BindType::ValueType
225240
out.print("#[repr(C, align({}))]\n", node_record->align / 8);
226241
out.print("#[derive(Clone)]\n");

test/dtor/ref/dtor-sys/src/std_string.rs

+11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ impl Default for std____cxx11__basic_string_char__t {
1717
}
1818
}
1919

20+
impl std____cxx11__basic_string_char__t {
21+
pub fn layout() -> std::alloc::Layout {
22+
unsafe {
23+
std::alloc::Layout::from_size_align(
24+
std____cxx11__basic_string_char__sizeof(),
25+
std____cxx11__basic_string_char__alignof(),
26+
).unwrap()
27+
}
28+
}
29+
}
30+
2031

2132

2233
extern "C" {

test/exceptions/ref/exceptions-sys/src/c_ex.rs

+11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ impl Default for ex__Struct_t {
1717
}
1818
}
1919

20+
impl ex__Struct_t {
21+
pub fn layout() -> std::alloc::Layout {
22+
unsafe {
23+
std::alloc::Layout::from_size_align(
24+
ex__Struct_sizeof(),
25+
ex__Struct_alignof(),
26+
).unwrap()
27+
}
28+
}
29+
}
30+
2031

2132

2233
extern "C" {

test/std/ref/std-sys/src/std_set.rs

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ impl Default for std__set_std__string__t {
2121
}
2222
}
2323

24+
impl std__set_std__string__t {
25+
pub fn layout() -> std::alloc::Layout {
26+
unsafe {
27+
std::alloc::Layout::from_size_align(
28+
std__set_std__string__sizeof(),
29+
std__set_std__string__alignof(),
30+
).unwrap()
31+
}
32+
}
33+
}
34+
2435
#[repr(C, align(8))]
2536
#[derive(Clone)]
2637
pub struct std___Rb_tree_const_iterator_std____cxx11__basic_string_char___t {

test/std/ref/std-sys/src/std_string.rs

+22
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ impl Default for std____cxx11__basic_string_char__t {
1717
}
1818
}
1919

20+
impl std____cxx11__basic_string_char__t {
21+
pub fn layout() -> std::alloc::Layout {
22+
unsafe {
23+
std::alloc::Layout::from_size_align(
24+
std____cxx11__basic_string_char__sizeof(),
25+
std____cxx11__basic_string_char__alignof(),
26+
).unwrap()
27+
}
28+
}
29+
}
30+
2031
#[repr(C, align(8))]
2132
#[derive(Clone)]
2233
pub struct std__vector_std__string__t {
@@ -29,6 +40,17 @@ impl Default for std__vector_std__string__t {
2940
}
3041
}
3142

43+
impl std__vector_std__string__t {
44+
pub fn layout() -> std::alloc::Layout {
45+
unsafe {
46+
std::alloc::Layout::from_size_align(
47+
std__vector_std__string__sizeof(),
48+
std__vector_std__string__alignof(),
49+
).unwrap()
50+
}
51+
}
52+
}
53+
3254

3355

3456
extern "C" {

test/std/ref/std-sys/src/test.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
// Empty dummy test file for automated testing. This will be replaced by a
2-
// file copied in from the test suite
1+
use crate::*;
32

43
#[test]
54
fn it_works() {
6-
assert!(true, "It works!");
7-
}
5+
let lay = std_string_t::layout();
6+
assert_eq!(lay.size(), std::mem::size_of::<std_string_t>());
7+
assert_eq!(lay.align(), std::mem::align_of::<std_string_t>());
8+
9+
let lay = std_vector_string_t::layout();
10+
assert_eq!(lay.size(), std::mem::size_of::<std_vector_string_t>());
11+
assert_eq!(lay.align(), std::mem::align_of::<std_vector_string_t>());
12+
}

test/std/test.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use crate::*;
2+
3+
#[test]
4+
fn it_works() {
5+
let lay = std_string_t::layout();
6+
assert_eq!(lay.size(), std::mem::size_of::<std_string_t>());
7+
assert_eq!(lay.align(), std::mem::align_of::<std_string_t>());
8+
9+
let lay = std_vector_string_t::layout();
10+
assert_eq!(lay.size(), std::mem::size_of::<std_vector_string_t>());
11+
assert_eq!(lay.align(), std::mem::align_of::<std_vector_string_t>());
12+
}

0 commit comments

Comments
 (0)