aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-05-21 18:50:32 -0400
committerBoris Kolpackov <boris@codesynthesis.com>2013-05-21 18:50:32 -0400
commit6c666b0dfa38cf1f6407817261a829645e86d855 (patch)
treeed37bde32f989b86fb637121092bad85c4149e06
parent38b4810e67bf461ddad1cdd75b491ba7f8d5dd9b (diff)
Ignore requests to load transient objects in lazy pointers
-rw-r--r--odb/lazy-ptr.ixx17
-rw-r--r--odb/tr1/lazy-ptr.ixx11
2 files changed, 15 insertions, 13 deletions
diff --git a/odb/lazy-ptr.ixx b/odb/lazy-ptr.ixx
index 38fcf1a..724142a 100644
--- a/odb/lazy-ptr.ixx
+++ b/odb/lazy-ptr.ixx
@@ -115,7 +115,7 @@ namespace odb
inline T* lazy_ptr<T>::
load () const
{
- if (!loaded ())
+ if (p_ == 0 && i_)
p_ = i_.template load<T> (true); // Reset id.
return p_;
@@ -371,7 +371,7 @@ namespace odb
inline std::auto_ptr<T>& lazy_auto_ptr<T>::
load () const
{
- if (!loaded ())
+ if (p_.get () == 0 && i_)
{
std::auto_ptr<T> tmp (i_.template load<T> (true)); // Reset id.
p_ = tmp;
@@ -645,7 +645,7 @@ namespace odb
inline std::unique_ptr<T, D>& lazy_unique_ptr<T, D>::
load () const
{
- if (!loaded ())
+ if (!p_ && i_)
p_ = std::unique_ptr<T, D> (i_.template load<T> (true)); // Reset id.
return p_;
@@ -1128,7 +1128,7 @@ namespace odb
inline std::shared_ptr<T> lazy_shared_ptr<T>::
load () const
{
- if (!loaded ())
+ if (!p_ && i_)
p_ = i_.template load<T> (true); // Reset id.
return p_;
@@ -1517,11 +1517,12 @@ namespace odb
{
std::shared_ptr<T> r (p_.lock ());
- if (r || !i_)
- return r;
+ if (!r && i_)
+ {
+ r = i_.template load<T> (false); // Keep id.
+ p_ = r;
+ }
- r = i_.template load<T> (false); // Keep id.
- p_ = r;
return r;
}
diff --git a/odb/tr1/lazy-ptr.ixx b/odb/tr1/lazy-ptr.ixx
index e524710..b33a12d 100644
--- a/odb/tr1/lazy-ptr.ixx
+++ b/odb/tr1/lazy-ptr.ixx
@@ -185,7 +185,7 @@ namespace odb
inline std::tr1::shared_ptr<T> lazy_shared_ptr<T>::
load () const
{
- if (!loaded ())
+ if (!p_ && i_)
p_ = i_.template load<T> (true); // Reset id.
return p_;
@@ -499,11 +499,12 @@ namespace odb
{
std::tr1::shared_ptr<T> r (p_.lock ());
- if (r || !i_)
- return r;
+ if (!r && i_)
+ {
+ r = i_.template load<T> (false); // Keep id.
+ p_ = r;
+ }
- r = i_.template load<T> (false); // Keep id.
- p_ = r;
return r;
}