This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: linking problem when using "fopen"


Robin Farine wrote:
> 
> On Fri, 2002-04-05 at 10:45, Martin Buck wrote:
> > Jonathan Larmour wrote:
> > > > Using the non-throwing form of operator new might work:
> > > >
> > > >         new (std::nothrow) Cyg_StdioStream(...);
> > >
> > > I'm afraid I doubt this will work.
> >
> > I don't know about this problem here, but wouldn't "new (std::nothrow)"
> > be the correct solution anyway?
> >
> > IIRC, gcc assumes that the standard new always succeeds if it doesn't
> > throw an exception (which it can't in this case due to -fno-exceptions)
> > and calls the constructor without checking the return value from new. So
> > checking for curr_stream == NULL in fopen.cxx is useless because calling
> > Cyg_StdioStream's constructor with a NULL this pointer will most likely
> > already have caused a crash.

I thought that an effect of compiling with -fno-exceptions means that gcc
would automatically use the nothrow variant.

> Yes, good point Martin. However, the class Cyg_StdioStream could
> redefine new to use a preallocated heap and keep one slot for the error
> case for instance. Anyway, it would not return NULL.
> 
> In this particular case, (new not overridden and no C++ exceptions), I
> believe that a safe way to do it would first allocate the required space
> using "new char [sizeof(...)]", and then if this doesn't return 0 then
> call the placement operator new to actually create the object.

char's probably bad in case there are alignment issues (future/alternative
versions of malloc may not align things so generously (i.e. wastefully).

Anyway, I've changed it to allocate with malloc and use placement new
instead now.

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]