Skip to content

Commit 9159715

Browse files
authored
Merge pull request #1645 from evoskuil/master
Make chain_state pointers const.
2 parents 71dae59 + 7496aa3 commit 9159715

6 files changed

Lines changed: 10 additions & 29 deletions

File tree

include/bitcoin/system/chain/chain_state.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class BC_API chain_state
4949
typedef std::deque<uint32_t> bitss;
5050
typedef std::deque<uint32_t> versions;
5151
typedef std::deque<uint32_t> timestamps;
52-
typedef std::shared_ptr<chain_state> ptr;
52+
typedef std::shared_ptr<const chain_state> cptr;
5353
typedef struct { size_t count; size_t high; } range;
5454

5555
/// Heights used to identify construction requirements.

include/bitcoin/system/impl/machine/interpreter.ipp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,6 @@ connect(const context& state, const transaction& tx,
16491649
return error::script_success;
16501650
}
16511651

1652-
BC_PUSH_WARNING(NO_NEW_OR_DELETE)
16531652
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
16541653

16551654
template <typename Stack>
@@ -1695,7 +1694,6 @@ code interpreter<Stack>::connect_embedded(const context& state,
16951694
return error::script_success;
16961695
}
16971696

1698-
BC_POP_WARNING()
16991697
BC_POP_WARNING()
17001698

17011699
template <typename Stack>

src/chain/block.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ code block::identify(const context& ctx) const NOEXCEPT
878878
// In the case of validation failure
879879
// The block header is checked/accepted independently.
880880

881-
// TODO: use of get_hash() in is_forward_reference makes this thread-unsafe.
881+
// Use of get_hash() in is_forward_reference makes this thread-unsafe.
882882
code block::check() const NOEXCEPT
883883
{
884884
// empty_block is subset of first_not_coinbase.
@@ -908,7 +908,7 @@ code block::check() const NOEXCEPT
908908
// timestamp
909909
// median_time_past
910910

911-
// TODO: use of get_hash() in is_hash_limit_exceeded makes this thread-unsafe.
911+
// Use of get_hash() in is_hash_limit_exceeded makes this thread-unsafe.
912912
// bip141 should be disabled when the node is not accepting witness data.
913913
code block::check(const context& ctx) const NOEXCEPT
914914
{

src/chain/input.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,14 @@ static_assert(max_script_size <
4848
// static/private
4949
const witness& input::no_witness() NOEXCEPT
5050
{
51-
static const chain::witness empty_witness{};
52-
return empty_witness;
51+
static const chain::witness empty{};
52+
return empty;
5353
}
5454

5555
// static/private
5656
const witness::cptr& input::no_witness_cptr() NOEXCEPT
5757
{
58-
BC_PUSH_WARNING(NO_NEW_OR_DELETE)
59-
static const std::shared_ptr<const chain::witness> empty
60-
{
61-
new const chain::witness{}
62-
};
63-
BC_POP_WARNING()
58+
static const auto empty = std::make_shared<const chain::witness>();
6459
return empty;
6560
}
6661

src/chain/operation.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,22 @@ static constexpr auto any_invalid = opcode::op_xor;
4545
// static/private
4646
const data_chunk& operation::no_data() NOEXCEPT
4747
{
48-
static const data_chunk empty_data{};
49-
return empty_data;
48+
static const data_chunk empty{};
49+
return empty;
5050
}
5151

5252
// static/private
5353
const chunk_cptr& operation::no_data_cptr() NOEXCEPT
5454
{
55-
BC_PUSH_WARNING(NO_NEW_OR_DELETE)
56-
static const std::shared_ptr<const data_chunk> empty
57-
{
58-
new const data_chunk{}
59-
};
60-
BC_POP_WARNING()
55+
static const auto empty = std::make_shared<const data_chunk>();
6156
return empty;
6257
}
6358

6459
// static/private
6560
// Push data is not possible with an invalid code, combination is invalid.
6661
const chunk_cptr& operation::any_data_cptr() NOEXCEPT
6762
{
68-
BC_PUSH_WARNING(NO_NEW_OR_DELETE)
69-
static const std::shared_ptr<const data_chunk> any
70-
{
71-
new const data_chunk{ 0x42 }
72-
};
73-
BC_POP_WARNING()
63+
static const auto any = to_shared(data_chunk{ 0x42 });
7464
return any;
7565
}
7666

src/crypto/pseudo_random.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ namespace libbitcoin {
3030
namespace system {
3131

3232
BC_PUSH_WARNING(NO_STATIC_CAST)
33-
BC_PUSH_WARNING(NO_NEW_OR_DELETE)
3433
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
3534
BC_PUSH_WARNING(NO_CASTS_FOR_ARITHMETIC_CONVERSION)
3635

@@ -104,7 +103,6 @@ steady_clock::duration pseudo_random::duration(
104103
BC_POP_WARNING()
105104
BC_POP_WARNING()
106105
BC_POP_WARNING()
107-
BC_POP_WARNING()
108106

109107
} // namespace system
110108
} // namespace libbitcoin

0 commit comments

Comments
 (0)