Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e4277472
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e4277472
编写于
4月 26, 2012
作者:
B
Brian Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: Split sys::align_of into min_align_of, pref_align_of
上级
f4f909b8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
15 deletion
+29
-15
src/libcore/sys.rs
src/libcore/sys.rs
+24
-10
src/rustc/middle/trans/debuginfo.rs
src/rustc/middle/trans/debuginfo.rs
+4
-4
src/test/run-pass/rec-align-32-bit.rs
src/test/run-pass/rec-align-32-bit.rs
+1
-1
未找到文件。
src/libcore/sys.rs
浏览文件 @
e4277472
...
...
@@ -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
;
}
}
...
...
src/rustc/middle/trans/debuginfo.rs
浏览文件 @
e4277472
...
...
@@ -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
)}};
}
...
...
src/test/run-pass/rec-align-32-bit.rs
浏览文件 @
e4277472
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录