OSDN Git Service

* Makefile.am (hosted_source): Add libmath and testsuite.
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / libsupc++ / eh_alloc.cc
index ab285fd..dbf007e 100644 (file)
 // for cross-architecture compatibility are noted with "@@@".
 
 #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.
 
@@ -99,7 +112,7 @@ __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,7 +147,7 @@ __cxa_allocate_exception(std::size_t thrown_size) throw()
        std::terminate ();
     }
 
-  std::memset (ret, 0, sizeof (__cxa_exception));
+  memset (ret, 0, sizeof (__cxa_exception));
 
   return (void *)((char *)ret + sizeof (__cxa_exception));
 }
@@ -159,5 +172,5 @@ __cxa_free_exception(void *vptr) throw()
 #endif
     }
   else
-    std::free (ptr - sizeof (__cxa_exception));
+    free (ptr - sizeof (__cxa_exception));
 }