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

pull domob1812 wants to merge 1 commits into bitcoin:master from domob1812:miner-uniqueptr changing 5 files +15 −24
  1. domob1812 commented at 6:32 pm on June 18, 2016: contributor
    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.
  2. [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.
    9fce0629b4
  3. in src/miner.cpp: in 9fce0629b4
    164@@ -164,7 +165,7 @@ CBlockTemplate* BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn)
    165         throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, FormatStateMessage(state)));
    166     }
    167 
    168-    return pblocktemplate.release();
    169+    return std::move(pblocktemplate);
    


    sipa commented at 6:37 pm on June 18, 2016:
    Return value optimization applies here; I think using std::move is discouraged in that case.

    domob1812 commented at 6:41 pm on June 18, 2016:
    No, it does not. pblocktemplate is a member variable and not a local one, I think the code does not compile without std::move.
  4. sipa commented at 6:42 pm on June 18, 2016: member
    Oops, I forgot we just merged the refactor that turned it into a class. You’re right.
  5. luke-jr commented at 7:02 pm on June 18, 2016: member
    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…
  6. MarcoFalke added the label Refactoring on Jun 18, 2016
  7. dcousens commented at 3:43 am on June 19, 2016: contributor
    utACK 9fce062
  8. in src/miner.h: in 9fce0629b4
    159@@ -160,7 +160,7 @@ class BlockAssembler
    160 public:
    161     BlockAssembler(const CChainParams& chainparams);
    162     /** Construct a new block template with coinbase to scriptPubKeyIn */
    163-    CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn);
    164+    std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn);
    


    laanwj commented at 12:01 pm on June 20, 2016:
    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?

    sipa commented at 12:06 pm on June 20, 2016:
    Converting from unique_ptr to shared_ptr is relatively cheap (specifically, does not require copying the object).

    laanwj commented at 12:29 pm on June 20, 2016:
    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.
  9. laanwj commented at 7:13 pm on October 18, 2016: member
    utACK 9fce062
  10. laanwj merged this on Oct 18, 2016
  11. laanwj closed this on Oct 18, 2016

  12. laanwj referenced this in commit 744d2652dd on Oct 18, 2016
  13. domob1812 deleted the branch on Oct 19, 2016
  14. codablock referenced this in commit 02366321e6 on Sep 19, 2017
  15. codablock referenced this in commit 85706a0ae5 on Jan 12, 2018
  16. andvgal referenced this in commit a47b84e7ed on Jan 6, 2019
  17. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-22 09:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me