-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Change the return type of mulDiv to std::optional #4243
Conversation
I had to use |
Nice, thanks @chennakeshava1998 , but I don't think it is necessary to leave the old code commented out. |
@greg7mdp Sorry my bad. I forgot to remove it. Completed now 👍 |
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.
Almost there!
Done :) Do I need to clean up the commits? (I can do a force push with a single commit) |
Nice! Looks very clean now.
Yes, I think it would be better. Make sure to run the unittests again with the latest version, if you haven't already. |
3c3c6df
to
ed9f30a
Compare
I have executed the unit tests, I didn't observe any failures. 👍 |
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.
Looks great!
I approved the PR, but I don't have write access to the repo, so it doesn't count. |
Okat, thanks for helping me out greg! |
@ckeshava could you merge |
Hello @intelliot , I do not have C++ toolchain required to install the dependencies and unit-test this change. Can I do this after 2-3 weeks? |
No hurry - thanks! |
@ckeshava Could you rebase this against the current develop? I tried to do so and got multiple merge conflicts. And I don't want to try to guess the correct conflict resolutions. I need it rebased because we've recently moved to conan for a build tool, and your PR won't build with Conan without a rebase. |
@HowardHinnant Will do 👍 |
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.
Needs a rebase to develop (has merge conflicts).
@HowardHinnant I have merged the latest develop into this feature branch. |
you can download the clang-format patch from https://github.com/XRPLF/rippled/actions/runs/4759912341?pr=4243 (under Artifacts) and apply it with |
thanks a lot elliot, I was searching for exactly that :)) |
Hello, |
I have requested changes to the git merge which place these commits at the top. |
I'll work on your suggestions, sorry I forgot about it. |
Hello @HowardHinnant , Is there a better alternative than force-pushing the changes? After rebasing, the remote and local branches were so different that I couldn't think of a better alternative. |
I think force pushing is the only option here. Thanks for this work. It is on my to-do list to review. |
@@ -2056,7 +2056,7 @@ NetworkOPsImp::pubServer() | |||
f.em->openLedgerFeeLevel, | |||
f.loadBaseServer, | |||
f.em->referenceFeeLevel) | |||
.second); |
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.
Are cases like this guaranteed to have a value? Is that why the old code didn't check for success? If so, then I think the new code should just use operator*
.
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.
Cases like this are not guaranteed to have a value. When the old behavior overflowed, it passed back an overflow flag and the value ripple::muldiv_max
. The client level code (in this example) didn't check the overflow flag and just took the value. In this rewrite, the client code is forced to be explicit that it is using ripple::muldiv_max
on overflow.
In any case the behavior is unchanged.
CI caught a format issue. Instructions on how to fix it are in the job log. |
okay, I've fixed that. let me know if I need to squash or clean-up the commit log |
It will be squashed when it is merged. Now that there are at least two approvals and all checks pass, you can add the "Passed" label if you think this PR is ready to merge. |
Okay, done. thanks |
Suggested commit message:
|
- Previously, mulDiv had `std::pair<bool, uint64_t>` as the output type. - This is an error-prone interface as it is easy to ignore when overflow occurs. - Using a return type of `std::optional` should decrease the likelihood of ignoring overflow. - It also allows for the use of optional::value_or() as a way to explicitly recover from overflow. - Include limits.h header file preprocessing directive in order to satisfy gcc's numeric_limits incomplete_type requirement. Fix XRPLF#3495 --------- Co-authored-by: John Freeman <[email protected]>
For future reference: there is no need to force push. Instead, just confirm (or write a comment with) the desired commit message. A new commit message is set when the PR is Also, for future PRs, please sign your commits. |
okay, I'll keep that in mind 👍 |
Following up on an old question: @HowardHinnant @ckeshava please never force-push in a PR. If you end up in a situation where you don't want to bother resolving conflicts, and you just want to keep your changes, then use this:
This creates a merge commit with two parents, but just takes your changes wherever there is a conflict. You should not rebase either. That is what creates the conditions (lost history) that encourages force-push. |
Okay, thanks for the tip, I'll keep it in mind. |
- Previously, mulDiv had `std::pair<bool, uint64_t>` as the output type. - This is an error-prone interface as it is easy to ignore when overflow occurs. - Using a return type of `std::optional` should decrease the likelihood of ignoring overflow. - It also allows for the use of optional::value_or() as a way to explicitly recover from overflow. - Include limits.h header file preprocessing directive in order to satisfy gcc's numeric_limits incomplete_type requirement. Fix XRPLF#3495 --------- Co-authored-by: John Freeman <[email protected]>
- Previously, mulDiv had `std::pair<bool, uint64_t>` as the output type. - This is an error-prone interface as it is easy to ignore when overflow occurs. - Using a return type of `std::optional` should decrease the likelihood of ignoring overflow. - It also allows for the use of optional::value_or() as a way to explicitly recover from overflow. - Include limits.h header file preprocessing directive in order to satisfy gcc's numeric_limits incomplete_type requirement. Fix XRPLF#3495 --------- Co-authored-by: John Freeman <[email protected]>
- Previously, mulDiv had `std::pair<bool, uint64_t>` as the output type. - This is an error-prone interface as it is easy to ignore when overflow occurs. - Using a return type of `std::optional` should decrease the likelihood of ignoring overflow. - It also allows for the use of optional::value_or() as a way to explicitly recover from overflow. - Include limits.h header file preprocessing directive in order to satisfy gcc's numeric_limits incomplete_type requirement. Fix XRPLF#3495 --------- Co-authored-by: John Freeman <[email protected]>
std::pair<bool, uint64_t>
as the output type.