This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Add configure flag for operator new (std::nothrow)
- From: Daniel Gutson <daniel dot gutson at tallertechnologies dot com>
- To: Jonathan Wakely <jwakely at redhat dot com>
- Cc: Pedro Alves <alves dot ped at gmail dot com>, Jonathan Wakely <jwakely dot gcc at gmail dot com>, Martin Sebor <msebor at gmail dot com>, Aurelio Remonda <aurelio dot remonda at tallertechnologies dot com>, "libstdc++" <libstdc++ at gcc dot gnu dot org>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 19 Feb 2016 18:45:18 -0300
- Subject: Re: [PATCH] Add configure flag for operator new (std::nothrow)
- Authentication-results: sourceware.org; auth=none
- References: <1446554133-3090-1-git-send-email-aurelio dot remonda at tallertechnologies dot com> <56391843 dot 1070807 at gmail dot com> <CAF5HaEVeD4G1Mj8GwbpLyZ8V+GWNRAy1=5qbfVHgrZ=GpkbHbg at mail dot gmail dot com> <CAH6eHdQ_8cL8rqsX5u3NrNouf6E2_LtRPQ5F-V-rgTQ3FZTRug at mail dot gmail dot com> <CAF5HaEX5Ju0uXcFP4cLRvh_wWOBaqezbM6WdNUFp+CbzzKNjdg at mail dot gmail dot com> <CAH6eHdRf296VZwDaz8cS742RKEWid76un6-7ogxyzcTyWzj=rw at mail dot gmail dot com> <CAF5HaEVx-Y9JJQ-nnUL3-kuwbCx0_rh+GOrxAFGFYBF2u6=iKw at mail dot gmail dot com> <CAH6eHdQYLqFLkMBJqe=4oSj20ago6F6rGXaDQ8umEEWsBy8k8g at mail dot gmail dot com> <563C79EB dot 7090302 at gmail dot com> <20151110131014 dot GC2937 at redhat dot com>
On Tue, Nov 10, 2015 at 10:10 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
> On 06/11/15 09:59 +0000, Pedro Alves wrote:
>>
>> On 11/06/2015 01:56 AM, Jonathan Wakely wrote:
>>>
>>> On 5 November 2015 at 23:31, Daniel Gutson
>>
>>
>>>> The issue is, as I understand it, to do the actual work of operator
>>>> new, i.e. allocate memory. It should force
>>>> us to copy most of the code of the original code of operator new,
>>>> which may change on new versions of the
>>>> STL, forcing us to keep updated.
>>>
>>>
>>> It can just call malloc, and the replacement operator delete can call
>>> free.
>>>
>>> That is very unlikely to need to change (which is corroborated by the
>>> fact that the default definitions in libsupc++ change very rarely).
>>
>>
>> Or perhaps libsupc++ could provide the default operator new under
>> a __default_operator_new alias or some such, so that the user-defined
>> replacement can fallback to calling it. Likewise for op delete.
that would allow us to overload operator new as something like this:
void* operator new ( std::size_t count, const std::nothrow_t& tag)
noexcept(true)
{
const auto old_handler = std::set_new_handler(nullptr);
const auto ret = __default_operator_new(count, tag);
std::set_new_handler(old_handler);
return ret;
}
This is a non-iterating operator new.
This additional user defined operator new would be possible:
void* operator new ( std::size_t count, const std::nothrow_t& tag)
noexcept(true)
{
const auto old_handler = std::set_new_handler(nullptr);
const auto ret = __default_operator_new(count, tag);
std::set_new_handler(old_handler);
if (ret == nullptr && old_handler != nullptr)
old_handler();
return ret;
}
So I like the idea.
>
>
> That could be useful, please file an enhancement request in bugzilla
> if you'd like that done.
--
Daniel F. Gutson
Chief Engineering Officer, SPD
San Lorenzo 47, 3rd Floor, Office 5
CÃrdoba, Argentina
Phone: +54 351 4217888 / +54 351 4218211
Skype: dgutson
LinkedIn: http://ar.linkedin.com/in/danielgutson