Skip to content

Commit 9d2873c

Browse files
author
Carl Hetherington
committedApr 19, 2012
Add shared_ptr debugging patch, as I keep losing it.
git-svn-id: svn://localhost/ardour2/branches/3.0@12038 d708f5d6-7413-0410-9779-e7cbd77b26cf
1 parent caae89f commit 9d2873c

File tree

1 file changed

+275
-0
lines changed

1 file changed

+275
-0
lines changed
 

‎patches/shared_ptr.patch

+275
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
--- shared_ptr.hpp.KEEP 2011-02-09 11:54:05.203963701 -0500
2+
+++ shared_ptr.hpp 2011-02-10 08:27:24.643133773 -0500
3+
@@ -55,6 +55,13 @@
4+
# pragma warning(disable:4284) // odd return type for operator->
5+
#endif
6+
7+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
8+
+void boost_debug_shared_ptr_operator_equals (void const *, void const *, int, void const*, int);
9+
+void boost_debug_shared_ptr_reset (void const *, void const *, int, void const*, int);
10+
+void boost_debug_shared_ptr_destructor (void const *, void const *, int);
11+
+void boost_debug_shared_ptr_constructor (void const *, void const *, int);
12+
+#endif
13+
+
14+
namespace boost
15+
{
16+
17+
@@ -181,12 +188,31 @@
18+
19+
shared_ptr(): px(0), pn() // never throws in 1.30+
20+
{
21+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
22+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
23+
+#endif
24+
+ }
25+
+
26+
+ ~shared_ptr()
27+
+ {
28+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
29+
+ boost_debug_shared_ptr_destructor (this, get(), use_count());
30+
+#endif
31+
+ }
32+
+
33+
+ shared_ptr(const shared_ptr<T>& r ) : px (r.px), pn (r.pn) {
34+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
35+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
36+
+#endif
37+
}
38+
39+
template<class Y>
40+
explicit shared_ptr( Y * p ): px( p ), pn( p ) // Y must be complete
41+
{
42+
boost::detail::sp_enable_shared_from_this( this, p, p );
43+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
44+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
45+
+#endif
46+
}
47+
48+
//
49+
@@ -197,7 +223,10 @@
50+
51+
template<class Y, class D> shared_ptr(Y * p, D d): px(p), pn(p, d)
52+
{
53+
- boost::detail::sp_enable_shared_from_this( this, p, p );
54+
+ boost::detail::sp_enable_shared_from_this( this, p, p );
55+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
56+
+ boost_debug_shared_ptr_constructor (this, px, 9249 /*use_count()*/);
57+
+#endif
58+
}
59+
60+
// As above, but with allocator. A's copy constructor shall not throw.
61+
@@ -205,6 +234,9 @@
62+
template<class Y, class D, class A> shared_ptr( Y * p, D d, A a ): px( p ), pn( p, d, a )
63+
{
64+
boost::detail::sp_enable_shared_from_this( this, p, p );
65+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
66+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
67+
+#endif
68+
}
69+
70+
// generated copy constructor, destructor are fine
71+
@@ -214,6 +246,9 @@
72+
{
73+
// it is now safe to copy r.px, as pn(r.pn) did not throw
74+
px = r.px;
75+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
76+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
77+
+#endif
78+
}
79+
80+
template<class Y>
81+
@@ -223,6 +258,9 @@
82+
{
83+
px = r.px;
84+
}
85+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
86+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
87+
+#endif
88+
}
89+
90+
template<class Y>
91+
@@ -237,22 +275,34 @@
92+
#endif
93+
: px( r.px ), pn( r.pn ) // never throws
94+
{
95+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
96+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
97+
+#endif
98+
}
99+
100+
// aliasing
101+
template< class Y >
102+
shared_ptr( shared_ptr<Y> const & r, T * p ): px( p ), pn( r.pn ) // never throws
103+
{
104+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
105+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
106+
+#endif
107+
}
108+
109+
template<class Y>
110+
shared_ptr(shared_ptr<Y> const & r, boost::detail::static_cast_tag): px(static_cast<element_type *>(r.px)), pn(r.pn)
111+
{
112+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
113+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
114+
+#endif
115+
}
116+
117+
template<class Y>
118+
shared_ptr(shared_ptr<Y> const & r, boost::detail::const_cast_tag): px(const_cast<element_type *>(r.px)), pn(r.pn)
119+
{
120+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
121+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
122+
+#endif
123+
}
124+
125+
template<class Y>
126+
@@ -262,6 +312,9 @@
127+
{
128+
pn = boost::detail::shared_count();
129+
}
130+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
131+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
132+
+#endif
133+
}
134+
135+
template<class Y>
136+
@@ -271,6 +324,9 @@
137+
{
138+
boost::throw_exception(std::bad_cast());
139+
}
140+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
141+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
142+
+#endif
143+
}
144+
145+
#ifndef BOOST_NO_AUTO_PTR
146+
@@ -281,6 +337,9 @@
147+
Y * tmp = r.get();
148+
pn = boost::detail::shared_count(r);
149+
boost::detail::sp_enable_shared_from_this( this, tmp, tmp );
150+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
151+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
152+
+#endif
153+
}
154+
155+
#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
156+
@@ -291,6 +350,9 @@
157+
typename Ap::element_type * tmp = r.get();
158+
pn = boost::detail::shared_count( r );
159+
boost::detail::sp_enable_shared_from_this( this, tmp, tmp );
160+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
161+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
162+
+#endif
163+
}
164+
165+
166+
@@ -302,6 +364,9 @@
167+
168+
shared_ptr & operator=( shared_ptr const & r ) // never throws
169+
{
170+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
171+
+ boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
172+
+#endif
173+
this_type(r).swap(*this);
174+
return *this;
175+
}
176+
@@ -311,6 +376,9 @@
177+
template<class Y>
178+
shared_ptr & operator=(shared_ptr<Y> const & r) // never throws
179+
{
180+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
181+
+ boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
182+
+#endif
183+
this_type(r).swap(*this);
184+
return *this;
185+
}
186+
@@ -322,6 +390,9 @@
187+
template<class Y>
188+
shared_ptr & operator=( std::auto_ptr<Y> & r )
189+
{
190+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
191+
+ boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
192+
+#endif
193+
this_type(r).swap(*this);
194+
return *this;
195+
}
196+
@@ -348,6 +419,9 @@
197+
{
198+
pn.swap( r.pn );
199+
r.px = 0;
200+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
201+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
202+
+#endif
203+
}
204+
205+
template<class Y>
206+
@@ -364,10 +438,16 @@
207+
{
208+
pn.swap( r.pn );
209+
r.px = 0;
210+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
211+
+ boost_debug_shared_ptr_constructor (this, px, use_count());
212+
+#endif
213+
}
214+
215+
shared_ptr & operator=( shared_ptr && r ) // never throws
216+
{
217+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
218+
+ boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
219+
+#endif
220+
this_type( static_cast< shared_ptr && >( r ) ).swap( *this );
221+
return *this;
222+
}
223+
@@ -375,6 +455,9 @@
224+
template<class Y>
225+
shared_ptr & operator=( shared_ptr<Y> && r ) // never throws
226+
{
227+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
228+
+ boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
229+
+#endif
230+
this_type( static_cast< shared_ptr<Y> && >( r ) ).swap( *this );
231+
return *this;
232+
}
233+
@@ -383,27 +466,42 @@
234+
235+
void reset() // never throws in 1.30+
236+
{
237+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
238+
+ boost_debug_shared_ptr_reset (this, get(), use_count(), 0, 0);
239+
+#endif
240+
this_type().swap(*this);
241+
}
242+
243+
template<class Y> void reset(Y * p) // Y must be complete
244+
{
245+
BOOST_ASSERT(p == 0 || p != px); // catch self-reset errors
246+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
247+
+ boost_debug_shared_ptr_reset (this, get(), use_count(), p, 0);
248+
+#endif
249+
this_type(p).swap(*this);
250+
}
251+
252+
template<class Y, class D> void reset( Y * p, D d )
253+
{
254+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
255+
+ boost_debug_shared_ptr_reset (this, get(), use_count(), p, 0);
256+
+#endif
257+
this_type( p, d ).swap( *this );
258+
}
259+
260+
template<class Y, class D, class A> void reset( Y * p, D d, A a )
261+
{
262+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
263+
+ boost_debug_shared_ptr_reset (this, get(), use_count(), p, 0);
264+
+#endif
265+
this_type( p, d, a ).swap( *this );
266+
}
267+
268+
template<class Y> void reset( shared_ptr<Y> const & r, T * p )
269+
{
270+
+#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
271+
+ boost_debug_shared_ptr_reset (this, get(), use_count(), r.get(), r.use_count());
272+
+#endif
273+
this_type( r, p ).swap( *this );
274+
}
275+

0 commit comments

Comments
 (0)
Please sign in to comment.