提交 e4277472 编写于 作者: B Brian Anderson

core: Split sys::align_of into min_align_of, pref_align_of

上级 f4f909b8
......@@ -3,7 +3,8 @@
export type_desc;
export get_type_desc;
export size_of;
export align_of;
export min_align_of;
export pref_align_of;
export refcount;
export log_str;
......@@ -43,8 +44,21 @@ fn size_of<T>() -> uint unsafe {
rusti::size_of::<T>()
}
#[doc = "Returns the alignment of a type"]
fn align_of<T>() -> uint unsafe {
#[doc = "
Returns the ABI-required minimum alignment of a type
This is the alignment used for struct fields. It may be smaller
than the preferred alignment.
"]
fn min_align_of<T>() -> uint unsafe {
// FIXME: use rusti::min_align_of after snapshot
// rusti::align_of::<T>()
fail "FIXME: uncomment the above line to use min_align_of";
}
#[doc = "Returns the preferred alignment of a type"]
fn pref_align_of<T>() -> uint unsafe {
// FIXME: use rusti::pref_align_of after snapshot
rusti::align_of::<T>()
}
......@@ -85,24 +99,24 @@ fn size_of_64() {
#[test]
fn align_of_basic() {
assert align_of::<u8>() == 1u;
assert align_of::<u16>() == 2u;
assert align_of::<u32>() == 4u;
assert pref_align_of::<u8>() == 1u;
assert pref_align_of::<u16>() == 2u;
assert pref_align_of::<u32>() == 4u;
}
#[test]
#[cfg(target_arch = "x86")]
#[cfg(target_arch = "arm")]
fn align_of_32() {
assert align_of::<uint>() == 4u;
assert align_of::<*uint>() == 4u;
assert pref_align_of::<uint>() == 4u;
assert pref_align_of::<*uint>() == 4u;
}
#[test]
#[cfg(target_arch = "x86_64")]
fn align_of_64() {
assert align_of::<uint>() == 8u;
assert align_of::<*uint>() == 8u;
assert pref_align_of::<uint>() == 8u;
assert pref_align_of::<*uint>() == 8u;
}
}
......
......@@ -451,7 +451,7 @@ fn create_boxed_type(cx: @crate_ctxt, outer: ty::t, _inner: ty::t,
ast::ty_uint(ast::ty_u), span);
let scx = create_structure(file_node, ty_to_str(cx.tcx, outer), 0);
add_member(scx, "refcnt", 0, sys::size_of::<uint>() as int,
sys::align_of::<uint>() as int, refcount_type.node);
sys::min_align_of::<uint>() as int, refcount_type.node);
add_member(scx, "boxed", 0, 8, //XXX member_size_and_align(??)
8, //XXX just a guess
boxed.node);
......@@ -502,9 +502,9 @@ fn create_vec(cx: @crate_ctxt, vec_t: ty::t, elem_t: ty::t,
let size_t_type = create_basic_type(cx, ty::mk_uint(cx.tcx),
ast::ty_uint(ast::ty_u), vec_ty_span);
add_member(scx, "fill", 0, sys::size_of::<libc::size_t>() as int,
sys::align_of::<libc::size_t>() as int, size_t_type.node);
sys::min_align_of::<libc::size_t>() as int, size_t_type.node);
add_member(scx, "alloc", 0, sys::size_of::<libc::size_t>() as int,
sys::align_of::<libc::size_t>() as int, size_t_type.node);
sys::min_align_of::<libc::size_t>() as int, size_t_type.node);
let subrange = llmdnode([lltag(SubrangeTag), lli64(0), lli64(0)]);
let (arr_size, arr_align) = size_and_align_of(cx, elem_t);
let data_ptr = create_composite_type(ArrayTypeTag, "", file_node.node, 0,
......@@ -512,7 +512,7 @@ fn create_vec(cx: @crate_ctxt, vec_t: ty::t, elem_t: ty::t,
option::some(elem_ty_md.node),
option::some([subrange]));
add_member(scx, "data", 0, 0, // clang says the size should be 0
sys::align_of::<u8>() as int, data_ptr);
sys::min_align_of::<u8>() as int, data_ptr);
let llnode = finish_structure(scx);
ret @{node: llnode, data: {hash: ty::type_id(vec_t)}};
}
......
......@@ -22,7 +22,7 @@ fn main() {
// Send it through the shape code
let y = #fmt["%?", x];
#debug("align inner = %?", sys::align_of::<inner>()); // 8
#debug("align inner = %?", sys::pref_align_of::<inner>()); // 8
#debug("size outer = %?", sys::size_of::<outer>()); // 12
#debug("y = %s", y); // (22, (0))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册