diff options
Diffstat (limited to 'odb/details')
-rw-r--r-- | odb/details/posix/exceptions.cxx | 6 | ||||
-rw-r--r-- | odb/details/posix/exceptions.hxx | 3 | ||||
-rw-r--r-- | odb/details/shared-ptr.hxx | 1 | ||||
-rw-r--r-- | odb/details/shared-ptr/base.cxx | 21 | ||||
-rw-r--r-- | odb/details/shared-ptr/base.hxx | 10 | ||||
-rw-r--r-- | odb/details/shared-ptr/base.ixx | 6 | ||||
-rw-r--r-- | odb/details/shared-ptr/base.txx | 26 | ||||
-rw-r--r-- | odb/details/shared-ptr/exception.hxx | 30 | ||||
-rw-r--r-- | odb/details/win32/exceptions.cxx | 6 | ||||
-rw-r--r-- | odb/details/win32/exceptions.hxx | 3 |
10 files changed, 89 insertions, 23 deletions
diff --git a/odb/details/posix/exceptions.cxx b/odb/details/posix/exceptions.cxx index 7a50a13..b8bb702 100644 --- a/odb/details/posix/exceptions.cxx +++ b/odb/details/posix/exceptions.cxx @@ -13,5 +13,11 @@ namespace odb { return "POSIX API error"; } + + posix_exception* posix_exception:: + clone () const + { + return new posix_exception (*this); + } } } diff --git a/odb/details/posix/exceptions.hxx b/odb/details/posix/exceptions.hxx index ebea763..5ff023d 100644 --- a/odb/details/posix/exceptions.hxx +++ b/odb/details/posix/exceptions.hxx @@ -24,6 +24,9 @@ namespace odb virtual const char* what () const throw (); + virtual posix_exception* + clone () const; + private: int code_; }; diff --git a/odb/details/shared-ptr.hxx b/odb/details/shared-ptr.hxx index aecde12..9d2b62f 100644 --- a/odb/details/shared-ptr.hxx +++ b/odb/details/shared-ptr.hxx @@ -9,6 +9,7 @@ #include <odb/details/shared-ptr-fwd.hxx> #include <odb/details/shared-ptr/base.hxx> +#include <odb/details/shared-ptr/exception.hxx> namespace odb { diff --git a/odb/details/shared-ptr/base.cxx b/odb/details/shared-ptr/base.cxx index 590d844..0214c54 100644 --- a/odb/details/shared-ptr/base.cxx +++ b/odb/details/shared-ptr/base.cxx @@ -3,6 +3,7 @@ // license : GNU GPL v2; see accompanying LICENSE file #include <odb/details/shared-ptr/base.hxx> +#include <odb/details/shared-ptr/exception.hxx> using std::size_t; @@ -19,6 +20,12 @@ namespace odb return "object is not shared"; } + not_shared* not_shared:: + clone () const + { + return new not_shared (*this); + } + bool shared_base:: _dec_ref_callback () { @@ -29,6 +36,20 @@ namespace odb return r; } + + namespace bits + { + size_t* locator_common:: + counter (void* x) + { + size_t* p (static_cast<size_t*> (x)); + + if (*(--p) != 0xDEADBEEF) + throw not_shared (); + + return --p; + } + } } } diff --git a/odb/details/shared-ptr/base.hxx b/odb/details/shared-ptr/base.hxx index 6cfe1c9..b16bc8b 100644 --- a/odb/details/shared-ptr/base.hxx +++ b/odb/details/shared-ptr/base.hxx @@ -10,7 +10,6 @@ #include <new> #include <cstddef> // std::size_t -#include <odb/exception.hxx> #include <odb/details/export.hxx> #include <odb/details/shared-ptr/counter-type.hxx> @@ -45,12 +44,6 @@ namespace odb { namespace details { - struct LIBODB_EXPORT not_shared: exception - { - virtual const char* - what () const throw (); - }; - class LIBODB_EXPORT shared_base { public: @@ -69,6 +62,9 @@ namespace odb _ref_count () const; void* + operator new (std::size_t) throw (std::bad_alloc); + + void* operator new (std::size_t, share) throw (std::bad_alloc); void diff --git a/odb/details/shared-ptr/base.ixx b/odb/details/shared-ptr/base.ixx index 53105ce..c5beec6 100644 --- a/odb/details/shared-ptr/base.ixx +++ b/odb/details/shared-ptr/base.ixx @@ -64,6 +64,12 @@ namespace odb } inline void* shared_base:: + operator new (std::size_t n) throw (std::bad_alloc) + { + return ::operator new (n); + } + + inline void* shared_base:: operator new (std::size_t n, share) throw (std::bad_alloc) { return ::operator new (n); diff --git a/odb/details/shared-ptr/base.txx b/odb/details/shared-ptr/base.txx index e00bd5c..7047b7a 100644 --- a/odb/details/shared-ptr/base.txx +++ b/odb/details/shared-ptr/base.txx @@ -13,38 +13,32 @@ namespace odb { // Support for locating the counter in the memory block. // + struct LIBODB_EXPORT locator_common + { + static std::size_t* + counter (void*); + }; + template <typename X, bool poly = meta::polymorphic_p<X>::result> struct locator; template <typename X> - struct locator<X, false> + struct locator<X, false>: locator_common { static std::size_t* counter (X* x) { - std::size_t* p (reinterpret_cast<std::size_t*> (x)); - - if (*(--p) != 0xDEADBEEF) - throw not_shared (); - - return --p; + return locator_common::counter (x); } }; template <typename X> - struct locator<X, true> + struct locator<X, true>: locator_common { static std::size_t* counter (X* x) { - std::size_t* p ( - static_cast<std::size_t*> ( - dynamic_cast<void*> (x))); - - if (*(--p) != 0xDEADBEEF) - throw not_shared (); - - return --p; + return locator_common::counter (dynamic_cast<void*> (x)); } }; diff --git a/odb/details/shared-ptr/exception.hxx b/odb/details/shared-ptr/exception.hxx new file mode 100644 index 0000000..bd7ea38 --- /dev/null +++ b/odb/details/shared-ptr/exception.hxx @@ -0,0 +1,30 @@ +// file : odb/details/shared-ptr/exception.hxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_DETAILS_SHARED_PTR_EXCEPTION_HXX +#define ODB_DETAILS_SHARED_PTR_EXCEPTION_HXX + +#include <odb/pre.hxx> + +#include <odb/exception.hxx> +#include <odb/details/export.hxx> + +namespace odb +{ + namespace details + { + struct LIBODB_EXPORT not_shared: exception + { + virtual const char* + what () const throw (); + + virtual not_shared* + clone () const; + }; + } +} + +#include <odb/post.hxx> + +#endif // ODB_DETAILS_SHARED_PTR_EXCEPTION_HXX diff --git a/odb/details/win32/exceptions.cxx b/odb/details/win32/exceptions.cxx index 75043b4..10605c2 100644 --- a/odb/details/win32/exceptions.cxx +++ b/odb/details/win32/exceptions.cxx @@ -13,5 +13,11 @@ namespace odb { return "Win32 API error"; } + + win32_exception* win32_exception:: + clone () const + { + return new win32_exception (*this); + } } } diff --git a/odb/details/win32/exceptions.hxx b/odb/details/win32/exceptions.hxx index ecc36b6..c987430 100644 --- a/odb/details/win32/exceptions.hxx +++ b/odb/details/win32/exceptions.hxx @@ -26,6 +26,9 @@ namespace odb virtual const char* what () const throw (); + virtual win32_exception* + clone () const; + private: DWORD code_; }; |