-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Operator new improvements #287
Comments
This issue became relevant recently, when #340 was merged. With that, the Arduino core exposes a I had another look at this and planning to submit a fixing PR. I think the above steps are still good, except that we should probably not copy the uclibc++ implementation completely. Changes I think we need compared to
As for calling With the above, instead of using the uclibc++ coe, I think we might end up just using the existing implementation and modifying it to correctly handle 0-byte allocations and the above things, and maybe also call One open question is what should we implement exactly? Ideally, everything mandated by the standard for C++11, with the following differences:
If we implement the |
This makes this header complete up to including C++14, except two exception classes that cannot be defined without `<exception>`. The functions related to the "new_handler" are declared but not actually defined, to prevent overhead and complexity. They are still declared to allow implementing them in user code if needed. This makes the implementation of all operator new and delete functions comply with the C++11/C++14 specification in terms of which should be actually implemented and which should be delegate to other functions. There are still some areas where these implementations are not entirely standards-compliant, which will be fixed in subsequent commits. This fixes part of arduino#287 and fixes arduino#47.
This fixes part of arduino#287.
This is currently disabled, keeping the old behavior of returning NULL on failure, but should probably be enabled in the future as code that does want to do a null check has had a chance to switch to the more portable nothrow versions. When enabled, allocation failure calls the weak `std::terminate()`, which calls `abort()` by default, but can be replaced by user code to do more specific handling. To enable this, a macro must be defined (in new.cpp or on the compiler commandline). This fixes part of arduino#287.
This makes this header complete up to including C++14, except two exception classes that cannot be defined without `<exception>`. The functions related to the "new_handler" are declared but not actually defined, to prevent overhead and complexity. They are still declared to allow implementing them in user code if needed. This makes the implementation of all operator new and delete functions comply with the C++11/C++14 specification in terms of which should be actually implemented and which should be delegate to other functions. There are still some areas where these implementations are not entirely standards-compliant, which will be fixed in subsequent commits. This fixes part of arduino#287 and fixes arduino#47.
This fixes part of arduino#287.
This is currently disabled, keeping the old behavior of returning NULL on failure, but should probably be enabled in the future as code that does want to do a null check has had a chance to switch to the more portable nothrow versions. When enabled, allocation failure calls the weak `std::terminate()`, which calls `abort()` by default, but can be replaced by user code to do more specific handling. To enable this, a macro must be defined (in new.cpp or on the compiler commandline). This fixes part of arduino#287.
I submitted a PR, implementing pretty much what I proposed above. I did leave out the |
In arduino/Arduino#108, some improvements to the operator new provided by Arduino were suggested (since the current forms are not standards-compliant wrt error handling IIRC). The PR itself originally suggested to remove them and include uclibc++ instead, but after some discussion, we concluded that it would be better to:
throw(std::bad_alloc)
.std::__throw_bad_alloc
that callsstd::terminate()
std::terminate
that callsabort()
I think the PR itself is not really useful directly, but the dicussion on it is. I do not recall the details right now, but wanted to at least keep record of this here.
The text was updated successfully, but these errors were encountered: