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: fopen/fclose


Andrew Lunn wrote (Monday, March 25, 2002 13:57):
> > However, I don't understand why FILE operations wouldn't use delete when
> > CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS is disabled (... #ifdef
> > CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS ... #else...#endif ...)?
> > Specifically, I need to overload default new/delete operators
> and this might
> > not be possible if 'fopen()' uses new, while 'fclose()' does not call
> > delete.
>
> How about...
>
> Because know one has yet needed to overload new/delete for FILE
> operations.
>

Maybe I did not express myself correctly :-)
What I need is to modify C++ built-in (global) 'new' & 'delete' operators.
Since this is quite normal in C++ (egg. for memory leaks & overwrites
detection) I believe that having 'delete' in fclose()
is quite reasonable in case CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS is disabled.


> Just a guess. Jifl is the correct person to answer this question i
> guess.
>

Then I would appreciate Jonathan's opinion on trivial patch at the end of
mail.


> You are obviously delving around the insides of eCos and not using the
> C API. The C API does not require what you want and so its not
> strictly needed. You can always add it and send a patch to Jifl for
> inclusion.

Thanks for your help.


Best regards,
Jura

Here is the patch that fixed my problem. I hope that it can be safely
applied to the eCos CVS.
====================================================================

--- packages/language/c/libc/stdio/current/src/common/fclose.cxx  Fri Aug 25
20:33:40 2000
+++ packages/language/c/libc/stdio/current/src/common/fclose.cxx Mon Mar 25
14:53:18 2002
@@ -96,12 +96,16 @@ fclose( FILE *stream )
         return EOF;
     }

+#ifdef CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS
     // FIXME: should use delete?
     // Explicitly call destructor - this flushes the output too
     real_stream->~Cyg_StdioStream();

     // and free it
     free(real_stream);
+#else
+    delete real_stream;
+#endif // CYGFUN_INFRA_EMPTY_DELETE_FUNCTIONS

     // and mark the stream available for use
     Cyg_libc_stdio_files::set_file_stream(i, NULL);



-- 
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]