OSDN Git Service

2005-08-17 Kelley Cook <kcook@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / libsupc++ / eh_alloc.cc
index 1f59ec4..3577920 100644 (file)
@@ -1,22 +1,22 @@
 // -*- C++ -*- Allocate exception objects.
-// Copyright (C) 2001 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2004 Free Software Foundation, Inc.
 //
-// This file is part of GNU CC.
+// This file is part of GCC.
 //
-// GNU CC is free software; you can redistribute it and/or modify
+// GCC is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
 // the Free Software Foundation; either version 2, or (at your option)
 // any later version.
 //
-// GNU CC is distributed in the hope that it will be useful,
+// GCC is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 // GNU General Public License for more details.
 //
 // You should have received a copy of the GNU General Public License
-// along with GNU CC; see the file COPYING.  If not, write to
-// the Free Software Foundation, 59 Temple Place - Suite 330,
-// Boston, MA 02111-1307, USA.
+// along with GCC; see the file COPYING.  If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02110-1301, USA.
 
 // As a special exception, you may use this file as part of a free software
 // library without restriction.  Specifically, if other files instantiate
 // This is derived from the C++ ABI for IA-64.  Where we diverge
 // for cross-architecture compatibility are noted with "@@@".
 
-#include <exception>
 #include <cstdlib>
+#if _GLIBCXX_HOSTED
 #include <cstring>
+#endif
 #include <climits>
+#include <exception>
 #include "unwind-cxx.h"
 #include "bits/c++config.h"
 #include "bits/gthr.h"
 
-using namespace __cxxabiv1;
+#if _GLIBCXX_HOSTED
+using std::free;
+using std::malloc;
+using std::memcpy;
+#else
+// In a freestanding environment, these functions may not be
+// available -- but for now, we assume that they are.
+extern "C" void *malloc (std::size_t);
+extern "C" void free(void *);
+extern "C" int memset (void *, int, std::size_t);
+#endif
 
+using namespace __cxxabiv1;
 
 // ??? How to control these parameters.
 
@@ -94,12 +107,12 @@ emergency_mutex_init ()
 
 
 extern "C" void *
-__cxa_allocate_exception(std::size_t thrown_size)
+__cxxabiv1::__cxa_allocate_exception(std::size_t thrown_size) throw()
 {
   void *ret;
 
   thrown_size += sizeof (__cxa_exception);
-  ret = std::malloc (thrown_size);
+  ret = malloc (thrown_size);
 
   if (! ret)
     {
@@ -134,14 +147,20 @@ __cxa_allocate_exception(std::size_t thrown_size)
        std::terminate ();
     }
 
-  std::memset (ret, 0, sizeof (__cxa_exception));
+  // We have an uncaught exception as soon as we allocate memory.  This
+  // yields uncaught_exception() true during the copy-constructor that
+  // initializes the exception object.  See Issue 475.
+  __cxa_eh_globals *globals = __cxa_get_globals ();
+  globals->uncaughtExceptions += 1;
+
+  memset (ret, 0, sizeof (__cxa_exception));
 
   return (void *)((char *)ret + sizeof (__cxa_exception));
 }
 
 
 extern "C" void
-__cxa_free_exception(void *vptr)
+__cxxabiv1::__cxa_free_exception(void *vptr) throw()
 {
   char *ptr = (char *) vptr;
   if (ptr >= &emergency_buffer[0][0]
@@ -159,5 +178,5 @@ __cxa_free_exception(void *vptr)
 #endif
     }
   else
-    std::free (ptr - sizeof (__cxa_exception));
+    free (ptr - sizeof (__cxa_exception));
 }