refactor: Add missing includes in pubkey.cpp/pubkey.h #21745

pull whb07 wants to merge 1 commits into bitcoin:master from whb07:refactor_imports_pubkey changing 2 files +8 −1
  1. whb07 commented at 7:35 PM on April 21, 2021: contributor

    Problem:

    Many symbols in the files were undefined and causing issues when I was working on building independent sections of the codebase. The hidden imports from the "secp256k1" library was a particular pain point.

    The other standard and missing includes are following best practices and will help with refactoring, build process and others.

    Changes:

    Clean up and declared imports/include for pubkey.cpp and pubkey.h

  2. whb07 commented at 8:59 PM on April 21, 2021: contributor

    Would like feedback on the comments next to the imports.

    sometimes they can be helpful, but assuming one imports multiple things I’m not sure what styling to take or just omit.

  3. in src/pubkey.h:16 in 55e02fd3b8 outdated
      17 | +#include <uint256.h>    // for u256
      18 |  
      19 | -#include <stdexcept>
      20 | -#include <vector>
      21 | +#include <cstring>      // for memcmp, memcpy, size_t
      22 | +#include <vector>       // for vector
    


    fanquake commented at 6:23 AM on April 22, 2021:

    Would like feedback on the comments next to the imports.

    That is not something we want to do. What is the value-add of putting // for vector next to #include <vector>? In the other cases, these comments would be fairly unmaintainable, frequently become out of date (if not managed in some automated way), would pollute diffs etc.


    whb07 commented at 2:04 PM on April 22, 2021:

    I agree. Changes have been implemented by removing comments from includes.

  4. jnewbery commented at 1:48 PM on April 22, 2021: member

    I'd much rather we went the other way and removed all of the // for comments from include lines, for the reasons of maintainability explained here: #21745 (review).

  5. whb07 commented at 2:06 PM on April 22, 2021: contributor

    I'd much rather we went the other way and removed all of the // for comments from include lines, for the reasons of maintainability explained here: #21745 (comment).

    Agreed all around then. I've updated the code and removed the "for" comments next to include. Better to include those comments in the PR itself.

    Should be good to go now.

  6. in src/pubkey.cpp:18 in 050727e903 outdated
      13 | +#include <span.h>
      14 | +#include <uint256.h>
      15 | +
      16 | +#include <algorithm>
      17 | +
      18 | +#include <assert.h>
    


    jnewbery commented at 2:37 PM on April 22, 2021:
    #include <cassert>
    #include <algorithm>
    

    (group all standard library imports together and prefer the c++ versions of the c headers).


    whb07 commented at 2:46 PM on April 22, 2021:

    Done. Yep that was a question I was slightly mulling over. I'll take a look and see if i see the styling docs (if any).

  7. jnewbery commented at 2:37 PM on April 22, 2021: member

    Looks better. All commits can be squashed.

  8. cleaned up and added missing "include" statements for pubkey.cpp and pubkey.h
    removed comments next to include statements.
    
    removed comments in include statements.
    
    changed assert.h to cassert based on pr comments
    71c824ed6c
  9. whb07 force-pushed on Apr 22, 2021
  10. whb07 commented at 3:04 PM on April 22, 2021: contributor

    Looks better. All commits can be squashed.

    Commits got squashed. let me know if you need anything else

  11. jnewbery commented at 5:06 PM on April 22, 2021: member

    utACK 71c824ed6c

    Change looks good. Did you use a tool to find the missing includes?

  12. whb07 commented at 5:19 PM on April 22, 2021: contributor

    Change looks good. Did you use a tool to find the missing includes?

    I am working on currently writing up a CMake build for the repo and did run into several issues especially with the secp256k1 libraries due to some different includes within that lib/module.

    I generally just crank up all the warnings and flags for the compilers I use and other static analyzers, which also bring in "include what you use" tool.

  13. MarcoFalke added the label Refactoring on Apr 22, 2021
  14. laanwj renamed this:
    includes refactor pubkey.cpp/pubkey.h
    Add missing includes in pubkey.cpp/pubkey.h
    on May 10, 2021
  15. laanwj renamed this:
    Add missing includes in pubkey.cpp/pubkey.h
    refactor: Add missing includes in pubkey.cpp/pubkey.h
    on May 10, 2021
  16. laanwj commented at 12:30 PM on May 10, 2021: member

    Code review ACK 71c824ed6cf70b39ca09e8b3962f452f69523af0 Checked that nothing outrageous was added, I did not verify that all the added includes are necessary individually.

  17. laanwj merged this on May 10, 2021
  18. laanwj closed this on May 10, 2021

  19. sidhujag referenced this in commit b16a789079 on May 10, 2021
  20. gwillen referenced this in commit 16944dd222 on Jun 1, 2022
  21. DrahtBot locked this on Aug 18, 2022

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: 2026-04-22 06:14 UTC

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