home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gnat-2.06-src.tgz / tar.out / fsf / gnat / ada / a-raise.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  4KB  |  131 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                         GNAT COMPILER COMPONENTS                         */
  4. /*                                                                          */
  5. /*                              A - R A I S E                               */
  6. /*                                                                          */
  7. /*                          C Implementation File                           */
  8. /*                                                                          */
  9. /*                            $Revision: 1.7 $                              */
  10. /*                                                                          */
  11. /*        Copyright (c) 1992,1993,1994.1995 NYU, All Rights Reserved        */
  12. /*                                                                          */
  13. /* The GNAT library is free software; you can redistribute it and/or modify */
  14. /* it under terms of the GNU Library General Public License as published by */
  15. /* the Free Software  Foundation; either version 2, or (at your option) any */
  16. /* later version.  The GNAT library is distributed in the hope that it will */
  17. /* be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty */
  18. /* of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU */
  19. /* Library  General  Public  License for  more  details.  You  should  have */
  20. /* received  a copy of the GNU  Library  General Public License  along with */
  21. /* the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free */
  22. /* Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        */
  23. /*                                                                          */
  24. /****************************************************************************/
  25.  
  26. /* Routines to support runtime exception handling */
  27.  
  28.  
  29. /* ??? We need this to define malloc on those machines that need it, but
  30.    this is the wrong file when this is built for libgnat.a.  */
  31. #include "config.h"
  32.  
  33. /* predefined exceptions */
  34. char constraint_error = 0;
  35. char numeric_error    = 0;
  36. char program_error    = 0;
  37. char storage_error    = 0;
  38. char tasking_error    = 0;
  39. char _abort_signal    = 1;
  40.  
  41. extern void (*system__tasking_soft_links__abort_defer) ();  
  42. extern char *system__task_specific_data__get_gnat_exception ();
  43. extern int *system__task_specific_data__get_jmpbuf_address ();
  44. extern char debug__get_debug_flag_k (); 
  45.  
  46. void
  47. __gnat_unhandled_exception (except, ptr)
  48.      char *except;
  49.      int  *ptr;
  50. {
  51.   if (except == &constraint_error) 
  52.     puts ("\nraised Constraint_Error\n"); 
  53.   else if (except == &numeric_error) 
  54.     puts ("\nraised Numeric_Error\n"); 
  55.   else if (except == &program_error) 
  56.     puts ("\nraised Program_Error\n"); 
  57.   else if (except == &storage_error)
  58.     puts ("\nraised Storage_Error\n");
  59.   else if (except == &tasking_error)
  60.     puts ("\nraised Tasking_Error\n");
  61.   else if (!ptr)
  62.     puts ("\nraised unhandled exception\n");
  63. }
  64.  
  65. void
  66. __gnat_raise_nodefer (except)
  67.      char *except;
  68. {
  69.   int *ptr = system__task_specific_data__get_jmpbuf_address ();
  70.  
  71.   system__task_specific_data__set_gnat_exception (except);
  72.   if (ptr)
  73.     longjmp (ptr, 1);
  74.  
  75.   else 
  76.     {
  77.       __gnat_unhandled_exception (except, ptr);
  78.       exit (1);
  79.  
  80.     }
  81. }
  82.  
  83. void 
  84. __gnat_raise (except)
  85.      char *except;
  86. {
  87.   (*system__tasking_soft_links__abort_defer) ();
  88.   __gnat_raise_nodefer (except);
  89. }
  90.  
  91. void
  92. __gnat_reraise (flag)
  93.      int flag;
  94. {
  95.   char *except = system__task_specific_data__get_gnat_exception ();
  96.  
  97.   if (flag)
  98.     __gnat_raise (except);
  99.   else
  100.     __gnat_raise_nodefer (except);
  101. }
  102.  
  103. void
  104. __gnat_raise_constraint_error ()
  105. {
  106.   __gnat_raise (&constraint_error);
  107. }
  108.  
  109. void
  110. __gnat_raise_program_error ()
  111. {
  112.   __gnat_raise (&program_error);
  113. }
  114.  
  115. void *
  116. __gnat_malloc (size)
  117.      __SIZE_TYPE__ size;
  118. {
  119.   void *result;
  120.  
  121.   if (size == 0)
  122.     return 0;
  123.  
  124.   result = (char *) malloc (size);
  125.  
  126.   if (result == 0)
  127.     __gnat_raise (&storage_error);
  128.  
  129.   return result;
  130. }
  131.