-
Notifications
You must be signed in to change notification settings - Fork 36.2k
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
rpc: replace wallet raw pointers with references (#18592 rebased) #21331
Conversation
(edited title) |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 199c81f
I think this would be much easier to review if it was split into two commits:
- Remove all the
CWallet* const pwallet = wallet.get()
lines and rename wallet to pwallet. - Change the function signatures to take references instead of pointers.
src/wallet/rpcdump.cpp
Outdated
@@ -1768,20 +1758,20 @@ RPCHelpMan listdescriptors() | |||
}, | |||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue | |||
{ | |||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | |||
if (!wallet) return NullUniValue; | |||
std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our style is no longer to use pthing
as the name for pointer variables, but I guess you did this to be consistent with the other functions in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea it's done to keep the diff to a minimum, otherwise we'd also have to rename all the pwallet usage in each function.
Super Strong Concept ACK for safety reasons: pre-conditions should be stated explicitly and be enforced at compile-time where possible. Thanks for tackling these! I stumbled upon a similar case in the networking code the other day. More generally it seems like there are a few functions in our case base where we take More specifically … void f_1(T& t) { t.foo(); } … is preferable over … void f_2(T* t) { t->foo(); } Live demo: $ cat nullptr-deref.cpp
#include <iostream>
struct T {
void foo() { std::cout << this << "->foo()\n"; }
};
void f_1(T& t) { t.foo(); }
void f_2(T* t) { t->foo(); }
int main(void)
{
T t;
f_1(t);
f_2(&t);
// f_1(nullptr); // compile time error: no known conversion from nullptr_t to T&
f_2(nullptr);
}
$ clang++ -o nullptr-deref nullptr-deref.cpp && ./nullptr-deref
0x7fff9e191234->foo()
0x7fff9e191234->foo()
0->foo()
$ g++ -o nullptr-deref nullptr-deref.cpp && ./nullptr-deref
0x7fff9e191234->foo()
0x7fff9e191234->foo()
0->foo()
$ clang++ -fsanitize=undefined -o nullptr-deref nullptr-deref.cpp && ./nullptr-deref
0x7fff9e191234->foo()
0x7fff9e191234->foo()
nullptr-deref.cpp:9:21: runtime error: member call on null pointer of type 'T'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior nullptr-deref.cpp:9:21 in
nullptr-deref.cpp:4:10: runtime error: member call on null pointer of type 'T *'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior nullptr-deref.cpp:4:10 in
0->foo() Note how |
Co-authored-by: MarcoFalke <falke.marco@gmail.com> Co-authored-by: João Barbosa <joao.paulo.barbosa@gmail.com>
…ters Co-authored-by: MarcoFalke <falke.marco@gmail.com> Co-authored-by: João Barbosa <joao.paulo.barbosa@gmail.com>
This is now split into two commits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 7c90c67. Changes easy to review with --word-diff-regex=. -U0
ACK 7c90c67 🐧 Show signature and timestampSignature:
Timestamp of file with hash |
This is a rebased #18592.