Skip to content

Commit 43a9571

Browse files
committed
Fixed some technical problems with smart pointer support uncovered by
STLPort's debug mode. Unfortunately, had to expand Dereferenceable requirements. [SVN r16459]
1 parent bbef71d commit 43a9571

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

doc/v2/Dereferenceable.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,25 @@ <h3><a name="Dereferenceable-concept"></a>Dereferenceable Concept</h3>
4949
</tr>
5050
</table>
5151

52+
If <code><b>x</b></code> is not a pointer type, it also must satsify the following expression:
53+
54+
<table summary="Dereferenceable expressions" border="1" cellpadding="5">
55+
56+
<tr>
57+
<td><b>Expression</b></td>
58+
<td><b>Operational Semantics</b></td>
59+
</tr>
60+
61+
<tr>
62+
<td valign="top"><code>x.get()</code></td>
63+
<td><code>&amp;*x</code>, or a null pointer
64+
</tr>
65+
</table>
66+
5267
<hr>
5368
<p>Revised
5469
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->
55-
13 November, 2002
70+
29 November, 2002
5671
<!--webbot bot="Timestamp" endspan i-checksum="39359" -->
5772
</p>
5873
<p><i>&copy; Copyright <a href="../../../../people/dave_abrahams.htm">Dave

include/boost/python/object/pointer_holder.hpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@
3232

3333
namespace boost { namespace python { namespace objects {
3434

35+
template <class T>
36+
typename bool is_null(T const& p, ...)
37+
{
38+
return p.get() == 0;
39+
}
40+
41+
template <class T>
42+
bool is_null(T* p, int)
43+
{
44+
return p == 0;
45+
}
46+
3547
# define BOOST_PYTHON_UNFORWARD_LOCAL(z, n, _) BOOST_PP_COMMA_IF(n) (typename unforward<A##n>::type)(a##n)
3648

3749
template <class Pointer, class Value>
@@ -98,9 +110,12 @@ void* pointer_holder<Pointer, Value>::holds(type_info dst_t)
98110
if (dst_t == python::type_id<Pointer>())
99111
return &this->m_p;
100112

113+
if (objects::is_null(this->m_p, 0))
114+
return 0;
115+
101116
type_info src_t = python::type_id<Value>();
102-
return src_t == dst_t ? &*this->m_p
103-
: find_dynamic_type(&*this->m_p, src_t, dst_t);
117+
Value* p = &*this->m_p;
118+
return src_t == dst_t ? p : find_dynamic_type(p, src_t, dst_t);
104119
}
105120

106121
template <class Pointer, class Value>
@@ -109,6 +124,9 @@ void* pointer_holder_back_reference<Pointer, Value>::holds(type_info dst_t)
109124
if (dst_t == python::type_id<Pointer>())
110125
return &this->m_p;
111126

127+
if (objects::is_null(this->m_p, 0))
128+
return 0;
129+
112130
if (dst_t == python::type_id<held_type>())
113131
return &*this->m_p;
114132

0 commit comments

Comments
 (0)