Cleanup code by using forward declarations and other methods… #2767

pull brandondahler wants to merge 1 commits into bitcoin:master from brandondahler:header-cleanup changing 177 files +2028 −1625
  1. brandondahler commented at 4:55 am on June 14, 2013: contributor

    … of avoiding unnecessary header includes. Additionally alphabetizes and groups includes and forward declarations.

    Note: there are a large amount of changes that have been rebased onto the most recent master. I did my best to ensure that no code was functionally changed; however, a code review of all my changes would be advised.

    Theory

    By using forward declarations, compilation speed can be increased in both incremental and full builds.

    Forward declarations suffice over having the full declaration in cases where the type that is being forward declared is only used as a reference or being pointed to, and the usage is not an lvalue.

    By making these modifications, the total number of header files needed to compile any .cpp file is reduced. Fewer header files being included reduces the total amount of code that needs to be compiled for each .cpp file.

    Quantitative Results

    How much time does this actually account for?

    For bitcoind: Bitcoind Results

    This spreadsheet shows detailed results for each of the different builds (note that there are multiple sheets in the spreadsheet), along with the interesting stats and graph for each.

    This data was generated automatically via the scripts here.

    Method

    • Go through each file, group each #include by type (see Order) and sort alphabetically
    • Using doxygen with the graphviz dots extension
      • Go through each header, comment each #include individually and all headers that indirectly include the commented one
      • See if it can build with the #include commented, analyze errors to understand if they can actually be solved with forward declares
      • Remove, keep, or add a direct header to the required type, as needed.

    Order

    Most Generic

     0// License text as first
     1// lines
     2
     3#if defined(HAVE_CONFIG_H)
     4#include "bitcoin-config.h"
     5#endif
     6
     7#include "matching_file.h"
     8
     9#include "local_file1.h"
    10#include "local_file2.h"
    11
    12#include "file_in_other_dir1.h"
    13#include "file_in_other_dir2.h"
    14
    15#include <system1.h>
    16#include <system2.h>
    17
    18#ifdef SOMETHING1
    19#include <system3.h>
    20#endif
    21
    22#include "json/a_file.h"
    23#include <library1.h>
    24#include <library2.h>
    25
    26#ifdef SOMETHING2
    27#include <library3.h>
    28#endif
    29
    30class ForwardDeclare1;
    31class ForwardDeclare2;
    32
    33namespace SomeNamespace {
    34    class ForwardDeclare3;
    35}
    36
    37...
    

    Example1 - No matching file, no file_in_other_dir, no ifdefs

     0// License text as first
     1// lines
     2
     3#include "local_file1.h"
     4#include "local_file2.h"
     5
     6#include <system1.h>
     7#include <system2.h>
     8
     9#include "json/a_file.h"
    10#include <library1.h>
    11#include <library2.h>
    12
    13class ForwardDeclare1;
    14class ForwardDeclare2;
    15
    16...
    
  2. gmaxwell commented at 5:03 am on June 14, 2013: contributor
    And how do you prevent very bad thing from happening when one of the many duplicated definitions gets desynchronized?
  3. brandondahler commented at 5:12 am on June 14, 2013: contributor

    Rebasing conflicts on the actual code changes made (one actual, moving some definitions from a header to the code file). Due diligence was taken on my part to ensure that the conflicts were resolved correctly, I would still recommend someone bite the bullet and look at all the changes that are not adding/removing/reordering header files.

    Rebasing additionally conflicted on include files being added/removed usually because most of the includes were re-ordered, these were easy to resolve.

  4. laanwj commented at 8:46 am on June 14, 2013: member

    @gmaxwell From what I understand this does not duplicate anything. It does pre-declare classes, but that only consists of the name and nothing more.

    At first glance this seems like a lot of changes, but it’s almost entirely restricted to the #include portion of files. The only substantial code move is moving WalletDB.h functions to its implementation file.

    There’s problems with compiling the tests after this, though (see pulltester output).

    0test/script_tests.cpp: In function 'CScript ParseScript(std::string)':
    1test/script_tests.cpp:47: error: 'replace_first' was not declared in this scope
    
  5. in src/addrman.h: in a497d3d260 outdated
     5@@ -6,16 +6,16 @@
     6 
     7 #include "netbase.h"
     8 #include "protocol.h"
     9-#include "util.h"
    10 #include "sync.h"
    11+#include "util.h"
    12 
    13-
    14+#include <cstdio>
    


    sipa commented at 9:30 am on June 14, 2013:
    What is this needed for?

    brandondahler commented at 4:31 pm on June 15, 2013:
    The “printf"s on lines 406, 422, and 428.

    sipa commented at 7:03 pm on June 15, 2013:
    printf is #define’d in util.h to be OutputDebugStringF.

    Diapolo commented at 3:56 pm on June 16, 2013:
    Yeah, printf is our own macro.
  6. in src/crypter.h: in a497d3d260 outdated
    58@@ -59,6 +59,7 @@ class CMasterKey
    59 };
    60 
    61 typedef std::vector<unsigned char, secure_allocator<unsigned char> > CKeyingMaterial;
    62+typedef std::vector<unsigned char, secure_allocator<unsigned char> > CSecret;
    


    sipa commented at 9:34 am on June 14, 2013:
    CSecret doesn’t exist anymore since #2600.
  7. in src/net.cpp: in a497d3d260 outdated
     7 #include "net.h"
     8-#include "core.h"
     9+
    10 #include "addrman.h"
    11+#include "db.h"
    12+#include "main.h"
    


    sipa commented at 9:36 am on June 14, 2013:
    Net shouldn’t depend on main anymore since #2154, only on core.
  8. sipa commented at 9:42 am on June 14, 2013: member

    I’m generally in favor of cleanups like this, and it indeed seems pure code movement + include changes.

    However:

    • Some changes seem not up-to-date with recent refactors (see inline comments)
    • I’m not sure I like the increased use of forward declarations. They don’t remove actual code dependencies, but they hide them. Of course we’re already using them, and the compilation performance improvements it gives may be worth it. Other devs opinions?
    • Regarding uint64 and int64: I’d prefer including stdint.h and using int64_t and uint64_t instead, over redeclaring them all over the place. @CodeShark Mind taking a look at this? Does it interfere with the dependencies cleanup?
  9. laanwj commented at 10:58 am on June 14, 2013: member

    Getting rid of code dependencies is even better, but in the general case if it is possible do forward declarations instead of an #include in a header I’m in favor of that. It generates a flatter include hierarchy, let’s not give the C++ compiler more work than need be.

    Re: uint64_t/int32_t I agree. If available, they should be used, as they take the burden of determining data type sizes from us, at least on most platforms.

  10. brandondahler commented at 4:40 pm on June 15, 2013: contributor

    Addressed the specific problems references inline.

    Hopefully should pass build, don’t know why it built on my machine to be honest.

  11. brandondahler commented at 3:49 am on June 17, 2013: contributor
    Delt with cstdio problems. Also normalized all [u]int64 types to [u]int64_t values from stdint.h, alongside replacing PRI64[xdu] with PRI[xdu]64 from inttypes.h .
  12. luke-jr commented at 3:52 am on June 17, 2013: member
    @brandondahler Simply replacing [u]int64 types with stdint will probably break something - we tried this like a year ago and had to revert it :(
  13. brandondahler commented at 3:55 am on June 17, 2013: contributor
    @luke-jr It was a non-negligable change, but it did compile and pass tests on my linux machine. Was the issue with compiling on other architectures?
  14. luke-jr commented at 9:46 pm on July 16, 2013: member

    @brandondahler Reviewing logs, it looks like it didn’t build on 64-bit Fedora. I don’t believe we ever fully diagnosed the reason, but:

     0[Wednesday, December 21, 2011] [3:15:25 PM] <jgarzik>   serialize.h: In function unsigned int GetSerializeSize(int64
     1_t, int, int):
     2[Wednesday, December 21, 2011] [3:15:26 PM] <jgarzik>   serialize.h:139:21: error: redefinition of unsigned int GetS
     3erializeSize(int64_t, int, int)
     4[Wednesday, December 21, 2011] [3:15:26 PM] <jgarzik>   serialize.h:137:21: error: unsigned int GetSerializeSize(lon
     5g int, int, int) previously defined here
     6[Wednesday, December 21, 2011] [3:15:38 PM] <jgarzik>   tree is full of broken
     7[Wednesday, December 21, 2011] [3:16:18 PM] Join        larsivi has joined this channel (~quassel@188.113.74.106).
     8[Wednesday, December 21, 2011] [3:16:25 PM] <jgarzik>   luke-jr: ^^
     9[Wednesday, December 21, 2011] [3:16:29 PM] <luke-jr>   jgarzik: works fine here
    10[Wednesday, December 21, 2011] [3:16:56 PM] <jgarzik>   luke-jr: totally broke Fedora build (g++ 4.6.1)
    11[Wednesday, December 21, 2011] [3:17:05 PM] <jgarzik>   luke-jr: on 64-bit
    12[Wednesday, December 21, 2011] [3:17:32 PM] <jgarzik>   luke-jr: breakage is obvious.  64-bit platforms define int64_t==long int
    13[Wednesday, December 21, 2011] [3:17:49 PM] <luke-jr>   jgarzik: 4.5.3 here
    14[Wednesday, December 21, 2011] [3:18:31 PM] <jgarzik>   'int foo(int64_t)' is the same as 'int foo(long)'
    
  15. in src/compat.h: in 8637dc2d61 outdated
    11@@ -12,18 +12,19 @@
    12 #define NOMINMAX
    13 #endif
    14 #define FD_SETSIZE 1024 // max number of fds in fd_set
    15-#include <winsock2.h>
    16 #include <mswsock.h>
    17+#include <winsock2.h>
    


    luke-jr commented at 8:09 pm on July 22, 2013:
    winsock2.h must be included before mswsock.h or build fails.

    Diapolo commented at 8:55 pm on July 22, 2013:

    I also get a MinGW compiler warning that winsock2.h should be included before windows.h from this file in current master.

  16. in src/qt/bitcoinstrings.cpp: in 7a58df8f74 outdated
    0@@ -1,4 +1,7 @@
    1+
    


    Diapolo commented at 6:40 am on July 23, 2013:
    AFAIK you can leave out any mods to this file, as we have a script which generates it and that is likely to revert your small formatting changes everytime we update our translations.

    Diapolo commented at 6:56 am on July 29, 2013:
    Ping - see extract_strings_qt.py in in share/qt, perhaps you can rework how that script outputs this file, if you really care :).

    brandondahler commented at 0:59 am on July 30, 2013:
    Not that I think it really matters, I updated it anyways :). I did not revert the changes to src/qt/bitcoinstrings.cpp because it would just cause more changes later.
  17. in src/qt/bitcoin.cpp: in 7a58df8f74 outdated
    27+#include "util.h"
    28+
    29+#include <stdint.h>
    30+
    31+#include <boost/filesystem/operations.hpp>
    32+#include <QApplication>
    


    Diapolo commented at 6:44 am on July 23, 2013:

    Can you add #undef loop /* Todo: ugh, remove this when the #define loop is gone from util.h */ before all #include <QApplication> you moved or it will break Qt5 compilation on some machines.

    Nevermind, I created a pull for this: #2847

  18. sipa commented at 0:18 am on July 29, 2013: member
    I think most other refactors that were in the pipeline are merged now. Care to rebase this?
  19. brandondahler commented at 3:41 am on July 29, 2013: contributor
    Rebased branch onto master.
  20. in src/qt/addressbookpage.cpp: in d3b01995a6 outdated
    16-#include <QSortFilterProxyModel>
    17-#include <QClipboard>
    18-#include <QMessageBox>
    19+#include <QIcon>
    20 #include <QMenu>
    21+#include <QSortFilterProxyModel>
    


    Diapolo commented at 6:52 am on July 29, 2013:
    Is this needed, as we include it in addressbookpage.h?

    brandondahler commented at 0:40 am on July 30, 2013:

    It is not included in addressbookpage.h–there is only forward declare (see below).

    0QT_BEGIN_NAMESPACE
    1...
    2class QSortFilterProxyModel;
    3...
    4QT_END_NAMESPACE
    

    Diapolo commented at 5:01 am on July 30, 2013:
    My fault, I didn’t look correctly, sorry :).

    brandondahler commented at 2:03 am on July 31, 2013:
    No problems at all, thanks for reviewing the changes :)
  21. in src/qt/qrcodedialog.cpp: in d3b01995a6 outdated
     6@@ -7,12 +7,12 @@
     7 #include "optionsmodel.h"
     8 
     9 #include <QPixmap>
    10+#include <qrencode.h>
    


    Diapolo commented at 11:42 am on July 29, 2013:
    Does this change fit into your proposed style? You move a lib-header in between 2 Qt includes (one of which is in a clause, yes).

    brandondahler commented at 0:47 am on July 30, 2013:

    It does fit how I proposed it (and consequently implemented it). I decided to group all library headers together, see below for the excerpt from the original post with two lines added for clarity.

     0...
     1#include "json/a_file.h"
     2#include <library1.h>
     3#include <library2.h>
     4#include "namedLibrary.h"       // Added
     5
     6#ifdef SOMETHING2
     7#include <aLibraryStartingWithA.h>       // Added
     8#include <library3.h>
     9#endif 
    10...
    
  22. jgarzik commented at 3:11 am on August 25, 2013: contributor

    It would be nice to collapse the commits, and merge in the [u]int64_t change first.

    Looks pretty good overall, though I do worry there is a subtle compiler detail being missed in the int64/int64_t type changes.

    Very much like seeing use of stdint.h and int64_t, rather than using our own type.

  23. Diapolo commented at 1:28 pm on August 29, 2013: none

    I also like the intention of this pull, can you rebase and perhaps follow @jgarzik so we can differentiate the type-changes and the cleanup changes :).

    Edit: Also a merge-speedup is possible, if you create a Qt-only and a core-only pull, as @laanwj is able to merge Qt-pulls much faster than core changes.

    Edit 2: @laanwj Any objection, to start using quint64 or qint64 in Qt code? Perhaps that could also be a scope of a separate Qt pull.

  24. in src/qt/bitcoin.cpp: in ee6d0efccf outdated
    1@@ -2,29 +2,36 @@
    2  * W.J. van der Laan 2011-2012
    3  */
    4 
    5+
    


    Diapolo commented at 1:32 pm on August 29, 2013:
    Nit: remove this new-line.
  25. in src/qt/guiutil.cpp: in ee6d0efccf outdated
    32-#include <QFileDialog>
    33-#include <QDesktopServices>
    34 #include <QThread>
    35 #include <QSettings>
    36-#include <QDesktopWidget>
    37+#include <QUrl>
    


    Diapolo commented at 1:35 pm on August 29, 2013:
    This includes QUrl also for Qt 5 and up, which is not needed AFAIK. Can you check if this was changed in other places also?
  26. in src/qt/bitcoingui.cpp: in ee6d0efccf outdated
    3@@ -4,54 +4,54 @@
    4  * W.J. van der Laan 2011-2012
    5  * The Bitcoin Developers 2011-2012
    6  */
    7-
    


    Diapolo commented at 1:36 pm on August 29, 2013:
    Nit: Above in bitcoin.cpp you keep a new-line after the license ^^.
  27. in src/qt/paymentserver.cpp: in ee6d0efccf outdated
    0@@ -1,6 +1,22 @@
    1 // Copyright (c) 2009-2012 The Bitcoin developers
    2 // Distributed under the MIT/X11 software license, see the accompanying
    3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
    4+#include "paymentserver.h"
    


    Diapolo commented at 1:38 pm on August 29, 2013:
    Nit: missing new-line after license :).
  28. Diapolo commented at 10:56 am on September 7, 2013: none
    I really hope to see PullTester happy and some final ACKs for your great work here.
  29. brandondahler commented at 4:47 am on September 8, 2013: contributor

    Rebased and squashed small commits (made sure that the resuting rebased version is equivalent to the previously merged version).

    I plan on going over the source again to re-alphabetize etc.

  30. gavinandresen commented at 1:30 am on September 9, 2013: contributor
    Pull-tester is fixed, so if it is complaining there is something wrong with your pull. See the test.log to debug.
  31. brandondahler commented at 1:41 am on September 9, 2013: contributor

    @gavinandresen: Are you sure? First two errors for last log are:

    0leveldb.h:11:24: error: leveldb/db.h: No such file or directory
    1leveldb.h:12:33: error: leveldb/write_batch.h: No such file or directory
    

    I think I kicked off the last update by updating my original comment.

  32. gavinandresen commented at 2:19 am on September 9, 2013: contributor

    Am I sure pull-tester is working? Yes, see http://jenkins.bluematt.me/pull-tester/102518fdb711b646dec8f0cc26fa170364bf2e0b/test.logfor a successful pull-test from 2 hours ago.

    On Mon, Sep 9, 2013 at 11:41 AM, Brandon Dahler notifications@github.comwrote:

    @gavinandresen https://github.com/gavinandresen: Are you sure? First two errors for last log are:

    leveldb.h:11:24: error: leveldb/db.h: No such file or directory leveldb.h:12:33: error: leveldb/write_batch.h: No such file or directory

    I think I kicked off the last update by updating my original comment.

    — Reply to this email directly or view it on GitHubhttps://github.com/bitcoin/bitcoin/pull/2767#issuecomment-24034659 .

    Gavin Andresen

  33. in src/crypter.h: in 721a13900d outdated
    0@@ -1,13 +1,14 @@
    1 // Copyright (c) 2009-2012 The Bitcoin Developers
    2 // Distributed under the MIT/X11 software license, see the accompanying
    3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
    4+
    5 #ifndef __CRYPTER_H__
    6 #define __CRYPTER_H__
    7 
    8-#include "allocators.h" /* for SecureString */
    


    sipa commented at 11:14 am on September 13, 2013:
    You’re hiding the SecureString dependency on allocators.h by indirect include via serialize.h?

    brandondahler commented at 5:58 pm on September 15, 2013:
    Added back.
  34. in src/hash.h: in 721a13900d outdated
     1@@ -2,16 +2,18 @@
     2 // Copyright (c) 2009-2012 The Bitcoin developers
     3 // Distributed under the MIT/X11 software license, see the accompanying
     4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
     5+
     6 #ifndef BITCOIN_HASH_H
     7 #define BITCOIN_HASH_H
     8 
     9 #include "uint256.h"
    10-#include "serialize.h"
    


    sipa commented at 11:17 am on September 13, 2013:
    serialize.h defines ::Serialize(S, T, int, int), which is used in this file.
  35. in src/key.h: in 721a13900d outdated
     7 #define BITCOIN_KEY_H
     8 
     9-#include <vector>
    10-
    11 #include "allocators.h"
    12-#include "serialize.h"
    


    sipa commented at 11:19 am on September 13, 2013:
    This file uses for example ::WriteCompactSize from serialize.h.
  36. in src/miner.cpp: in 721a13900d outdated
    14+#include "main.h"
    15+#include "wallet.h"
    16 
    17+#include <stdint.h>
    18 
    19+extern std::vector<CNode*> vNodes;
    


    sipa commented at 11:22 am on September 13, 2013:
    This is ugly…
  37. in src/protocol.cpp: in 721a13900d outdated
    3@@ -4,8 +4,10 @@
    4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
    5 
    6 #include "protocol.h"
    7+
    8 #include "util.h"
    9-#include "netbase.h"
    


    sipa commented at 11:24 am on September 13, 2013:
    This file uses CService, defined in netbase.

    brandondahler commented at 5:03 pm on September 15, 2013:
    Included in protocol.h

    sipa commented at 2:14 am on November 10, 2013:
    So? I prefer no indirect dependencies…

    sipa commented at 2:14 am on November 10, 2013:
    Ugh, sorry - forgot which file I was looking at. Ignore my comment.
  38. in src/uint256.h: in 721a13900d outdated
    584@@ -589,8 +585,8 @@ class uint256 : public base_uint256
    585     }
    586 };
    587 
    588-inline bool operator==(const uint256& a, uint64 b)                           { return (base_uint256)a == b; }
    589-inline bool operator!=(const uint256& a, uint64 b)                           { return (base_uint256)a != b; }
    590+inline bool operator==(const uint256& a, uint64_t b)                           { return (base_uint256)a == b; }
    


    sipa commented at 4:01 pm on September 13, 2013:
    Can you keep the alignment here (and elsewhere)?

    brandondahler commented at 4:20 pm on September 15, 2013:
    I don’t understand the question.

    sipa commented at 4:31 pm on September 15, 2013:
    The function bodies used to align; by changing uint64 into uint64_t, operator== and operator!= are now shifted two spaces to the right compared to the rest.

    brandondahler commented at 5:03 pm on September 15, 2013:
    Fixed.
  39. in src/uint256.h: in 721a13900d outdated
     8 
     9-#include <limits.h>
    10-#include <stdio.h>
    11-#include <string.h>
    12-#include <inttypes.h>
    13+#include "util.h"
    


    sipa commented at 4:01 pm on September 13, 2013:
    Why does this need util?
  40. in src/txdb.cpp: in 721a13900d outdated
    3@@ -4,9 +4,10 @@
    4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
    5 
    6 #include "txdb.h"
    


    sipa commented at 4:03 pm on September 13, 2013:
    You’re making all dependencies indirect via txdb.h?

    brandondahler commented at 4:47 pm on September 15, 2013:
    No, but items which are fulfilled fully by the .cpp’s .h file should not be re-included in the .cpp file. I have made a minor change after reviewing txdb.{cpp,h}.
  41. sipa commented at 4:11 pm on September 13, 2013: member

    I started going through the changes, and noticed several missing dependencies, but maybe this is intentional, relying on indirect dependencies?

    I’m very much in favor of cleaning up our dependencies, but hiding things further by making them implicit only worsens understanding the dependency graph, makes things break when you reduce actual dependencies, and has no speed benefit.

  42. brandondahler commented at 4:18 pm on September 15, 2013: contributor

    It is not intentional at all. The idea is that if and only if we can replace a header dependency with a forward declare, do so. Additionally (and this is harder to do), if there are indirect dependencies, add them to be a direct dependency.

    My method to find direct dependencies has been to remove the header(s) that resolve the dependency (using doxygen to find indirect includes of a given header), and analyze the error messages to see if the file actually uses the header. If so see if we can optimize the header out with forward declares, and if not make sure we #include it directly.

    The method to find indirect dependencies has been to assume they will show up as un-related build errors and make them work.

    All of this being said, I don’t know the project well enough to know exactly where things are, so my methods have a certain amount of flaws in them. This is one of the reasons why I say that there will be a major need to review the changes I make.

    I will do my best to resolve the issues you mentioned above and squash any others that come up.

  43. sipa commented at 4:22 pm on September 15, 2013: member
    Ok, great! I understand finding indirect dependencies is hard, and the code certainly already has a ton of them, so anything is an improvement. I’ll review it some more, if you’re willing to address the comments.
  44. brandondahler commented at 4:30 pm on September 15, 2013: contributor
    Without a doubt, ideally there are no indirect dependencies anywhere, but that would take a lot of knowledge about all files dependency fulfillment and usage.
  45. sipa commented at 4:32 pm on September 15, 2013: member
    @brandondahler Sure, no need to fix everything. But I’ll help avoiding introducing more of them.
  46. brandondahler commented at 3:22 am on September 16, 2013: contributor

    I am going to need some help fixing the build error the pull tester is encountering. It looks like the tester is trying to build without setting HAVE_CONFIG_H.

    On Sep 15, 2013, at 9:51 PM, BitcoinPullTester notifications@github.com wrote:

    Automatic sanity-testing: FAILED BUILD/TEST, see http://jenkins.bluematt.me/pull-tester/10a08c93b5c7bc3dfb141da377a604a59599913c for binaries and test log.

    This could happen for one of several reasons:

    1. It chanages paths in makefile.linux-mingw or otherwise changes build scripts in a way that made them incompatible with the automated testing scripts (please tweak those patches in qa/pull-tester)
    2. It adds/modifies tests which test network rules (thanks for doing that), which conflicts with a patch applied at test time
    3. It does not build on either Linux i386 or Win32 (via MinGW cross compile)
    4. The test suite fails on either Linux i386 or Win32
    5. The block test-cases failed (lookup the first bNN identifier which failed in https://github.com/TheBlueMatt/test-scripts/blob/master/FullBlockTestGenerator.java)

    If you believe this to be in error, please ping BlueMatt on freenode or TheBlueMatt here.

    This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.

    — Reply to this email directly or view it on GitHub.

  47. brandondahler commented at 5:31 am on November 4, 2013: contributor
    Rebased to current master and squashed all commits to single one.
  48. laanwj commented at 9:13 am on November 8, 2013: member

    If we intend to merge this, I think we should merge it as soon as possible. Keeping a patch this size up to date must be frustrating.

    After squashing this you seem to have introduced some merge commits into the pull request, can you make it one commit again? (easiest way to get rid of merges is to merge the branch using git merge --squash)

  49. in src/rpcwallet.cpp: in d00b76320e outdated
    1276@@ -1268,7 +1277,7 @@ Value keypoolrefill(const Array& params, bool fHelp)
    1277             "Fills the keypool."
    1278             + HelpRequiringPassphrase());
    1279 
    1280-    unsigned int kpSize = max(GetArg("-keypool", 100), 0LL);
    1281+    unsigned int kpSize = max(GetArg("-keypool", 100), (int64_t) 0);
    


    laanwj commented at 4:25 pm on November 8, 2013:
    Why change 0LL to (uint64_t)0?

    brandondahler commented at 0:10 am on November 9, 2013:

    (0LL) is equivalent to ((long long) 0), which is not necessarily equivalent to ((uint64_t) 0).

    For instance, uint64_t is actually defined by “typedef long int64_t;” my on x86_64 linux machine. Leaving it as 0LL would cause it to emit a warning about implicit conversion from long long to uint64_t [long].


    laanwj commented at 5:04 am on November 9, 2013:
    Oh, right, agreed, I was just curious. It’s fine in this case, though I don’t think the (cast) notation without LL will work for specifying constants for numbers that don’t fit in 32 bits on 32 bit architectures.
  50. in src/qt/transactiondesc.cpp: in d00b76320e outdated
    192-                    int64 nValue = nCredit - nChange;
    193-                    strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, -nValue) + "<br>";
    194-                    strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(unit, nValue) + "<br>";
    195+                    int64_t nChange = wtx.GetChange();
    196+                    int64_t nValue = nCredit - nChange;
    197+                    strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -nValue) + "<br>";
    


    laanwj commented at 4:29 pm on November 8, 2013:
    Please keep using unit here instead of hardcoding BitcoinUnits::BTC. I suppose this is an accidental reversion.
  51. in src/net.cpp: in d00b76320e outdated
    42 
    43 // Dump addresses to peers.dat every 15 minutes (900s)
    44 #define DUMP_ADDRESSES_INTERVAL 900
    45-#if !defined(HAVE_MSG_NOSIGNAL)
    46+
    47+#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL)
    


    laanwj commented at 4:36 pm on November 8, 2013:
    This added check is not needed IMO. Any specific reason to add it? If HAVE_MSG_NOSIGNAL is set, MSG_NOSIGNAL must not be defined, if HAVE_MSG_NOSIGNAL is not set, MSG_NOSIGNAL must not be defined. If the detection went wrong, a warning/error can and should be emitted, so I don’t see why add this extra clause.

    brandondahler commented at 0:22 am on November 9, 2013:

    Was changed to standardize it with the other 2 existing instances:

    util.h:97 netbase.cpp:22

    I would imagine it is to prevent redefinition warnings/errors due to including util.h’s define (indirectly).


    laanwj commented at 5:04 am on November 9, 2013:
    OK
  52. laanwj commented at 5:30 pm on November 8, 2013: member
    I’ve read through the entire patch and verified code movement and renames. ACK apart from the above minor nits
  53. brandondahler commented at 0:29 am on November 9, 2013: contributor
    Replied to/fixed nits, rebase onto master, squash all but #3211 merge.
  54. in src/rpcdump.cpp: in 429504d3ba outdated
    28+#include "json/json_spirit_value.h"
    29 
    30 using namespace json_spirit;
    31 using namespace std;
    32 
    33+extern CWallet* pwalletMain;
    


    laanwj commented at 5:52 am on November 9, 2013:
    This extern CWallet declaration is now duplicated in various places, why?

    brandondahler commented at 9:51 pm on November 9, 2013:

    I think it was done before init.{h,cpp} existed and it would have required main.h – which would have pulled a large amount of dependencies.

    Good catch, removed them.

  55. in src/rpcrawtransaction.cpp: in 429504d3ba outdated
    23 using namespace std;
    24 using namespace boost;
    25 using namespace boost::assign;
    26 using namespace json_spirit;
    27 
    28+extern CWallet* pwalletMain;
    


    laanwj commented at 5:52 am on November 9, 2013:
    Like here. I understand that you want to avoid header includes, but just copying variable declarations is a kind of cheating :)
  56. laanwj commented at 5:57 am on November 9, 2013: member

    Another nit: the commit messages that we use are of the format (see http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)

    0subject line (~50 chars)
    1(empty line)
    2longer description...
    

    You left out the empty line for commit 0de9da2, which causes git tools to merge your entire message into one line.

  57. brandondahler commented at 9:50 pm on November 9, 2013: contributor
    Rebased, addressed nits.
  58. gavinandresen commented at 11:13 pm on November 9, 2013: contributor

    Has anybody tested if the int64 changes run properly on Windows 32/64 machines ?

    UPDATE: I downloaded the pull-tester-created bitcoind.exe into a Windows XP, 32-bit virtual machine and it seems to be running -testnet just fine.

  59. gavinandresen commented at 1:40 am on November 10, 2013: contributor
    ACK from me.
  60. in src/Makefile.am: in cb4030da11 outdated
    80@@ -81,7 +81,7 @@ CLEANFILES = leveldb/libleveldb.a leveldb/libmemenv.a *.gcda *.gcno
    81 
    82 DISTCLEANFILES = obj/build.h
    83 
    84-EXTRA_DIST = leveldb Makefile.include
    85+EXTRA_DIST = leveldb Makefile.include 
    


    sipa commented at 1:57 am on November 10, 2013:
    Nit: trailing space.
  61. in src/allocators.h: in cb4030da11 outdated
     1@@ -2,17 +2,20 @@
     2 // Copyright (c) 2009-2013 The Bitcoin developers
     3 // Distributed under the MIT/X11 software license, see the accompanying
     4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
     5+
     6 #ifndef BITCOIN_ALLOCATORS_H
     7 #define BITCOIN_ALLOCATORS_H
     8 
     9-#include <string.h>
    10+#include "compat.h"
    


    sipa commented at 1:59 am on November 10, 2013:
    Why does allocators.h need compat.h?

    brandondahler commented at 4:32 am on November 10, 2013:
    I have no clue, fixing.

    brandondahler commented at 6:14 am on November 10, 2013:
    Ended up being needed in util.h instead of allocators.h, specifically for windows.
  62. in src/keystore.h: in cb4030da11 outdated
     9-#include "crypter.h"
    10+#include "key.h"
    11 #include "sync.h"
    12-#include <boost/signals2/signal.hpp>
    13 
    14-class CScript;
    


    sipa commented at 2:04 am on November 10, 2013:
    AFAICS, this forward declaration is still necessary.
  63. in src/limitedmap.h: in cb4030da11 outdated
     5 #ifndef BITCOIN_LIMITEDMAP_H
     6 #define BITCOIN_LIMITEDMAP_H
     7 
     8 #include <assert.h> // TODO: remove
     9 #include <map>
    10-#include <deque>
    


    sipa commented at 2:05 am on November 10, 2013:
    Nice catch!
  64. in src/main.h: in cb4030da11 outdated
    31+#include <string>
    32+#include <utility>
    33+#include <vector>
    34 
    35 class CBlock;
    36+class CBlockHeader;
    


    sipa commented at 2:07 am on November 10, 2013:
    No need to forward declare this; CBlockHeader is defined in core, which is included.
  65. in src/main.h: in cb4030da11 outdated
    39 class CInv;
    40 class CKeyItem;
    41 class CNode;
    42+class CNodeSignals;
    43 class CReserveKey;
    44+class CTransaction;
    


    sipa commented at 2:08 am on November 10, 2013:
    Same here; already defined in core.h.
  66. in src/net.cpp: in cb4030da11 outdated
    14+
    15 #include "addrman.h"
    16+#include "chainparams.h"
    17+#include "core.h"
    18+#include "db.h"
    19+#include "main.h"
    


    sipa commented at 2:11 am on November 10, 2013:
    Net really should not depend on main, it was really hard to break that circular dependency. Is it still lurking somewhere yet?
  67. in src/serialize.h: in cb4030da11 outdated
    164+template<typename Stream> inline void Serialize(Stream& s, unsigned short a,     int, int=0) { WRITEDATA(s, a); }
    165+template<typename Stream> inline void Serialize(Stream& s, signed int a,         int, int=0) { WRITEDATA(s, a); }
    166+template<typename Stream> inline void Serialize(Stream& s, unsigned int a,       int, int=0) { WRITEDATA(s, a); }
    167+template<typename Stream> inline void Serialize(Stream& s, signed long a,        int, int=0) { WRITEDATA(s, a); }
    168+template<typename Stream> inline void Serialize(Stream& s, unsigned long a,      int, int=0) { WRITEDATA(s, a); }
    169+template<typename Stream> inline void Serialize(Stream& s, signed long long a,   int, int=0) { WRITEDATA(s, a); }
    


    sipa commented at 2:22 am on November 10, 2013:
    All these should really only be data types with known constant sizes. I’d prefer having int64_t here for that reason.

    brandondahler commented at 5:33 am on November 10, 2013:
    I tried to do this but it caused build errors due to problems with the template version lower in the file. Would be best to address this in a new issue/pull.

    sipa commented at 9:41 am on November 10, 2013:
    Fair enough. I think that’s a general problem that already exists, anyway.
  68. in src/script.cpp: in cb4030da11 outdated
    10 #include "bignum.h"
    11+#include "core.h"
    12+#include "hash.h"
    13 #include "key.h"
    14+#include "keystore.h"
    15+#include "main.h"
    


    sipa commented at 2:23 am on November 10, 2013:
    Why does script need to depend on main?
  69. brandondahler commented at 5:32 am on November 10, 2013: contributor
    Address @sipa comments. I think most of the main.h problems were caused by rebasing/merging so many times.
  70. in src/main.cpp: in 625188f2ea outdated
    15@@ -17,6 +16,15 @@
    16 #include "txdb.h"
    17 #include "txmempool.h"
    18 #include "ui_interface.h"
    19+#include "util.h"
    20+#include "wallet.h"
    


    sipa commented at 9:30 am on November 10, 2013:
    Since #3115, this shouldn’t be needed anymore.

    sipa commented at 10:10 am on November 10, 2013:
    Oh, this is my fault: it was supposed to remove setpwalletRegistered and its critical section, but apparently didn’t. In any case, they’re obsolete now, and that can remove the dependency on CWallet.
  71. in src/main.h: in 625188f2ea outdated
    30+#include <stdint.h>
    31+#include <string>
    32+#include <utility>
    33+#include <vector>
    34 
    35 class CBlock;
    


    sipa commented at 9:31 am on November 10, 2013:
    Also defined in core.h.
  72. in src/main.h: in 625188f2ea outdated
    35 class CBlock;
    36 class CBlockIndex;
    37+class CBloomFilter;
    38 class CInv;
    39 class CKeyItem;
    40 class CNode;
    


    sipa commented at 9:31 am on November 10, 2013:
    Defined in net.h.
  73. in src/main.h: in 625188f2ea outdated
    36 class CBlockIndex;
    37+class CBloomFilter;
    38 class CInv;
    39 class CKeyItem;
    40 class CNode;
    41+class CNodeSignals;
    


    sipa commented at 9:32 am on November 10, 2013:
    Also defined in net.h.
  74. in src/main.h: in 625188f2ea outdated
    37+class CBloomFilter;
    38 class CInv;
    39 class CKeyItem;
    40 class CNode;
    41+class CNodeSignals;
    42 class CReserveKey;
    


    sipa commented at 9:33 am on November 10, 2013:
    Not needed.
  75. in src/main.h: in 625188f2ea outdated
    38 class CInv;
    39 class CKeyItem;
    40 class CNode;
    41+class CNodeSignals;
    42 class CReserveKey;
    43 class CWallet;
    


    sipa commented at 9:33 am on November 10, 2013:
    Not needed since #3115.
  76. in src/main.h: in 625188f2ea outdated
    34 
    35 class CBlock;
    36 class CBlockIndex;
    37+class CBloomFilter;
    38 class CInv;
    39 class CKeyItem;
    


    sipa commented at 9:33 am on November 10, 2013:
    Not needed, I think.
  77. sipa commented at 9:48 am on November 10, 2013: member
    ACK, apart from my nits above.
  78. sipa referenced this in commit b643ce4191 on Nov 10, 2013
  79. sipa commented at 11:22 am on November 10, 2013: member
    Some suggested changes, which seem to work: sipa/bitcoin@0762f57854af54d08c969c029f629c9741e79e64
  80. Cleanup code using forward declarations.
    Use misc methods of avoiding unnecesary header includes.
    Replace int typedefs with int##_t from stdint.h.
    Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h.
    Normalize QT_VERSION ifs where possible.
    Resolve some indirect dependencies as direct ones.
    Remove extern declarations from .cpp files.
    51ed9ec971
  81. brandondahler commented at 3:38 pm on November 10, 2013: contributor
    Merged sipa/bitcoin@header-cleanup (sipa/bitcoin@0762f57)
  82. BitcoinPullTester commented at 3:53 pm on November 10, 2013: none
    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/51ed9ec971614aebdbfbd9527aba365dd0afd437 for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.
  83. sipa commented at 6:19 pm on November 10, 2013: member
    ACK. Thanks a lot for the effort of writing this, and maintaining it.
  84. sipa referenced this in commit f76c122e2e on Nov 10, 2013
  85. sipa merged this on Nov 10, 2013
  86. sipa closed this on Nov 10, 2013

  87. brandondahler deleted the branch on Nov 11, 2013
  88. Bushstar referenced this in commit 6350adf1b9 on Apr 5, 2019
  89. DrahtBot 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-07-06 01:12 UTC

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