This is the mail archive of the ecos-patches@sourceware.org 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: Always provide exit() & friends prototypes.


Sergei Organov wrote:
Jonathan Larmour <jifl@eCosCentric.com> writes:
Sergei Organov wrote:
Hello,

A short patch below ensures exit(), etc. prototypes are provided in
<stdlib.h> even when CYGINT_ISO_EXIT is undefined.

For me it solves the problem that I don't wish to use libc_startup
package, but do use exit()/abort() routines in applications. So the
situation is that application itself provides implementation of those
functions, while their declarations are expected to be found in the
<stdlib.h>.
Then you should add your own package and implement CYGINT_ISO_EXIT;

Even if I can't think of an implementation? A package that provides empty or CYG_FAIL'ing exit()? Why?

Then fix your code not to use it :-), or "#define exit(x)" in an application header or something. I think it's much more valuable to more eCos users that people who call functions that are not included due to configuration choices that they have made get it picked up straight away at compile time.


or declare them in your own application-specific header.

Not an option. Almost any C code on this planet expects to find exit() declaration in the <stdlib.h>.

Only because they assume it is a conforming implementation, meaning there's a real implementation. What we're talking about here is a non-conforming implementation (due to deliberate configuration choices by the programmer).


Only OS definitions should go in <stdlib.h>.

The contents of <stdlib.h> is specified by the C standard, and exit() is standard declaration that should be there in <stdlib.h> according to the C standard. Currently (at some configuration options) eCos provides non-standard <stdlib.h> and non-standard libc. I'd vote for standard <stdlib.h> and non-standard libc (missing exit() definition) instead,

I vote no declaration if there is no definition, in order to pick up configuration misunderstandings as soon as possible.


From practicality POV, it's more convenient to have all the standard
declarations there in <stdlib.h>, making existence/absence of their
implementation separate issue. What is the pain of having exit()
*declaration* at it's standard place in the <stdlib.h>?

exit(), like other functions, has implementation-specific behaviour associated. For example the values of the EXIT_SUCCESS and EXIT_FAILURE macros. This is why as a general rule (exit() being no exception) functions are only declared when the implementation has been selected. There are some exceptions, but there are usually particularly good special reasons; or people were lazy in implementation :/.


For eCos source base itself, it solves the following problem. If one
configures eCos, e.g., like is shown below, and tries to compile with
rather recent GCC (v.3+; old versions of GCC happened to declare exit()
internally), she gets the following error:

[...]
That's a separate problem due to failing to take into account CDL
dependencies. Fixed with the attached patch, checked in.

No, that's exactly this problem, -- see below.


[...]
+#if CYGINT_ISO_EXIT
     exit(1000 + sig); // FIXME
+#else
+    CYG_FAIL("Default signal handler called - no exit available");
+#endif

Sorry, but this looks more like a work-around. In C, if you need exit(), you call exit(), and if you need to call exit(), your include <stlib.h>, period. If you still don't see the problem, there are actually hundreds places that call exit() in the eCos "packages/" tree (I've counted roughly 230). Are you going to check/fix all those as well?! That is exactly the problem that I faced with in applications.

I did consider whether it was better or not to instead put in a "requires CYGINT_ISO_EXIT" in the package CDL, but I thought that would annoy you more so chose it like I did. I am happy to switch if you think that leads to a more consistent implementation - I think I'd agree.


Incidentally there is an eCos kernel thread class method called exit(), so I expect you have a lot of false positives in that count; as well as of course those packages which do have consistent CDL "requires" statements.

I think the CYG_FAIL() you have added rather belongs to the exit()
implementation, provided you prefer run-time checks (that besides are
off by default) over link-time checks.

No I don't prefer run-time checks, and preferably not even link-time checks, if compile-time checks are possible.


In your specific case I do think having a header which does:
#define exit(x)   /* nothing */
(or defined to whatever you want) should do.

Jifl
--
eCosCentric Limited      http://www.eCosCentric.com/     The eCos experts
Barnwell House, Barnwell Drive, Cambridge, UK.       Tel: +44 1223 245571
Registered in England and Wales: Reg No 4422071.
 >>>> Visit us on stand 810 at The Embedded Systems Show 2007, NEC <<<<
 >>>> Oct 17-18 Birmingham, UK http://www.edaexhibitions.com/ess/  <<<<
------["The best things in life aren't things."]------      Opinions==mine


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