[haiku-development] Re: possible bad usage of "new" in haiku

  • From: "François Revol" <revol@xxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Mon, 03 Nov 2008 12:01:10 +0100 CET

> Axel Dörfler wrote:
> > romain.haiku@xxxxxxxxxxx wrote:
> > > And I wonder if we do not missuse the "new" operator in haiku.
> > > For
> > > example
> > > in libbe.so, exceptions are not used (and afaik most/all of haiku
> > > code
> > > do
> > > not use them also). According to the previous link, testing for
> > > new
> > > returning null is nonsense on new compilers. This may not be an
> > > issue
> > > for
> > > the old gcc 2.95, but probably for 4.x.
> > >
> > > I discovered the nothrow notion with this link so I may miss
> > > something.
> > > Maybe we should make all haiku classes inherit from a common
> > > class that

That's not possible, at least not for R1, because it would break the
whole API compatibility with BeOS.
In BeOS exceptions were just not used, but indeed it'd be desirable to
fix all possible leaks.

> > > would just overload new with something like that:

Some applications actually use exceptions (like Pe...).

> > As inherited from the Be API, our API is indeed not supposed to
> > throw any
> > exceptions. Therefore, all API implementations are bound to use new
> > (std::nothrow) all the time.
> > If you detect any usage of "new" without std::nothrow, please open
> > a bug
> > report for this or supply patches that fixes those instances.
>
> If you spot usage of new without std::nothrow in applications and
> preflets,
> I would not report all those, just within the kits. Otherwise we
> would be

Well, for self-contained code, maybe it's possible to use a trick with
"using std::nothrow::new" at the top of the file for simplicity ? Would
still need a lot of NULL checks I suppose.

> overwelmed with the reports. One more question though: What about
> "new
> BMessage"? AFAIU, BMessage has a custom allocator? Can nothrow be
> ommited
> there?

Oh I didn't notice that one...

Hmm I suppose nothrow will change the signature and break the ABI...

François.


Other related posts: