[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tyndur-devel] [PATCH 4/6] + 18.4 Language support library, Start and termination: <cstdlib>



Am Montag, 1. Juni 2009 20:59 schrieb Jörg Pfähler:
> ---
>  STATUS                          |    2 +-
>  include/cstdlib                 |  140
> +++++++++++++++++++++++++++++++++++++++ include/lightlibc++/doxygen.hpp |  
>  2 +
>  source/cstdlib.cpp              |   71 ++++++++++++++++++++
>  4 files changed, 214 insertions(+), 1 deletions(-)
>  create mode 100644 include/cstdlib
>  create mode 100644 source/cstdlib.cpp

> diff --git a/source/cstdlib.cpp b/source/cstdlib.cpp
> new file mode 100644
> index 0000000..2f30780
> --- /dev/null
> +++ b/source/cstdlib.cpp
> @@ -0,0 +1,71 @@
> +/*
> +Permission is granted to use, modify, and / or redistribute at will.
> +
> +This includes removing authorship notices, re-use of code parts in
> +other software (with or without giving credit), and / or creating a
> +commercial product based on it.
> +
> +This permission is not revocable by the author.
> +
> +This software is provided as-is. Use it at your own risk. There is
> +no warranty whatsoever, neither expressed nor implied, and by using
> +this software you accept that the author(s) shall not be held liable
> +for any loss of data, loss of service, or other damages, be they
> +incidental or consequential. Your only option other than accepting
> +this is not to use the software at all.
> +*/
> +#include <cstdlib>
> +#include <cstddef>           // std::size_t
> +#include <exception>         // std::terminate
> +
> +
> +
> +/*
> + * file-local variables
> + */
> +typedef void (*quick_exit_function_t)(void);
> +quick_exit_function_t quick_exit_functions[32];
> +std::size_t quick_exit_functions_index = 0;

Wie im IRC besprochen wäre hier zweimal ein static nett

> +
> +
> +
> +/*
> + * functions
> + */
> +
> +int std::at_quick_exit(void (*f)(void))

Willst du hier nicht den oben definierten Typ verwenden?

> +{
> +  // TODO: Ensure thread-safety
> +
> +  if (quick_exit_functions_index == 32)

Besser eine Konstante statt der 32 oder was mit sizeof. Sonst gehen die 
Deklaration des Arrays und dieser Code garantiert irgendwann auseinander.

> +    return -1;
> +
> +  quick_exit_functions[quick_exit_functions_index++] = f;
> +  return 0;
> +}
> +
> +void std::quick_exit(int status)
> +{
> +  // TODO: except that a function shall be called after any previously
> +  //       registered functions that had already been called at the time
> it was +  //       registered
> +  for (;quick_exit_functions_index > 0;--quick_exit_functions_index)
> +  {
> +    #ifndef _LIGHTLIBCPP_NO_EXCEPTIONS
> +      try
> +      {
> +    #endif
> +
> +        quick_exit_functions[quick_exit_functions_index - 1]();
> +
> +    #ifndef _LIGHTLIBCPP_NO_EXCEPTIONS
> +      }
> +      catch (...)
> +      {
> +        std::terminate();
> +      }
> +    #endif
> +  }
> +
> +  std::_Exit(status);
> +}

Dieses #ifdef läuft natürlich der testgetriebenen Entwicklung völlig entgegen. 
Du hast nicht nur keinen Testcase dafür, sondern es wird momentan nichtmal 
kompiliert (klar, geht vermutlich auch gar nicht). Aber meinetwegen kannst du 
es auch so lassen.