- Notifications
You must be signed in to change notification settings - Fork13.3k
new w/ OOM now aborts by defaults, or throw an exception#7536
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
new bynew (std::nothrow), removearduino_newnew bynew (std::nothrow), removearduino_newnew bynew (std::nothrow), removearduino_newTD-er commentedAug 30, 2020
Can we also have a build option to deliberately keep the old situation? |
d-a-v commentedAug 30, 2020
|
devyte commentedAug 30, 2020
@TD-er the whole point of this PR is to clean up the current situation and better conform to the C++ language standard. That means removing the legacy behavior. |
TD-er commentedAug 30, 2020
I have not tried it yet. I will try to see if it compiles using the current core code and will start making a macro for it. |
TD-er commentedAug 30, 2020
OK, next time I should try it first before panic. |
earlephilhower left a comment
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 very nice! Smart move to overload the new(std::nothrow&) operator, I was wondering how you'd fix things.
devyte commentedAug 31, 2020
Thanks for this, finally this is cleaned up! |
| if (ctx) | ||
| delete ctx; | ||
| if (sha256) | ||
| delete sha256; |
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.
isif (...) redundant here? afaik, delete will be no-op with nullptr
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.
We don't know which one is nullptr
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.
meaning, we can delete both. one nullptr, another created (or both nullptr)
i.e.https://godbolt.org/z/63PKa3
Uh oh!
There was an error while loading.Please reload this page.
Changes:
newbehavior, c++operator newis supposed tonever returnnullptrarduino_newhas exactly the same behavior asnew (std::nothrow), removing the first.newwhich are checking the returned value are now callingnew (std::nothrow)instead(the others will abort on oom, then reboot)
mallocis untouched: it returnsnullptron oom likenew (std::nothrow)