mimalloc: Missing C++ operators taking `std::nothrow_t`
Overrides for C++ operator new and operator delete taking std::nothrow_t arguments are missing.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16
Commits related to this issue
- fix compilation with C++, fix overrides in C++ to adhere to the spec (issue #26) — committed to microsoft/mimalloc by daanx 5 years ago
Only some of them do that. Some of them do not. Especially when in debug builds with debug runtimes/libraries in play.
This is not true. It may be true on some platforms (libstdc++ maybe) but is not true on others.
To be very clear, it is also not true to ever assume that one overload of
newwill ever call a different overload ofnewby default.To do otherwise is to invoke undefined behavior.
If mimalloc is overriding
new, I would not only absolutely expect it to override all overloads, I would also expect that with mimalloc’s debug/security/correctness layer turned on that mimalloc would detect and raise an error whennewandfree(ormallocanddelete) are inappropriately paired, just like some existing C++ standard library implementations do today.Just pushed a new commit that implements the correct overriding for new/delete if compiling with a C++ compiler; adds overrides for all current new/delete variants including
nothrowetc. When using a C compiler we cannot callget_new_handleror throw exceptions, so in that case these are not overridden at all and we rely on the standard implementations calling malloc/free under the hood. (we do overridealigned_allocas well so everything should work now) 😃When the standard says throw
bad_allocthen the operator should do it. It is the caller who should be able to do something about it, if he wants to. Also note that there isset_new_handlerAPI.I haven’t found where, in mimalloc, they are overridden.
First,
operator newdoesn’t necessarily have to callmalloc. Maybe the existing runtimes do by incident, I haven’t checked, but you’re relying on implementation detail of the runtimes.Second, if you want to rely on implementation details, then at least be consistent about it. Either override all operators, or none. At least, if the operators don’t use
malloc/free, they will be able to work with whatever heap they all use.