Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c++11] Use std::unique_ptr for block creation. #8223

Merged
merged 1 commit into from Oct 18, 2016

Conversation

@domob1812
Copy link
Contributor

commented Jun 18, 2016

CreateNewBlock returns a pointer for which the caller takes ownership. Use std::unique_ptr to make this explicit and simplify handling of these objects in getblocktemplate.

[c++11] Use std::unique_ptr for block creation.
CreateNewBlock returns a pointer for which the caller takes ownership.
Use std::unique_ptr to make this explicit and simplify handling of these
objects in getblocktemplate.
@@ -164,7 +165,7 @@ CBlockTemplate* BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn)
throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, FormatStateMessage(state)));
}

return pblocktemplate.release();
return std::move(pblocktemplate);

This comment has been minimized.

Copy link
@sipa

sipa Jun 18, 2016

Member

Return value optimization applies here; I think using std::move is discouraged in that case.

This comment has been minimized.

Copy link
@domob1812

domob1812 Jun 18, 2016

Author Contributor

No, it does not. pblocktemplate is a member variable and not a local one, I think the code does not compile without std::move.

@sipa

This comment has been minimized.

Copy link
Member

commented Jun 18, 2016

Oops, I forgot we just merged the refactor that turned it into a class. You're right.

@luke-jr

This comment has been minimized.

Copy link
Member

commented Jun 18, 2016

Concept ACK. But it might make more sense to use a shared_ptr so TestBlockValidity can be split off to a new thread while GBT returns...

@dcousens

This comment has been minimized.

Copy link
Contributor

commented Jun 19, 2016

utACK 9fce062

@@ -160,7 +160,7 @@ class BlockAssembler
public:
BlockAssembler(const CChainParams& chainparams);
/** Construct a new block template with coinbase to scriptPubKeyIn */
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn);
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn);

This comment has been minimized.

Copy link
@laanwj

laanwj Jun 20, 2016

Member

Shouldn't the caller decide in what kind of pointer to wrap the object?
What if they want to e.g. have a shared pointer instead?

This comment has been minimized.

Copy link
@sipa

sipa Jun 20, 2016

Member

Converting from unique_ptr to shared_ptr is relatively cheap (specifically, does not require copying the object).

This comment has been minimized.

Copy link
@laanwj

laanwj Jun 20, 2016

Member

But does this mean we want all functions that currently return a bare pointer that will become caller ownership to returning unique_ptr?
This is probably the kind of c++11 refactoring that we want to leave for later.

@laanwj

This comment has been minimized.

Copy link
Member

commented Oct 18, 2016

utACK 9fce062

@laanwj laanwj merged commit 9fce062 into bitcoin:master Oct 18, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
laanwj added a commit that referenced this pull request Oct 18, 2016
Merge #8223: [c++11] Use std::unique_ptr for block creation.
9fce062 [c++11] Use std::unique_ptr for block creation. (Daniel Kraft)

@domob1812 domob1812 deleted the domob1812:miner-uniqueptr branch Oct 19, 2016

codablock added a commit to codablock/dash that referenced this pull request Jan 12, 2018
Merge bitcoin#8223: [c++11] Use std::unique_ptr for block creation.
9fce062 [c++11] Use std::unique_ptr for block creation. (Daniel Kraft)
andvgal added a commit to energicryptocurrency/energi that referenced this pull request Jan 6, 2019
Merge bitcoin#8223: [c++11] Use std::unique_ptr for block creation.
9fce062 [c++11] Use std::unique_ptr for block creation. (Daniel Kraft)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
6 participants
You can’t perform that action at this time.