Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
143579f5
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
143579f5
编写于
4月 04, 2018
作者:
A
Anton Perkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
don't allocate more memory on stack than needed #1030
上级
9adb819f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
28 deletion
+19
-28
contracts/eosiolib/dispatcher.hpp
contracts/eosiolib/dispatcher.hpp
+5
-4
contracts/eosiolib/multi_index.hpp
contracts/eosiolib/multi_index.hpp
+13
-14
tests/wasm_tests/multisig_tests.cpp
tests/wasm_tests/multisig_tests.cpp
+1
-10
未找到文件。
contracts/eosiolib/dispatcher.hpp
浏览文件 @
143579f5
...
...
@@ -40,14 +40,15 @@ namespace eosio {
template
<
typename
T
,
typename
...
Args
>
bool
execute_action
(
T
*
obj
,
void
(
T
::*
func
)(
Args
...)
)
{
size_t
size
=
action_data_size
();
char
default_buffer
[
512
];
//using malloc/free here potentially is not exception-safe, although WASM doesn't support exceptions
char
*
buffer
=
size
<=
sizeof
(
default_buffer
)
?
default_buffer
:
(
char
*
)
malloc
(
size
);
constexpr
size_t
max_stack_buffer_size
=
512
;
void
*
buffer
=
max_stack_buffer_size
<
size
?
malloc
(
size
)
:
alloca
(
size
);
read_action_data
(
buffer
,
size
);
auto
args
=
unpack
<
std
::
tuple
<
std
::
decay_t
<
Args
>
...
>>
(
buffer
,
size
);
auto
args
=
unpack
<
std
::
tuple
<
std
::
decay_t
<
Args
>
...
>>
(
(
char
*
)
buffer
,
size
);
if
(
buffer
!=
default_buffer
)
{
if
(
max_stack_buffer_size
<
size
)
{
free
(
buffer
);
}
...
...
contracts/eosiolib/multi_index.hpp
浏览文件 @
143579f5
...
...
@@ -154,6 +154,8 @@ class multi_index
return
(
n
&
0x000000000000000FULL
)
==
0
;
}
constexpr
static
size_t
max_stack_buffer_size
=
512
;
static_assert
(
validate_table_name
(
TableName
),
"multi_index does not support table names with a length greater than 12"
);
uint64_t
_code
;
...
...
@@ -440,16 +442,15 @@ class multi_index
auto
size
=
db_get_i64
(
itr
,
nullptr
,
0
);
eosio_assert
(
size
>=
0
,
"error reading iterator"
);
char
default_buffer
[
512
];
//using malloc/free here potentially is not exception-safe, although WASM doesn't support exceptions
char
*
buffer
=
size_t
(
size
)
<=
sizeof
(
default_buffer
)
?
default_buffer
:
(
char
*
)
malloc
(
size_t
(
size
)
);
void
*
buffer
=
max_stack_buffer_size
<
size_t
(
size
)
?
malloc
(
size_t
(
size
))
:
alloca
(
size_t
(
size
)
);
db_get_i64
(
itr
,
buffer
,
uint32_t
(
size
)
);
datastream
<
const
char
*>
ds
(
buffer
,
uint32_t
(
size
)
);
datastream
<
const
char
*>
ds
(
(
char
*
)
buffer
,
uint32_t
(
size
)
);
if
(
buffer
!=
default_buffer
)
{
free
(
buffer
);
if
(
max_stack_buffer_size
<
size_t
(
size
)
)
{
free
(
buffer
);
}
auto
itm
=
std
::
make_unique
<
item
>
(
this
,
[
&
](
auto
&
i
)
{
...
...
@@ -628,19 +629,18 @@ class multi_index
size_t
size
=
pack_size
(
obj
);
char
default_buffer
[
512
];
//using malloc/free here potentially is not exception-safe, although WASM doesn't support exceptions
char
*
buffer
=
size
<=
sizeof
(
default_buffer
)
?
default_buffer
:
(
char
*
)
malloc
(
size
);
void
*
buffer
=
max_stack_buffer_size
<
size
?
malloc
(
size
)
:
alloca
(
size
);
datastream
<
char
*>
ds
(
buffer
,
size
);
datastream
<
char
*>
ds
(
(
char
*
)
buffer
,
size
);
ds
<<
obj
;
auto
pk
=
obj
.
primary_key
();
i
.
__primary_itr
=
db_store_i64
(
_scope
,
TableName
,
payer
,
pk
,
buffer
,
size
);
if
(
buffer
!=
default_buffer
)
{
free
(
buffer
);
if
(
max_stack_buffer_size
<
size
)
{
free
(
buffer
);
}
if
(
pk
>=
_next_primary_key
)
...
...
@@ -688,16 +688,15 @@ class multi_index
eosio_assert
(
pk
==
obj
.
primary_key
(),
"updater cannot change primary key when modifying an object"
);
size_t
size
=
pack_size
(
obj
);
char
default_buffer
[
512
];
//using malloc/free here potentially is not exception-safe, although WASM doesn't support exceptions
char
*
buffer
=
size
<=
sizeof
(
default_buffer
)
?
default_buffer
:
(
char
*
)
malloc
(
size
);
void
*
buffer
=
max_stack_buffer_size
<
size
?
malloc
(
size
)
:
alloca
(
size
);
datastream
<
char
*>
ds
(
buffer
,
size
);
datastream
<
char
*>
ds
(
(
char
*
)
buffer
,
size
);
ds
<<
obj
;
db_update_i64
(
objitem
.
__primary_itr
,
payer
,
buffer
,
size
);
if
(
buffer
!=
default_buffer
)
{
if
(
max_stack_buffer_size
<
size
)
{
free
(
buffer
);
}
...
...
tests/wasm_tests/multisig_tests.cpp
浏览文件 @
143579f5
...
...
@@ -247,16 +247,7 @@ BOOST_FIXTURE_TEST_CASE( big_transaction, eosio_msig_tester ) try {
transaction
trx
;
contracts
::
abi_serializer
::
from_variant
(
pretty_trx
,
trx
,
get_resolver
());
/*
trx.actions.emplace_back( perm,
contracts::setcode{
.account = N(alice),
.vmtype = 0,
.vmversion = 0,
//.code = bytes(eosio_msig_wast, eosio_msig_wast + strlen(eosio_msig_wast))
.code = bytes( wasm.begin(), wasm.end() )
});
*/
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
alice
),
N
(
propose
),
mvo
()
(
"proposer"
,
"alice"
)
(
"proposal_name"
,
"first"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录