Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
d1bd1392
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,发现更多精彩内容 >>
提交
d1bd1392
编写于
9月 05, 2014
作者:
D
Daniel Micay
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix sized deallocation for Box<[T]>
上级
5aa2da01
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
77 addition
and
19 deletion
+77
-19
src/librustc/middle/trans/cleanup.rs
src/librustc/middle/trans/cleanup.rs
+55
-0
src/librustc/middle/trans/glue.rs
src/librustc/middle/trans/glue.rs
+4
-6
src/librustc/middle/trans/tvec.rs
src/librustc/middle/trans/tvec.rs
+18
-13
未找到文件。
src/librustc/middle/trans/cleanup.rs
浏览文件 @
d1bd1392
...
...
@@ -340,6 +340,27 @@ fn schedule_free_value(&self,
self
.schedule_clean
(
cleanup_scope
,
drop
as
CleanupObj
);
}
fn
schedule_free_slice
(
&
self
,
cleanup_scope
:
ScopeId
,
val
:
ValueRef
,
size
:
ValueRef
,
align
:
ValueRef
,
heap
:
Heap
)
{
/*!
* Schedules a call to `free(val)`. Note that this is a shallow
* operation.
*/
let
drop
=
box
FreeSlice
{
ptr
:
val
,
size
:
size
,
align
:
align
,
heap
:
heap
};
debug!
(
"schedule_free_slice({:?}, val={}, heap={:?})"
,
cleanup_scope
,
self
.ccx
.tn
()
.val_to_string
(
val
),
heap
);
self
.schedule_clean
(
cleanup_scope
,
drop
as
CleanupObj
);
}
fn
schedule_clean
(
&
self
,
cleanup_scope
:
ScopeId
,
cleanup
:
CleanupObj
)
{
...
...
@@ -926,6 +947,34 @@ fn trans<'a>(&self, bcx: &'a Block<'a>) -> &'a Block<'a> {
}
}
pub
struct
FreeSlice
{
ptr
:
ValueRef
,
size
:
ValueRef
,
align
:
ValueRef
,
heap
:
Heap
,
}
impl
Cleanup
for
FreeSlice
{
fn
must_unwind
(
&
self
)
->
bool
{
true
}
fn
clean_on_unwind
(
&
self
)
->
bool
{
true
}
fn
trans
<
'a
>
(
&
self
,
bcx
:
&
'a
Block
<
'a
>
)
->
&
'a
Block
<
'a
>
{
match
self
.heap
{
HeapManaged
=>
{
glue
::
trans_free
(
bcx
,
self
.ptr
)
}
HeapExchange
=>
{
glue
::
trans_exchange_free_dyn
(
bcx
,
self
.ptr
,
self
.size
,
self
.align
)
}
}
}
}
pub
struct
LifetimeEnd
{
ptr
:
ValueRef
,
}
...
...
@@ -1020,6 +1069,12 @@ fn schedule_free_value(&self,
val
:
ValueRef
,
heap
:
Heap
,
content_ty
:
ty
::
t
);
fn
schedule_free_slice
(
&
self
,
cleanup_scope
:
ScopeId
,
val
:
ValueRef
,
size
:
ValueRef
,
align
:
ValueRef
,
heap
:
Heap
);
fn
schedule_clean
(
&
self
,
cleanup_scope
:
ScopeId
,
cleanup
:
CleanupObj
);
...
...
src/librustc/middle/trans/glue.rs
浏览文件 @
d1bd1392
...
...
@@ -53,7 +53,7 @@ pub fn trans_free<'a>(cx: &'a Block<'a>, v: ValueRef) -> &'a Block<'a> {
Some
(
expr
::
Ignore
))
.bcx
}
fn
trans_exchange_free_internal
<
'a
>
(
cx
:
&
'a
Block
<
'a
>
,
v
:
ValueRef
,
size
:
ValueRef
,
pub
fn
trans_exchange_free_dyn
<
'a
>
(
cx
:
&
'a
Block
<
'a
>
,
v
:
ValueRef
,
size
:
ValueRef
,
align
:
ValueRef
)
->
&
'a
Block
<
'a
>
{
let
_
icx
=
push_ctxt
(
"trans_exchange_free"
);
let
ccx
=
cx
.ccx
();
...
...
@@ -65,10 +65,8 @@ fn trans_exchange_free_internal<'a>(cx: &'a Block<'a>, v: ValueRef, size: ValueR
pub
fn
trans_exchange_free
<
'a
>
(
cx
:
&
'a
Block
<
'a
>
,
v
:
ValueRef
,
size
:
u64
,
align
:
u64
)
->
&
'a
Block
<
'a
>
{
trans_exchange_free_internal
(
cx
,
v
,
C_uint
(
cx
.ccx
(),
size
as
uint
),
C_uint
(
cx
.ccx
(),
align
as
uint
))
trans_exchange_free_dyn
(
cx
,
v
,
C_uint
(
cx
.ccx
(),
size
as
uint
),
C_uint
(
cx
.ccx
(),
align
as
uint
))
}
pub
fn
trans_exchange_free_ty
<
'a
>
(
bcx
:
&
'a
Block
<
'a
>
,
ptr
:
ValueRef
,
...
...
@@ -467,7 +465,7 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'
let
info
=
GEPi
(
bcx
,
v0
,
[
0
,
abi
::
slice_elt_len
]);
let
info
=
Load
(
bcx
,
info
);
let
(
llsize
,
llalign
)
=
size_and_align_of_dst
(
bcx
,
content_ty
,
info
);
trans_exchange_free_
internal
(
bcx
,
llbox
,
llsize
,
llalign
)
trans_exchange_free_
dyn
(
bcx
,
llbox
,
llsize
,
llalign
)
})
}
_
=>
{
...
...
src/librustc/middle/trans/tvec.rs
浏览文件 @
d1bd1392
...
...
@@ -25,6 +25,7 @@
use
middle
::
trans
::
expr
::{
Dest
,
Ignore
,
SaveIn
};
use
middle
::
trans
::
expr
;
use
middle
::
trans
::
glue
;
use
middle
::
trans
::
machine
;
use
middle
::
trans
::
machine
::{
nonzero_llsize_of
,
llsize_of_alloc
};
use
middle
::
trans
::
type_
::
Type
;
use
middle
::
trans
::
type_of
;
...
...
@@ -59,6 +60,7 @@ pub fn make_drop_glue_unboxed<'a>(
->
&
'a
Block
<
'a
>
{
let
not_null
=
IsNotNull
(
bcx
,
vptr
);
with_cond
(
bcx
,
not_null
,
|
bcx
|
{
let
ccx
=
bcx
.ccx
();
let
tcx
=
bcx
.tcx
();
let
_
icx
=
push_ctxt
(
"tvec::make_drop_glue_unboxed"
);
...
...
@@ -73,8 +75,11 @@ pub fn make_drop_glue_unboxed<'a>(
if
should_deallocate
{
let
not_null
=
IsNotNull
(
bcx
,
dataptr
);
with_cond
(
bcx
,
not_null
,
|
bcx
|
{
// FIXME: #13994: the old `Box<[T]>` will not support sized deallocation
glue
::
trans_exchange_free
(
bcx
,
dataptr
,
0
,
8
)
let
llty
=
type_of
::
type_of
(
ccx
,
unit_ty
);
let
llsize
=
machine
::
llsize_of
(
ccx
,
llty
);
let
llalign
=
C_uint
(
ccx
,
machine
::
llalign_of_min
(
ccx
,
llty
)
as
uint
);
let
size
=
Mul
(
bcx
,
llsize
,
get_len
(
bcx
,
vptr
));
glue
::
trans_exchange_free_dyn
(
bcx
,
dataptr
,
size
,
llalign
)
})
}
else
{
bcx
...
...
@@ -281,15 +286,16 @@ pub fn trans_uniq_vec<'a>(bcx: &'a Block<'a>,
debug!
(
" vt={}, count={:?}"
,
vt
.to_string
(
ccx
),
count
);
let
vec_ty
=
node_id_type
(
bcx
,
uniq_expr
.id
);
let
unit_sz
=
nonzero_llsize_of
(
ccx
,
type_of
::
type_of
(
ccx
,
vt
.unit_ty
));
let
llty
=
type_of
::
type_of
(
ccx
,
vt
.unit_ty
);
let
unit_sz
=
nonzero_llsize_of
(
ccx
,
llty
);
let
llcount
=
if
count
<
4u
{
C_int
(
ccx
,
4
)
}
else
{
C_uint
(
ccx
,
count
)
};
let
alloc
=
Mul
(
bcx
,
llcount
,
unit_sz
);
let
llty_ptr
=
type_of
::
type_of
(
ccx
,
vt
.unit_ty
)
.ptr_to
();
let
align
=
C_uint
(
ccx
,
8
);
let
llty_ptr
=
llty
.ptr_to
();
let
align
=
C_uint
(
ccx
,
machine
::
llalign_of_min
(
ccx
,
llty
)
as
uint
);
let
Result
{
bcx
:
bcx
,
val
:
dataptr
}
=
malloc_raw_dyn
(
bcx
,
llty_ptr
,
vec_ty
,
...
...
@@ -299,16 +305,15 @@ pub fn trans_uniq_vec<'a>(bcx: &'a Block<'a>,
// Create a temporary scope lest execution should fail while
// constructing the vector.
let
temp_scope
=
fcx
.push_custom_cleanup_scope
();
// FIXME: #13994: the old `Box<[T]> will not support sized deallocation,
// this is a placeholder
fcx
.schedule_free_value
(
cleanup
::
CustomScope
(
temp_scope
),
dataptr
,
cleanup
::
HeapExchange
,
vt
.unit_ty
);
debug!
(
" alloc_uniq_vec() returned dataptr={}, len={}"
,
bcx
.val_to_string
(
dataptr
),
count
);
fcx
.schedule_free_slice
(
cleanup
::
CustomScope
(
temp_scope
)
,
dataptr
,
alloc
,
align
,
cleanup
::
HeapExchange
);
let
bcx
=
write_content
(
bcx
,
&
vt
,
uniq_expr
,
content_expr
,
SaveIn
(
dataptr
));
debug!
(
" alloc_uniq_vec() returned dataptr={}, len={}"
,
bcx
.val_to_string
(
dataptr
),
count
);
let
bcx
=
write_content
(
bcx
,
&
vt
,
uniq_expr
,
content_expr
,
SaveIn
(
dataptr
));
fcx
.pop_custom_cleanup_scope
(
temp_scope
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录