diff options
author | anonymous <local@localhost> | 2010-06-30 19:11:55 +0700 |
---|---|---|
committer | anonymous <local@localhost> | 2010-07-02 22:14:18 +0700 |
commit | 16c253aab349547b256482e6dcc86029d8fe2eda (patch) | |
tree | 0d5dbf3a058ae9cb7e2dbe68f0ce79e2e70f1dd1 /src | |
parent | 14a33592c267fe9dc277412444525f3fcfe14f15 (diff) | |
download | libcxxrt-16c253aab349547b256482e6dcc86029d8fe2eda.tar.gz libcxxrt-16c253aab349547b256482e6dcc86029d8fe2eda.tar.bz2 libcxxrt-16c253aab349547b256482e6dcc86029d8fe2eda.tar.xz |
1) Static library is added;
2) Aux std functions are added
3) Memory operators are added
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 12 | ||||
-rw-r--r-- | src/aux.cc | 13 | ||||
-rw-r--r-- | src/memory.cc | 23 | ||||
-rw-r--r-- | src/stdexcept.cc | 80 | ||||
-rw-r--r-- | src/stdexcept.h | 56 |
5 files changed, 183 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile index d8240a7..499a05c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,5 @@ -OBJECTS = typeinfo.o exception.o dynamic_cast.o terminate.o guard.o +OBJECTS = typeinfo.o exception.o dynamic_cast.o terminate.o guard.o \ + stdexcept.o memory.o aux.o # Needed for building the shared library CXXFLAGS = -fPIC @@ -20,10 +21,16 @@ LDFLAGS += -L/usr/local/lib -L. -lpthread -fexceptions PRODUCTS = libcxxabi.so.1 +all: libcxxabi.so.1 libcxxabi.a + libcxxabi.so.1: $(OBJECTS) @echo Linking $@... @gcc -fexception -shared $(OBJECTS) $(LDFLAGS) -o libcxxabi.so.1 #-lunwind +libcxxabi.a: $(OBJECTS) + @ar cr libcxxabi.a $(OBJECTS) + + .cc.o: @echo Compiling $<... @$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< @@ -38,3 +45,6 @@ exception.o: exception.cc typeinfo.h abi_namespace.h typeinfo dwarf_eh.h guard.o: guard.cc terminate.o: terminate.cc typeinfo.o: typeinfo.cc typeinfo.h abi_namespace.h typeinfo +stdexcept.o: stdexcept.cc stdexcept.h +memory.o: memory.cc stdexcept.h +aux.o: aux.cc stdexcept.h diff --git a/src/aux.cc b/src/aux.cc new file mode 100644 index 0000000..c1590e5 --- /dev/null +++ b/src/aux.cc @@ -0,0 +1,13 @@ + +#include "stdexcept.h" + +extern "C" void __cxa_bad_cast() +{ + throw std::bad_cast(); +} + +extern "C" void __cxa_bad_typeid() +{ + throw std::bad_typeid(); +} + diff --git a/src/memory.cc b/src/memory.cc new file mode 100644 index 0000000..de4bc0c --- /dev/null +++ b/src/memory.cc @@ -0,0 +1,23 @@ + + +// This file contains definition of C++ new/delete operators + + +#include <stddef.h> +#include <malloc.h> +#include "stdexcept.h" + +void * operator new(size_t size) { + void * mem = malloc(size); + if(mem == NULL) { + throw std::bad_alloc(); + } + + return mem; +} + + +void operator delete(void * ptr) { + free(ptr); +} + diff --git a/src/stdexcept.cc b/src/stdexcept.cc new file mode 100644 index 0000000..3d4e086 --- /dev/null +++ b/src/stdexcept.cc @@ -0,0 +1,80 @@ + +#include "stdexcept.h" + +namespace std { + + +exception::exception() throw() { +} + +exception::exception(const exception&) throw() { +} + +exception& exception::operator=(const exception&) throw() { + return *this; +} + +exception::~exception() { +} + +const char* exception::what() const throw() { + return 0; +} + + +bad_alloc::bad_alloc() throw() { +} + +bad_alloc::bad_alloc(const bad_alloc&) throw() { +} + +bad_alloc& bad_alloc::operator=(const bad_alloc&) throw() { + return *this; +} + +bad_alloc::~bad_alloc() { +} + +const char* bad_alloc::what() const throw() { + return "cxxrt::bad_alloc"; +} + + + +bad_cast::bad_cast() throw() { +} + +bad_cast::bad_cast(const bad_cast&) throw() { +} + +bad_cast& bad_cast::operator=(const bad_cast&) throw() { + return *this; +} + +bad_cast::~bad_cast() { +} + +const char* bad_cast::what() const throw() { + return "std::bad_cast"; +} + + +bad_typeid::bad_typeid() throw() { +} + +bad_typeid::bad_typeid(const bad_typeid &__rhs) throw() { +} + +bad_typeid::~bad_typeid() { +} + +bad_typeid& bad_typeid::operator=(const bad_typeid &__rhs) throw() { + return *this; +} + +const char* bad_typeid::what() const throw() { + return "std::bad_typeid"; +} + +} + diff --git a/src/stdexcept.h b/src/stdexcept.h new file mode 100644 index 0000000..af06bda --- /dev/null +++ b/src/stdexcept.h @@ -0,0 +1,56 @@ + + +// This header defines standard exception classes which are needed +// for implementing new/delete operators + + +#ifndef __LIBCXXSUP_STDEXCEPT_H__ +#define __LIBCXXSUP_STDEXCEPT_H__ + +namespace std { + +class exception { +public: + exception() throw(); + exception(const exception&) throw(); + exception& operator=(const exception&) throw(); + virtual ~exception(); + virtual const char* what() const throw(); +}; + + +class bad_alloc: public exception { +public: + bad_alloc() throw(); + bad_alloc(const bad_alloc&) throw(); + bad_alloc& operator=(const bad_alloc&) throw(); + ~bad_alloc(); + virtual const char* what() const throw(); +}; + + +class bad_cast: public exception { +public: + bad_cast() throw(); + bad_cast(const bad_cast&) throw(); + bad_cast& operator=(const bad_cast&) throw(); + virtual ~bad_cast(); + virtual const char* what() const throw(); +}; + + +class bad_typeid: public exception { +public: + bad_typeid() throw(); + bad_typeid(const bad_typeid &__rhs) throw(); + virtual ~bad_typeid(); + bad_typeid& operator=(const bad_typeid &__rhs) throw(); + virtual const char* what() const throw(); +}; + + + +} // namespace std + +#endif // __LIBCXXSUP_STDEXCEPT_H__ + |