Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
184d3b3b
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
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,发现更多精彩内容 >>
提交
184d3b3b
编写于
6月 21, 2017
作者:
R
Ralf Jung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
expand thread-local storage tests to cover dtor order and re-running dtors
上级
d539fafa
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
68 addition
and
19 deletion
+68
-19
src/terminator/mod.rs
src/terminator/mod.rs
+1
-1
tests/run-pass/thread-local-no-dtor.rs
tests/run-pass/thread-local-no-dtor.rs
+0
-18
tests/run-pass/thread-local.rs
tests/run-pass/thread-local.rs
+67
-0
未找到文件。
src/terminator/mod.rs
浏览文件 @
184d3b3b
...
...
@@ -614,7 +614,7 @@ fn call_c_abi(
let
arg_dest
=
self
.eval_lvalue
(
&
mir
::
Lvalue
::
Local
(
arg_local
))
?
;
self
.write_primval
(
arg_dest
,
data
,
u8_ptr_ty
)
?
;
// We oursel
b
es return 0
// We oursel
v
es return 0
self
.write_primval
(
dest
,
PrimVal
::
Bytes
(
0
),
dest_ty
)
?
;
// Don't fall through
...
...
tests/run-pass/thread-local-no-dtor.rs
已删除
100644 → 0
浏览文件 @
d539fafa
//ignore-windows
#![feature(libc)]
extern
crate
libc
;
use
std
::
mem
;
pub
type
Key
=
libc
::
pthread_key_t
;
pub
unsafe
fn
create
(
dtor
:
Option
<
unsafe
extern
fn
(
*
mut
u8
)
>
)
->
Key
{
let
mut
key
=
0
;
assert_eq!
(
libc
::
pthread_key_create
(
&
mut
key
,
mem
::
transmute
(
dtor
)),
0
);
key
}
fn
main
()
{
let
_
=
unsafe
{
create
(
None
)
};
}
tests/run-pass/thread-local.rs
0 → 100644
浏览文件 @
184d3b3b
//ignore-windows
#![feature(libc)]
extern
crate
libc
;
use
std
::
mem
;
pub
type
Key
=
libc
::
pthread_key_t
;
static
mut
RECORD
:
usize
=
0
;
static
mut
KEYS
:
[
Key
;
2
]
=
[
0
;
2
];
static
mut
GLOBALS
:
[
u64
;
2
]
=
[
1
,
0
];
static
mut
CANNARY
:
*
mut
u64
=
0
as
*
mut
_
;
// this serves as a cannary: if TLS dtors are not run properly, this will not get deallocated, making the test fail.
pub
unsafe
fn
create
(
dtor
:
Option
<
unsafe
extern
fn
(
*
mut
u8
)
>
)
->
Key
{
let
mut
key
=
0
;
assert_eq!
(
libc
::
pthread_key_create
(
&
mut
key
,
mem
::
transmute
(
dtor
)),
0
);
key
}
pub
unsafe
fn
set
(
key
:
Key
,
value
:
*
mut
u8
)
{
let
r
=
libc
::
pthread_setspecific
(
key
,
value
as
*
mut
_
);
assert_eq!
(
r
,
0
);
}
pub
fn
record
(
r
:
usize
)
{
assert
!
(
r
<
10
);
unsafe
{
RECORD
=
RECORD
*
10
+
r
};
}
unsafe
extern
fn
dtor
(
mut
ptr
:
*
mut
u64
)
{
assert
!
(
CANNARY
!=
0
as
*
mut
_
);
// make sure we do not get run too often
let
val
=
*
ptr
;
let
which_key
=
GLOBALS
.iter
()
.position
(|
global
|
global
as
*
const
_
==
ptr
)
.expect
(
"Should find my global"
);
record
(
which_key
);
if
val
>
0
{
*
ptr
=
val
-
1
;
set
(
KEYS
[
which_key
],
ptr
as
*
mut
_
);
}
// Check if the records matches what we expect. If yes, clear the cannary.
// If the record is wrong, the cannary will ever get cleared, leading to a leak -> test fails.
// If the record is incomplete (i.e., more dtor calls happen), the check at the beginning of this function will fail -> test fails.
// The correct sequence is: First key 0, then key 1, then key 0.
if
RECORD
==
0_1_0
{
drop
(
Box
::
from_raw
(
CANNARY
));
CANNARY
=
0
as
*
mut
_
;
}
}
fn
main
()
{
unsafe
{
create
(
None
);
// check that the no-dtor case works
// Initialize the keys we use to check destructor ordering
for
(
key
,
global
)
in
KEYS
.iter_mut
()
.zip
(
GLOBALS
.iter
())
{
*
key
=
create
(
Some
(
mem
::
transmute
(
dtor
as
unsafe
extern
fn
(
*
mut
u64
))));
set
(
*
key
,
global
as
*
const
_
as
*
mut
_
);
}
// Initialize cannary
CANNARY
=
Box
::
into_raw
(
Box
::
new
(
0u64
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录