From f573927d48a7ceb155cf681e7cbad1e5176b2c0b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 6 Mar 2012 11:34:57 +0200 Subject: Detect situations where session is required but not used Throw session_required. --- odb/relational/source.hxx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'odb/relational/source.hxx') diff --git a/odb/relational/source.hxx b/odb/relational/source.hxx index fb13ade..a8edcf3 100644 --- a/odb/relational/source.hxx +++ b/odb/relational/source.hxx @@ -1195,6 +1195,7 @@ namespace relational if (lazy_pointer (pt)) os << member << " = ptr_traits::pointer_type (*db, id);"; else + { os << "// If a compiler error points to the line below, then" << endl << "// it most likely means that a pointer used in a member" << endl << "// cannot be initialized from an object pointer." << endl @@ -1202,6 +1203,23 @@ namespace relational << member << " = ptr_traits::pointer_type (" << endl << "db->load< obj_traits::object_type > (id));"; + // If we are loading into an eager weak pointer, make sure there + // is someone else holding a strong pointer to it (normally a + // session). Otherwise, the object will be loaded and immediately + // deleted. Besides not making much sense, this also breaks the + // delayed loading machinery which expects the object to be around + // at least until the top-level load() returns. + // + if (weak_pointer (pt)) + { + os << endl + << "if (pointer_traits< ptr_traits::strong_pointer_type >" << + "::null_ptr (" << endl + << "ptr_traits::lock (" << member << ")))" << endl + << "throw session_required ();"; + } + } + // @@ Composite value currently cannot be NULL. // if (!composite (mi.t)) -- cgit v1.1