make all catch() arguments const #5438

pull Diapolo wants to merge 1 commits into bitcoin:master from Diapolo:const_exception changing 24 files +78 −82
  1. Diapolo commented at 12:32 PM on December 7, 2014: none
  2. laanwj commented at 8:11 AM on December 8, 2014: member

    I'm fine with doing this. But then let's apply const to all exception catches, not just std::exception.

  3. laanwj added the label Improvement on Dec 8, 2014
  4. Diapolo commented at 8:17 AM on December 8, 2014: none

    Have you got the ability to script such a change and add a commit that extends this pull? I would dig through our files and replace by hand ;).

  5. laanwj commented at 9:08 AM on December 8, 2014: member

    I'd say

    cd src
    git grep catch
    

    But this doesn't require scripting. Just search all .cpp and .h files for 'catch', then exclude imported source like leveldb and jsonspirit.

  6. Diapolo commented at 11:34 AM on December 9, 2014: none

    @laanwj Can you recheck, I tried to catch all ;).

  7. Diapolo renamed this:
    make all std::exception uses in catch() const
    make all catch() arguments const
    on Dec 9, 2014
  8. in src/qt/intro.cpp:None in ba3a20a70e outdated
     179 | @@ -180,7 +180,7 @@ void Intro::pickDataDirectory()
     180 |              try {
     181 |                  TryCreateDirectory(GUIUtil::qstringToBoostPath(dataDir));
     182 |                  break;
     183 | -            } catch(fs::filesystem_error &e) {
     184 | +            } catch (fs::filesystem_error&) {
    


    laanwj commented at 12:07 PM on December 9, 2014:

    No const?


    Diapolo commented at 12:34 PM on December 9, 2014:

    Just missed that... will fix.

  9. laanwj commented at 12:11 PM on December 9, 2014: member

    Still a few left:

    src/bitcoin-cli.cpp:    catch (boost::thread_interrupted) {
    src/bitcoin-tx.cpp:    catch (boost::thread_interrupted) {
    src/init.cpp:            } catch (filesystem::filesystem_error& e) {
    src/main.cpp:        catch (boost::thread_interrupted) {
    src/miner.cpp:    catch (boost::thread_interrupted)
    src/net.cpp:        catch (boost::thread_interrupted)
    src/qt/intro.cpp:            } catch (fs::filesystem_error&) {
    src/rpcprotocol.h:        } catch (boost::system::system_error&) {
    src/util.h:    catch (boost::thread_interrupted)
    src/util.h:    catch (boost::thread_interrupted)
    src/walletdb.cpp:    catch (boost::thread_interrupted) {
    src/walletdb.cpp:    catch (boost::thread_interrupted) {
    
  10. Diapolo commented at 12:37 PM on December 9, 2014: none

    I wasn't sure about the boost::thread_interrupted, can this become const boost::thread_interrupted&?

    Edit: Hopefully I got them all now :)!?

  11. laanwj commented at 1:24 PM on December 9, 2014: member

    Yes it should be, thread_interrupted is an exception like any other.

  12. Diapolo commented at 7:11 AM on December 12, 2014: none

    @laanwj Should be fiine now.

  13. laanwj commented at 10:04 AM on December 12, 2014: member

    OK, now waiting for other ACKs

  14. sipa commented at 12:10 PM on December 12, 2014: member

    untested ACK

  15. laanwj commented at 2:05 PM on December 12, 2014: member

    Just for kicks I compared the -O2 assembly output

    --- /tmp/09ac7f9_a  2014-12-12 14:57:59.410014565 +0100
    +++ /tmp/f1fed36_a  2014-12-12 14:58:01.494014596 +0100
    @@ -1365,11 +1365,6 @@
        pushq  $
        jmpq   <_init+>
    
    -<__cxa_get_exception_ptr@plt>:
    -   jmpq   *(%rip)        # <_GLOBAL_OFFSET_TABLE_+>
    -   pushq  $
    -   jmpq   <_init+>
    -
     <sigemptyset@plt>:
        jmpq   *(%rip)        # <_GLOBAL_OFFSET_TABLE_+>
        pushq  $
    @@ -7802,7 +7797,7 @@
        callq  <__cxa_begin_catch@plt>
        mov    $,%esi
        mov    %rax,%rdi
    -   callq  <PrintExceptionContinue(st:exception*, char const*)>
    +   callq  <PrintExceptionContinue(st:exception const*, char const*)>
        callq  <__cxa_end_catch@plt>
        test   %rbx,%rbx
        je     <AppInit(int, char**)+>
    @@ -7864,7 +7859,7 @@
        callq  <__cxa_begin_catch@plt>
        mov    $,%esi
        xor    %edi,%edi
    -   callq  <PrintExceptionContinue(st:exception*, char const*)>
    +   callq  <PrintExceptionContinue(st:exception const*, char const*)>
        callq  <__cxa_end_catch@plt>
        jmpq   <AppInit(int, char**)+>
        nopw   (%rax,%rax,1)
    @@ -81665,7 +81660,7 @@
        callq  <__cxa_begin_catch@plt>
        mov    $,%esi
        xor    %edi,%edi
    -   callq  <PrintExceptionContinue(st:exception*, char const*)>
    +   callq  <PrintExceptionContinue(st:exception const*, char const*)>
        callq  <__cxa_end_catch@plt>
        jmpq   <ProcessMessages(CNode*)+>
        mov    %rax,%rbx
    @@ -81738,7 +81733,7 @@
        callq  <__cxa_begin_catch@plt>
        mov    $,%esi
        mov    %rax,%rdi
    -   callq  <PrintExceptionContinue(st:exception*, char const*)>
    +   callq  <PrintExceptionContinue(st:exception const*, char const*)>
        jmp    <ProcessMessages(CNode*)+>
        callq  <__cxa_begin_catch@plt>
        nopl   (%rax)
    @@ -81771,7 +81766,7 @@
        jmp    <ProcessMessages(CNode*)+>
        mov    $,%esi
        mov    %rbx,%rdi
    -   callq  <PrintExceptionContinue(st:exception*, char const*)>
    +   callq  <PrintExceptionContinue(st:exception const*, char const*)>
        jmpq   <ProcessMessages(CNode*)+>
        jmp    <ProcessMessages(CNode*)+>
        nopl   (%rax,%rax,1)
    @@ -153741,7 +153736,7 @@
        callq  <__cxa_begin_catch@plt>
        mov    (%rsp),%rsi
        mov    %rax,%rdi
    -   callq  <PrintExceptionContinue(st:exception*, char const*)>
    +   callq  <PrintExceptionContinue(st:exception const*, char const*)>
        callq  <__cxa_rethrow@plt>
        callq  <__cxa_begin_catch@plt>
        lea    (%rsp),%rdx
    @@ -153755,7 +153750,7 @@
        callq  <__cxa_begin_catch@plt>
        mov    (%rsp),%rsi
        xor    %edi,%edi
    -   callq  <PrintExceptionContinue(st:exception*, char const*)>
    +   callq  <PrintExceptionContinue(st:exception const*, char const*)>
        callq  <__cxa_rethrow@plt>
        jmp    <void LoopForever<void (*)()>(char const*, void (*)(), long)+>
        mov    %rax,%rbx
    @@ -153834,7 +153829,7 @@
        callq  <__cxa_begin_catch@plt>
        mov    (%rsp),%rsi
        mov    %rax,%rdi
    -   callq  <PrintExceptionContinue(st:exception*, char const*)>
    +   callq  <PrintExceptionContinue(st:exception const*, char const*)>
        callq  <__cxa_rethrow@plt>
        mov    %rax,%rbp
        mov    (%rsp),%rax
    @@ -153856,7 +153851,7 @@
        callq  <__cxa_begin_catch@plt>
        mov    (%rsp),%rsi
        xor    %edi,%edi
    -   callq  <PrintExceptionContinue(st:exception*, char const*)>
    +   callq  <PrintExceptionContinue(st:exception const*, char const*)>
        callq  <__cxa_rethrow@plt>
        callq  <__cxa_begin_catch@plt>
        lea    (%rsp),%rdx
    @@ -357103,26 +357098,16 @@
        nopl   (%rax)
    
     <TryCreateDirectory(boost::filesystem::path const&)>:
    -   push   %rbp
    -   xor    %esi,%esi
        push   %rbx
    +   xor    %esi,%esi
        mov    %rdi,%rbx
    -   sub    $,%rsp
        callq  <boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::system::error_code*)@plt>
    -   add    $,%rsp
        pop    %rbx
    -   pop    %rbp
        retq   
        sub    $,%rdx
    -   mov    %rax,%rbp
        mov    %rax,%rdi
        je     <TryCreateDirectory(boost::filesystem::path const&)+>
        callq  <_Unwind_Resume@plt>
    -   callq  <__cxa_get_exception_ptr@plt>
    -   mov    %rsp,%rdi
    -   mov    %rax,%rsi
    -   callq  <boost::filesystem::filesystem_error::filesystem_error(boost::filesystem::filesystem_error const&)>
    -   mov    %rbp,%rdi
        callq  <__cxa_begin_catch@plt>
        xor    %esi,%esi
        mov    %rbx,%rdi
    @@ -357136,16 +357121,13 @@
        je     <TryCreateDirectory(boost::filesystem::path const&)+>
        callq  <__cxa_rethrow@plt>
        mov    %rax,%rbx
    -   mov    %rsp,%rdi
    -   callq  <boost::filesystem::filesystem_error::~filesystem_error()>
        callq  <__cxa_end_catch@plt>
        mov    %rbx,%rdi
        callq  <_Unwind_Resume@plt>
    -   mov    %rsp,%rdi
    -   callq  <boost::filesystem::filesystem_error::~filesystem_error()>
        callq  <__cxa_end_catch@plt>
        xor    %eax,%eax
    -   jmp    <TryCreateDirectory(boost::filesystem::path const&)+>
    +   pop    %rbx
    +   retq   
        nopl   (%rax)
    
     <FileCommit(_IO_FILE*)>:
    @@ -358527,7 +358509,7 @@
        callq  <_Unwind_Resume@plt>
        data32 data32 data32 nopw %cs:(%rax,%rax,1)
    
    -<PrintExceptionContinue(st:exception*, char const*)>:
    +<PrintExceptionContinue(st:exception const*, char const*)>:
        push   %r12
        push   %rbp
        push   %rbx
    @@ -358536,7 +358518,7 @@
        test   %rdi,%rdi
        mov    %rsi,(%rsp)
        movq   $,(%rsp)
    -   je     <PrintExceptionContinue(st:exception*, char const*)+>
    +   je     <PrintExceptionContinue(st:exception const*, char const*)+>
        mov    (%rdi),%rax
        lea    (%rsp),%r12
        mov    %rsp,%rbp
    @@ -358595,7 +358577,7 @@
        lea    (%rsp),%rbx
        mov    %r12,%rdx
        callq  <st:string tinyformat::format<char const*, char const*>(char const*, char const* const&, char const* const&)>
    -   jmpq   <PrintExceptionContinue(st:exception*, char const*)+>
    +   jmpq   <PrintExceptionContinue(st:exception const*, char const*)+>
        mov    %rax,%rbx
        mov    (%rsp),%rax
        mov    %r12,%rsi
    @@ -358608,7 +358590,7 @@
        lea    (%rsp),%rsi
        lea    -(%rax),%rdi
        callq  <st:string::_Rep::_M_dispose(st:allocator<char> const&)@plt>
    -   jmp    <PrintExceptionContinue(st:exception*, char const*)+>
    +   jmp    <PrintExceptionContinue(st:exception const*, char const*)+>
        nopw   (%rax,%rax,1)
    
     <ParseParameters(int, char const* const*)>:
    @@ -359400,92 +359382,6 @@
        jmpq   <boost::filesystem::basic_ifstream<char, st:char_traits<char> >::~basic_ifstream()>
        nopl   (%rax)
    
    -<boost::filesystem::filesystem_error::what() const>:
    -   push   %rbp
    -   push   %rbx
    -   mov    %rdi,%rbx
    -   sub    $,%rsp
    -   mov    (%rdi),%rax
    -   test   %rax,%rax
    -   je     <boost::filesystem::filesystem_error::what() const+>
    -   mov    (%rax),%rax
    -   cmpq   $,-(%rax)
    -   je     <boost::filesystem::filesystem_error::what() const+>
    -   mov    %rax,%rbx
    -   add    $,%rsp
    -   mov    %rbx,%rax
    -   pop    %rbx
    -   pop    %rbp
    -   retq   
    -   xchg   %ax,%ax
    -   callq  <boost::system::system_error::what() const>
    -   mov    %rax,%rdi
    -   mov    %rax,%rbp
    -   callq  <strlen@plt>
    -   mov    (%rbx),%rcx
    -   mov    %rax,%rdx
    -   mov    %rbp,%rsi
    -   lea    (%rcx),%rdi
    -   callq  <st:string::assign(char const*, unsigned long)@plt>
    -   mov    (%rbx),%rax
    -   mov    (%rax),%rdx
    -   mov    %rax,%rdi
    -   cmpq   $,-(%rdx)
    -   jne    <boost::filesystem::filesystem_error::what() const+>
    -   mov    (%rdi),%rax
    -   cmpq   $,-(%rax)
    -   jne    <boost::filesystem::filesystem_error::what() const+>
    -   mov    (%rdi),%rax
    -   jmp    <boost::filesystem::filesystem_error::what() const+>
    -   nopl   (%rax)
    -   add    $,%rdi
    -   mov    $,%edx
    -   mov    $,%esi
    -   callq  <st:string::append(char const*, unsigned long)@plt>
    -   mov    (%rbx),%rdi
    -   lea    (%rdi),%rsi
    -   add    $,%rdi
    -   callq  <st:string::append(st:string const&)@plt>
    -   mov    (%rbx),%rax
    -   mov    $,%edx
    -   mov    $,%esi
    -   lea    (%rax),%rdi
    -   callq  <st:string::append(char const*, unsigned long)@plt>
    -   mov    (%rbx),%rax
    -   mov    (%rax),%rax
    -   jmpq   <boost::filesystem::filesystem_error::what() const+>
    -   lea    (%rax),%rdi
    -   mov    $,%edx
    -   mov    $,%esi
    -   callq  <st:string::append(char const*, unsigned long)@plt>
    -   mov    (%rbx),%rsi
    -   lea    (%rsi),%rdi
    -   callq  <st:string::append(st:string const&)@plt>
    -   mov    (%rbx),%rax
    -   mov    $,%edx
    -   mov    $,%esi
    -   lea    (%rax),%rdi
    -   callq  <st:string::append(char const*, unsigned long)@plt>
    -   mov    (%rbx),%rdi
    -   jmpq   <boost::filesystem::filesystem_error::what() const+>
    -   add    $,%rsp
    -   pop    %rbx
    -   pop    %rbp
    -   jmpq   <boost::system::system_error::what() const>
    -   mov    %rax,%rdi
    -   callq  <__cxa_begin_catch@plt>
    -   mov    %rbx,%rdi
    -   callq  <boost::system::system_error::what() const>
    -   mov    %rax,%rbx
    -   callq  <__cxa_end_catch@plt>
    -   jmpq   <boost::filesystem::filesystem_error::what() const+>
    -   add    $,%rdx
    -   mov    %rax,%rdi
    -   je     <boost::filesystem::filesystem_error::what() const+>
    -   callq  <_Unwind_Resume@plt>
    -   callq  <__cxa_call_unexpected@plt>
    -   nopl   (%rax,%rax,1)
    -
     <boost::filesystem::basic_ifstream<char, st:char_traits<char> >::~basic_ifstream()>:
        push   %rbp
        push   %rbx
    @@ -359598,120 +359494,6 @@
        jmp    <boost::thread_specific_ptr<st:set<st:string, st:less<st:string>, st:allocator<st:string> > >::~thread_specific_ptr()+>
        nopw   (%rax,%rax,1)
    
    -<boost::filesystem::filesystem_error::~filesystem_error()>:
    -   push   %r12
    -   push   %rbp
    -   push   %rbx
    -   mov    %rdi,%rbx
    -   sub    $,%rsp
    -   movq   $,(%rdi)
    -   mov    (%rdi),%rdi
    -   test   %rdi,%rdi
    -   je     <boost::filesystem::filesystem_error::~filesystem_error()+>
    -   callq  <boost::detail::sp_counted_bas:release()>
    -   mov    (%rbx),%rax
    -   lea    (%rsp),%rsi
    -   movq   $,(%rbx)
    -   lea    -(%rax),%rdi
    -   callq  <st:string::_Rep::_M_dispose(st:allocator<char> const&)@plt>
    -   mov    %rbx,%rdi
    -   callq  <st:runtime_error::~runtime_error()@plt>
    -   add    $,%rsp
    -   pop    %rbx
    -   pop    %rbp
    -   pop    %r12
    -   retq   
    -   mov    %rdx,%r12
    -   mov    %rbx,%rdi
    -   mov    %rax,%rbp
    -   callq  <boost::system::system_error::~system_error()>
    -   add    $,%r12
    -   mov    %rbp,%rdi
    -   je     <boost::filesystem::filesystem_error::~filesystem_error()+>
    -   callq  <_Unwind_Resume@plt>
    -   callq  <__cxa_call_unexpected@plt>
    -   nopl   (%rax,%rax,1)
    -
    -<boost::filesystem::filesystem_error::~filesystem_error()>:
    -   push   %r12
    -   push   %rbp
    -   push   %rbx
    -   mov    %rdi,%rbx
    -   sub    $,%rsp
    -   movq   $,(%rdi)
    -   mov    (%rdi),%rdi
    -   test   %rdi,%rdi
    -   je     <boost::filesystem::filesystem_error::~filesystem_error()+>
    -   callq  <boost::detail::sp_counted_bas:release()>
    -   mov    (%rbx),%rax
    -   lea    (%rsp),%rsi
    -   movq   $,(%rbx)
    -   lea    -(%rax),%rdi
    -   callq  <st:string::_Rep::_M_dispose(st:allocator<char> const&)@plt>
    -   mov    %rbx,%rdi
    -   callq  <st:runtime_error::~runtime_error()@plt>
    -   mov    %rbx,%rdi
    -   callq  <operator delete(void*)@plt>
    -   add    $,%rsp
    -   pop    %rbx
    -   pop    %rbp
    -   pop    %r12
    -   retq   
    -   mov    %rdx,%r12
    -   mov    %rbx,%rdi
    -   mov    %rax,%rbp
    -   callq  <boost::system::system_error::~system_error()>
    -   add    $,%r12
    -   mov    %rbp,%rdi
    -   je     <boost::filesystem::filesystem_error::~filesystem_error()+>
    -   callq  <_Unwind_Resume@plt>
    -   callq  <__cxa_call_unexpected@plt>
    -   nopw   %cs:(%rax,%rax,1)
    -   nopl   (%rax)
    -
    -<boost::filesystem::filesystem_error::filesystem_error(boost::filesystem::filesystem_error const&)>:
    -   push   %rbp
    -   mov    %rsi,%rbp
    -   lea    (%rsi),%rsi
    -   push   %rbx
    -   mov    %rdi,%rbx
    -   lea    (%rdi),%rdi
    -   sub    $,%rsp
    -   movq   $,-(%rdi)
    -   callq  <st:basic_string<char, st:char_traits<char>, st:allocator<char> >::basic_string(st:string const&)@plt>
    -   mov    (%rbp),%rax
    -   mov    (%rbp),%rdx
    -   lea    (%rbp),%rsi
    -   lea    (%rbx),%rdi
    -   movq   $,(%rbx)
    -   mov    %rax,(%rbx)
    -   mov    %rdx,(%rbx)
    -   callq  <st:basic_string<char, st:char_traits<char>, st:allocator<char> >::basic_string(st:string const&)@plt>
    -   mov    (%rbp),%rax
    -   movq   $,(%rbx)
    -   mov    %rax,(%rbx)
    -   mov    (%rbp),%rax
    -   test   %rax,%rax
    -   mov    %rax,(%rbx)
    -   je     <boost::filesystem::filesystem_error::filesystem_error(boost::filesystem::filesystem_error const&)+>
    -   lock incl (%rax)
    -   add    $,%rsp
    -   pop    %rbx
    -   pop    %rbp
    -   retq   
    -   mov    %rax,%rbp
    -   mov    %rbx,%rdi
    -   callq  <st:exception::~exception()@plt>
    -   mov    %rbp,%rdi
    -   callq  <_Unwind_Resume@plt>
    -   mov    %rax,%rbp
    -   mov    %rbx,%rdi
    -   callq  <st:runtime_error::~runtime_error()@plt>
    -   mov    %rbp,%rdi
    -   callq  <_Unwind_Resume@plt>
    -   nopw   %cs:(%rax,%rax,1)
    -   nopl   (%rax)
    -
     <boost::thread_specific_ptr<st:set<st:string, st:less<st:string>, st:allocator<st:string> > >::thread_specific_ptr()>:
        push   %rbp
        mov    %rdi,%rbp
    

    Apparently this shaves off a few functions, although the only significant difference appears to be in TryCreateDirectory.

    Edit: still ACK of course

  16. Diapolo commented at 1:09 PM on December 16, 2014: none

    Counting 2 ACKs here, more to come?

  17. make all catch() arguments const
    - I saw this on http://en.cppreference.com/w/cpp/language/try_catch and
      thought it would be a good idea
    - also unify used format to better be able to search for exception
      uses in our codebase
    27df4123c4
  18. laanwj merged this on Dec 17, 2014
  19. laanwj closed this on Dec 17, 2014

  20. laanwj referenced this in commit 89802fe3ee on Dec 17, 2014
  21. Diapolo deleted the branch on Dec 17, 2014
  22. 0xartem referenced this in commit 8a31902d08 on Jun 1, 2018
  23. MarcoFalke locked this on Sep 8, 2021
Contributors

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-21 18:15 UTC

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