public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Daniel Gutson <daniel.gutson@tallertechnologies.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: Pedro Alves <alves.ped@gmail.com>,
	Jonathan Wakely <jwakely.gcc@gmail.com>,
		Martin Sebor <msebor@gmail.com>,
	Aurelio Remonda <aurelio.remonda@tallertechnologies.com>,
		"libstdc++" <libstdc++@gcc.gnu.org>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Add configure flag for operator new (std::nothrow)
Date: Fri, 19 Feb 2016 21:45:00 -0000	[thread overview]
Message-ID: <CAF5HaEUzkz_hB-i46oP6hg85HWq3UnJiCDU1Pu8WZzomJq3qVg@mail.gmail.com> (raw)
In-Reply-To: <20151110131014.GC2937@redhat.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

  parent reply	other threads:[~2016-02-19 21:45 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-03 12:35 Aurelio Remonda
2015-11-03 13:26 ` Paolo Carlini
2015-11-03 14:06   ` Aurelio Remonda
2015-11-03 14:12     ` Andreas Schwab
2015-11-03 17:17   ` Aurelio Remonda
2015-11-03 20:25 ` Martin Sebor
2015-11-03 20:41   ` Daniel Gutson
2015-11-03 21:10     ` Martin Sebor
2015-11-03 23:09       ` Mike Stump
2015-11-03 23:50         ` Martin Sebor
2015-11-04  8:07           ` Marc Glisse
2015-11-04  6:20     ` Jonathan Wakely
2015-11-04  6:32       ` Jonathan Wakely
2015-11-05 15:22       ` Daniel Gutson
2015-11-05 17:11         ` Jonathan Wakely
2015-11-05 18:01           ` Daniel Gutson
2015-11-06  1:56             ` Jonathan Wakely
     [not found]               ` <CAF5HaEVF12CH+Z6BssUwmS-TVxGsjfXWdvvGUZ2OHuUhOhhwHA@mail.gmail.com>
2015-11-06  4:24                 ` Jonathan Wakely
2015-11-06  7:19                   ` Marc Glisse
2015-11-06  9:59               ` Pedro Alves
2015-11-10 13:10                 ` Jonathan Wakely
2015-11-16 18:56                   ` Pedro Alves
2016-02-19 21:56                     ` Daniel Gutson
2016-02-22 15:58                       ` Jonathan Wakely
2016-02-19 21:45                   ` Daniel Gutson [this message]
2015-11-17 12:38         ` Sebastian Huber
2015-11-04  6:15   ` Jonathan Wakely
2015-11-04 14:52     ` Martin Sebor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAF5HaEUzkz_hB-i46oP6hg85HWq3UnJiCDU1Pu8WZzomJq3qVg@mail.gmail.com \
    --to=daniel.gutson@tallertechnologies.com \
    --cc=alves.ped@gmail.com \
    --cc=aurelio.remonda@tallertechnologies.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jwakely.gcc@gmail.com \
    --cc=jwakely@redhat.com \
    --cc=libstdc++@gcc.gnu.org \
    --cc=msebor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).