Skip to content

Commit f83e023

Browse files
authored
Merge pull request #517 from evoskuil/master
Avoid assigning shared ptr dereference to reference.
2 parents cf58cbb + 88c036c commit f83e023

File tree

8 files changed

+133
-67
lines changed

8 files changed

+133
-67
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ Makefile
88
Makefile.in
99
libbitcoin-database.pc
1010

11+
bin
1112
obj
13+
build
1214
.*.swp
1315
*~
1416
/*.kdev4
@@ -25,9 +27,5 @@ obj
2527
/libtool
2628
.dirstamp
2729

28-
/tools/initchain/initchain
29-
30-
/bin
31-
/obj
3230
*.vsidx
3331
*.lock

.vscode/launch.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "(gdb) Launch",
9+
"type": "cppdbg",
10+
"request": "launch",
11+
"program": "${workspaceFolder}/obj/nix-gnu-debug-static/libbitcoin-database-test",
12+
"args": [],
13+
"stopAtEntry": false,
14+
"cwd": "${workspaceFolder}/obj/nix-gnu-debug-static",
15+
"environment": [],
16+
"externalConsole": false,
17+
"MIMode": "gdb",
18+
"setupCommands": [
19+
{
20+
"description": "Enable pretty-printing for gdb",
21+
"text": "-enable-pretty-printing",
22+
"ignoreFailures": true
23+
},
24+
{
25+
"description": "Set Disassembly Flavor to Intel",
26+
"text": "-gdb-set disassembly-flavor intel",
27+
"ignoreFailures": true
28+
}
29+
]
30+
}
31+
]
32+
}

.vscode/tasks.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"type": "cmake",
6+
"label": "CMake: build",
7+
"command": "build",
8+
"targets": [
9+
"all"
10+
],
11+
"preset": "${command:cmake.activeBuildPresetName}",
12+
"group": "build",
13+
"problemMatcher": [],
14+
"detail": "CMake template build task"
15+
},
16+
{
17+
"type": "cmake",
18+
"label": "CMake: clean",
19+
"command": "clean",
20+
"preset": "${command:cmake.activeBuildPresetName}",
21+
"problemMatcher": [],
22+
"detail": "CMake template clean task"
23+
},
24+
{
25+
"type": "cmake",
26+
"label": "CMake: install",
27+
"command": "install",
28+
"preset": "${command:cmake.activeBuildPresetName}",
29+
"problemMatcher": [],
30+
"detail": "CMake template install task"
31+
}
32+
]
33+
}

builds/cmake/CMakePresets.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "nix-base",
66
"description": "Factored base settings for non-windows *nix based platforms.",
77
"hidden": true,
8-
"installDir": "${sourceParentDir}/../../prefix/${presetName}",
8+
"installDir": "${sourceParentDir}/../../../prefix/${presetName}",
99
"binaryDir": "${sourceParentDir}/../obj/${presetName}",
1010
"condition": {
1111
"type": "inList",
@@ -18,11 +18,11 @@
1818
"cacheVariables": {
1919
"CMAKE_PREFIX_PATH": {
2020
"type": "PATH",
21-
"value": "${sourceParentDir}/../../prefix/${presetName}"
21+
"value": "${sourceParentDir}/../../../prefix/${presetName}"
2222
},
2323
"CMAKE_LIBRARY_PATH": {
2424
"type": "PATH",
25-
"value": "${sourceParentDir}/../../prefix/${presetName}/lib:$env{CMAKE_LIBRARY_PATH}"
25+
"value": "${sourceParentDir}/../../../prefix/${presetName}/lib:$env{CMAKE_LIBRARY_PATH}"
2626
}
2727
}
2828
},
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
2-
"folders": [
3-
{
4-
"path": "../../../libbitcoin-database"
5-
}
6-
],
7-
"settings": {}
2+
"folders": [
3+
{
4+
"path": "../../../libbitcoin-system"
5+
},
6+
{
7+
"path": "../../../libbitcoin-database"
8+
}
9+
],
10+
"settings": {}
811
}

include/bitcoin/database/impl/query/archive.ipp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ bool CLASS::populate(const transaction& tx) const NOEXCEPT
154154
BC_ASSERT(!tx.is_coinbase());
155155

156156
auto result = true;
157-
const auto& ins = *tx.inputs_ptr();
158-
std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT
157+
const auto& ins = tx.inputs_ptr();
158+
std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT
159159
{
160160
result &= populate(*in);
161161
});
@@ -166,16 +166,16 @@ bool CLASS::populate(const transaction& tx) const NOEXCEPT
166166
TEMPLATE
167167
bool CLASS::populate(const block& block) const NOEXCEPT
168168
{
169-
const auto& txs = *block.transactions_ptr();
170-
if (txs.empty())
169+
const auto& txs = block.transactions_ptr();
170+
if (txs->empty())
171171
return false;
172172

173173
auto result = true;
174-
std::for_each(std::next(txs.begin()), txs.end(),
174+
std::for_each(std::next(txs->begin()), txs->end(),
175175
[&](const auto& tx) NOEXCEPT
176176
{
177-
const auto& ins = *tx->inputs_ptr();
178-
std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT
177+
const auto& ins = tx->inputs_ptr();
178+
std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT
179179
{
180180
result &= populate(*in);
181181
});
@@ -225,8 +225,8 @@ bool CLASS::populate_with_metadata(const transaction& tx,
225225
const tx_link& link) const NOEXCEPT
226226
{
227227
auto result = true;
228-
const auto& ins = *tx.inputs_ptr();
229-
std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT
228+
const auto& ins = tx.inputs_ptr();
229+
std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT
230230
{
231231
result &= populate_with_metadata(*in, link);
232232
});
@@ -240,37 +240,37 @@ bool CLASS::populate_with_metadata(const transaction& tx) const NOEXCEPT
240240
BC_ASSERT(is_coinbase(tx));
241241

242242
// A coinbase tx is allowed only one input.
243-
const auto& input = *tx.inputs_ptr()->front();
243+
const auto& input = tx.inputs_ptr()->front();
244244

245245
// Find any confirmed unspent duplicates of tx (unspent_coinbase_collision).
246246
const auto ec = unspent_duplicates(tx);
247247
if (ec == error::integrity)
248248
return false;
249249

250250
// The prevout of a coinbase is null (not an output of a coinbase tx).
251-
input.metadata.coinbase = false;
252-
input.metadata.spent = (ec != error::unspent_coinbase_collision);
253-
input.metadata.median_time_past = max_uint32;
254-
input.metadata.height = zero;
251+
input->metadata.coinbase = false;
252+
input->metadata.spent = (ec != error::unspent_coinbase_collision);
253+
input->metadata.median_time_past = max_uint32;
254+
input->metadata.height = zero;
255255
return true;
256256
}
257257

258258
TEMPLATE
259259
bool CLASS::populate_with_metadata(const block& block) const NOEXCEPT
260260
{
261-
const auto& txs = *block.transactions_ptr();
262-
if (txs.empty())
261+
const auto& txs = block.transactions_ptr();
262+
if (txs->empty())
263263
return false;
264264

265265
auto result = true;
266-
const auto coinbase = populate_with_metadata(txs.front());
267-
std::for_each(std::next(txs.begin()), txs.end(),
266+
const auto coinbase = populate_with_metadata(txs->front());
267+
std::for_each(std::next(txs->begin()), txs->end(),
268268
[&](const auto& tx) NOEXCEPT
269269
{
270270
const auto link = to_tx(tx.get_hash());
271271
result &= !link.is_terminal();
272-
const auto& ins = *tx->inputs_ptr();
273-
std::for_each(ins.begin(), ins.end(), [&](const auto& in) NOEXCEPT
272+
const auto& ins = tx->inputs_ptr();
273+
std::for_each(ins->begin(), ins->end(), [&](const auto& in) NOEXCEPT
274274
{
275275
result &= populate_with_metadata(*in, link);
276276
});
@@ -743,15 +743,15 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT
743743
const auto& key = tx.get_hash(false);
744744

745745
// Declare puts record.
746-
const auto& ins = *tx.inputs_ptr();
747-
const auto& outs = *tx.outputs_ptr();
746+
const auto& ins = tx.inputs_ptr();
747+
const auto& outs = tx.outputs_ptr();
748748
table::puts::slab puts{};
749-
puts.spend_fks.reserve(ins.size());
750-
puts.out_fks.reserve(outs.size());
749+
puts.spend_fks.reserve(ins->size());
750+
puts.out_fks.reserve(outs->size());
751751

752752
// Declare spends buffer.
753753
std_vector<foreign_point> spends{};
754-
spends.reserve(ins.size());
754+
spends.reserve(ins->size());
755755

756756
// TODO: eliminate shared memory pointer reallocations.
757757
// ========================================================================
@@ -765,13 +765,13 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT
765765

766766
// Allocate spend records.
767767
// Clean single allocation failure (e.g. disk full).
768-
const auto count = possible_narrow_cast<spend_link::integer>(ins.size());
768+
const auto count = possible_narrow_cast<spend_link::integer>(ins->size());
769769
auto spend_fk = store_.spend.allocate(count);
770770
if (spend_fk.is_terminal())
771771
return error::tx_spend_allocate;
772772

773773
// Commit input records (spend records not indexed).
774-
for (const auto& in: ins)
774+
for (const auto& in: *ins)
775775
{
776776
// Commit input record.
777777
// Safe allocation failure, blob linked by unindexed spend.
@@ -833,7 +833,7 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT
833833
}
834834

835835
// Commit output records.
836-
for (const auto& out: outs)
836+
for (const auto& out: *outs)
837837
{
838838
// Safe allocation failure, blob unlinked.
839839
output_link output_fk{};
@@ -864,8 +864,8 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT
864864
{
865865
{},
866866
tx,
867-
system::possible_narrow_cast<ix::integer>(ins.size()),
868-
system::possible_narrow_cast<ix::integer>(outs.size()),
867+
system::possible_narrow_cast<ix::integer>(ins->size()),
868+
system::possible_narrow_cast<ix::integer>(outs->size()),
869869
puts_fk
870870
}))
871871
{
@@ -888,7 +888,7 @@ code CLASS::set_code(tx_link& out_fk, const transaction& tx) NOEXCEPT
888888
if (address_enabled())
889889
{
890890
auto output_fk = puts.out_fks.begin();
891-
for (const auto& out: outs)
891+
for (const auto& out: *outs)
892892
{
893893
// Safe allocation failure, unindexed tx outputs linked by address,
894894
// others unlinked. A replay of committed addresses without indexed

test/query/archive.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,9 +1273,9 @@ BOOST_AUTO_TEST_CASE(query_archive__get_input__genesis__expected)
12731273
BOOST_REQUIRE(query.set(test::genesis, test::context, false, false));
12741274

12751275
const auto tx = test::genesis.transactions_ptr()->front();
1276-
const auto& input = *tx->inputs_ptr()->front();
1277-
BOOST_REQUIRE(input == *query.get_input(query.to_tx(tx->hash(false)), 0u));
1278-
BOOST_REQUIRE(input == *query.get_input(0));
1276+
const auto input = tx->inputs_ptr()->front();
1277+
BOOST_REQUIRE(*input == *query.get_input(query.to_tx(tx->hash(false)), 0u));
1278+
BOOST_REQUIRE(*input == *query.get_input(0));
12791279
}
12801280

12811281
BOOST_AUTO_TEST_CASE(query_archive__get_inputs__tx_not_found__nullptr)
@@ -1328,10 +1328,10 @@ BOOST_AUTO_TEST_CASE(query_archive__get_output__genesis__expected)
13281328
BOOST_REQUIRE(query.set(test::genesis, test::context, false, false));
13291329

13301330
const auto tx = test::genesis.transactions_ptr()->front();
1331-
const auto& output1 = *tx->outputs_ptr()->front();
1332-
BOOST_REQUIRE(output1 == *query.get_output(query.to_tx(tx->hash(false)), 0u));
1333-
BOOST_REQUIRE(output1 == *query.get_output({ tx->hash(false), 0u }));
1334-
BOOST_REQUIRE(output1 == *query.get_output(0));
1331+
const auto output1 = tx->outputs_ptr()->front();
1332+
BOOST_REQUIRE(*output1 == *query.get_output(query.to_tx(tx->hash(false)), 0u));
1333+
BOOST_REQUIRE(*output1 == *query.get_output({ tx->hash(false), 0u }));
1334+
BOOST_REQUIRE(*output1 == *query.get_output(0));
13351335
}
13361336

13371337
BOOST_AUTO_TEST_CASE(query_archive__get_outputs__tx_not_found__nullptr)
@@ -1473,11 +1473,11 @@ BOOST_AUTO_TEST_CASE(query_archive__get_spenders__unspent_or_not_found__expected
14731473
//// BOOST_REQUIRE_EQUAL(query.get_spenders(1, 2)->size(), 0u);
14741474
////
14751475
//// // Match the two spenders.
1476-
//// const auto& block_inputs = *test::block2a.transactions_ptr()->front()->inputs_ptr();
1477-
//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->front() == *block_inputs.front());
1478-
//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->front() == *block_inputs.back());
1479-
//// BOOST_REQUIRE(*query.get_spenders(1, 0)->front() == *block_inputs.front());
1480-
//// BOOST_REQUIRE(*query.get_spenders(1, 1)->front() == *block_inputs.back());
1476+
//// const auto block_inputs = test::block2a.transactions_ptr()->front()->inputs_ptr();
1477+
//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->front() == *(*block_inputs).front());
1478+
//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->front() == *(*block_inputs).back());
1479+
//// BOOST_REQUIRE(*query.get_spenders(1, 0)->front() == *(*block_inputs).front());
1480+
//// BOOST_REQUIRE(*query.get_spenders(1, 1)->front() == *(*block_inputs).back());
14811481
////
14821482
//// // Each of the two outputs of block1a spent twice (two unconfirmed double spends).
14831483
//// BOOST_REQUIRE(query.set(test::tx4));
@@ -1489,15 +1489,15 @@ BOOST_AUTO_TEST_CASE(query_archive__get_spenders__unspent_or_not_found__expected
14891489
//// BOOST_REQUIRE_EQUAL(query.get_spenders(1, 2)->size(), 0u);
14901490
////
14911491
//// // Match the four spenders.
1492-
//// const auto& tx_inputs = *test::tx4.inputs_ptr();
1493-
//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->front() == *tx_inputs.front());
1494-
//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->front() == *tx_inputs.back());
1495-
//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->back() == *block_inputs.front());
1496-
//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->back() == *block_inputs.back());
1497-
//// BOOST_REQUIRE(*query.get_spenders(1, 0)->front() == *tx_inputs.front());
1498-
//// BOOST_REQUIRE(*query.get_spenders(1, 1)->front() == *tx_inputs.back());
1499-
//// BOOST_REQUIRE(*query.get_spenders(1, 0)->back() == *block_inputs.front());
1500-
//// BOOST_REQUIRE(*query.get_spenders(1, 1)->back() == *block_inputs.back());
1492+
//// const auto tx_inputs = test::tx4.inputs_ptr();
1493+
//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->front() == *(*tx_inputs).front());
1494+
//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->front() == *(*tx_inputs).back());
1495+
//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 0))->back() == *(*block_inputs).front());
1496+
//// BOOST_REQUIRE(*query.get_spenders(query.to_output(1, 1))->back() == *(*block_inputs).back());
1497+
//// BOOST_REQUIRE(*query.get_spenders(1, 0)->front() == *(*tx_inputs).front());
1498+
//// BOOST_REQUIRE(*query.get_spenders(1, 1)->front() == *(*tx_inputs).back());
1499+
//// BOOST_REQUIRE(*query.get_spenders(1, 0)->back() == *(*block_inputs).front());
1500+
//// BOOST_REQUIRE(*query.get_spenders(1, 1)->back() == *(*block_inputs).back());
15011501
////}
15021502

15031503
BOOST_AUTO_TEST_CASE(query_archive__get_value__genesis__expected)

test/tables/caches/buffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
////using namespace system;
2525
////const chain::transaction empty{};
2626
////const auto genesis = system::settings{ system::chain::selection::mainnet }.genesis_block;
27-
////const auto& genesis_tx = *genesis.transactions_ptr()->front();
27+
////const auto genesis_tx = genesis.transactions_ptr()->front();
2828
////const table::buffer::key key1{ 0x01, 0x02, 0x03, 0x04 };
2929
////const table::buffer::key key2{ 0xa1, 0xa2, 0xa3, 0xa4 };
3030
////const table::buffer::slab slab1{ {}, empty };
31-
////const table::buffer::slab slab2{ {}, genesis_tx };
31+
////const table::buffer::slab slab2{ {}, *genesis_tx };
3232
////const data_chunk expected_head = base16_chunk
3333
////(
3434
//// "0000000000"

0 commit comments

Comments
 (0)