-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
new w/ OOM now aborts by defaults, or throw an exception #7536
Conversation
new
by new (std::nothrow)
, remove arduino_new
new
by new (std::nothrow)
, remove arduino_new
new
by new (std::nothrow)
, remove arduino_new
Can we also have a build option to deliberately keep the old situation? |
|
@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. |
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. |
OK, next time I should try it first before panic. |
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.
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.
is if (...)
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
Changes:
new
behavior, c++operator new
is supposed to never returnnullptr
arduino_new
has exactly the same behavior asnew (std::nothrow)
, removing the first.new
which are checking the returned value are now callingnew (std::nothrow)
instead(the others will abort on oom, then reboot)
malloc
is untouched: it returnsnullptr
on oom likenew (std::nothrow)