new version of Boost shared ptr debugging patch
[ardour.git] / tools / boost-1.62-ptr-debug.patch
1 --- shared_ptr.hpp.orig 2016-11-12 13:46:50.000000000 -0500
2 +++ shared_ptr.hpp      2018-12-19 10:33:00.022538689 -0500
3 @@ -53,6 +53,13 @@
4  #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
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 *, volatile void const *, int);
11 +void boost_debug_shared_ptr_constructor (void const *, volatile void const *, int);
12 +#endif
13 +
14  namespace boost
15  {
16  
17 @@ -283,20 +290,29 @@
18  {
19      boost::detail::shared_count( p ).swap( pn );
20      boost::detail::sp_enable_shared_from_this( ppx, p, p );
21 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
22 +    boost_debug_shared_ptr_constructor (ppx, ppx->get(), ppx->use_count());
23 +#endif
24  }
25  
26  #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
27  
28 -template< class T, class Y > inline void sp_pointer_construct( boost::shared_ptr< T[] > * /*ppx*/, Y * p, boost::detail::shared_count & pn )
29 +template< class T, class Y > inline void sp_pointer_construct( boost::shared_ptr< T[] > * ppx, Y * p, boost::detail::shared_count & pn )
30  {
31      sp_assert_convertible< Y[], T[] >();
32      boost::detail::shared_count( p, boost::checked_array_deleter< T >() ).swap( pn );
33 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
34 +    /* no code for this yet - shared_ptr to array of T */
35 +#endif
36  }
37  
38  template< class T, std::size_t N, class Y > inline void sp_pointer_construct( boost::shared_ptr< T[N] > * /*ppx*/, Y * p, boost::detail::shared_count & pn )
39  {
40      sp_assert_convertible< Y[N], T[N] >();
41      boost::detail::shared_count( p, boost::checked_array_deleter< T >() ).swap( pn );
42 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
43 +    /* no code for this yet - shared_ptr to array of T */
44 +#endif
45  }
46  
47  #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
48 @@ -306,6 +322,9 @@
49  template< class T, class Y > inline void sp_deleter_construct( boost::shared_ptr< T > * ppx, Y * p )
50  {
51      boost::detail::sp_enable_shared_from_this( ppx, p, p );
52 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
53 +    boost_debug_shared_ptr_constructor (ppx, ppx->get(), ppx->use_count());
54 +#endif
55  }
56  
57  #if !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
58 @@ -313,11 +332,17 @@
59  template< class T, class Y > inline void sp_deleter_construct( boost::shared_ptr< T[] > * /*ppx*/, Y * /*p*/ )
60  {
61      sp_assert_convertible< Y[], T[] >();
62 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
63 +    /* no code for this yet - shared_ptr to array of T */
64 +#endif
65  }
66  
67  template< class T, std::size_t N, class Y > inline void sp_deleter_construct( boost::shared_ptr< T[N] > * /*ppx*/, Y * /*p*/ )
68  {
69      sp_assert_convertible< Y[N], T[N] >();
70 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
71 +    /* no code for this yet - shared_ptr to array of T */
72 +#endif
73  }
74  
75  #endif // !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
76 @@ -346,12 +371,20 @@
77  
78      shared_ptr() BOOST_NOEXCEPT : px( 0 ), pn() // never throws in 1.30+
79      {
80 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
81 +       /* default constructor case */
82 +       boost_debug_shared_ptr_constructor (this, px, use_count());
83 +#endif
84      }
85  
86  #if !defined( BOOST_NO_CXX11_NULLPTR )
87  
88      shared_ptr( boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT : px( 0 ), pn() // never throws
89      {
90 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
91 +       /* explicit nullptr constructor case */
92 +       boost_debug_shared_ptr_constructor (this, px, use_count());
93 +#endif
94      }
95  
96  #endif
97 @@ -392,11 +425,20 @@
98  
99      template<class D, class A> shared_ptr( boost::detail::sp_nullptr_t p, D d, A a ): px( p ), pn( p, d, a )
100      {
101 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
102 +       boost_debug_shared_ptr_constructor (this, px, use_count());
103 +#endif
104      }
105  
106  #endif
107  
108 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
109 +    ~shared_ptr() {
110 +       boost_debug_shared_ptr_destructor (this, get(), use_count());
111 +    }
112 +#else
113  //  generated copy constructor, destructor are fine...
114 +#endif /* BOOST_SP_ENABLE_DEBUG_HOOKS */
115  
116  #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
117  
118 @@ -404,6 +446,9 @@
119  
120      shared_ptr( shared_ptr const & r ) BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
121      {
122 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
123 +       boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
124 +#endif
125      }
126  
127  #endif
128 @@ -413,6 +458,9 @@
129      {
130          boost::detail::sp_assert_convertible< Y, T >();
131  
132 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
133 +       boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.px, -1);
134 +#endif
135          // it is now safe to copy r.px, as pn(r.pn) did not throw
136          px = r.px;
137      }
138 @@ -423,6 +471,9 @@
139      {
140          if( !pn.empty() )
141          {
142 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
143 +       boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.px, -1);
144 +#endif
145              px = r.px;
146          }
147      }
148 @@ -440,6 +491,9 @@
149      BOOST_NOEXCEPT : px( r.px ), pn( r.pn )
150      {
151          boost::detail::sp_assert_convertible< Y, T >();
152 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
153 +       boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
154 +#endif
155      }
156  
157      // aliasing
158 @@ -532,6 +586,9 @@
159      template<class Y>
160      shared_ptr & operator=(shared_ptr<Y> const & r) BOOST_NOEXCEPT
161      {
162 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
163 +       boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
164 +#endif
165          this_type(r).swap(*this);
166          return *this;
167      }
168 @@ -543,6 +600,9 @@
169      template<class Y>
170      shared_ptr & operator=( std::auto_ptr<Y> & r )
171      {
172 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
173 +       boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
174 +#endif
175          this_type( r ).swap( *this );
176          return *this;
177      }
178 @@ -552,6 +612,9 @@
179      template<class Y>
180      shared_ptr & operator=( std::auto_ptr<Y> && r )
181      {
182 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
183 +       boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
184 +#endif
185          this_type( static_cast< std::auto_ptr<Y> && >( r ) ).swap( *this );
186          return *this;
187      }
188 @@ -574,6 +637,9 @@
189      template<class Y, class D>
190      shared_ptr & operator=( std::unique_ptr<Y, D> && r )
191      {
192 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
193 +       boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
194 +#endif
195          this_type( static_cast< std::unique_ptr<Y, D> && >( r ) ).swap(*this);
196          return *this;
197      }
198 @@ -607,6 +673,9 @@
199  
200      shared_ptr( shared_ptr && r ) BOOST_NOEXCEPT : px( r.px ), pn()
201      {
202 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
203 +       boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
204 +#endif
205          pn.swap( r.pn );
206          r.px = 0;
207      }
208 @@ -625,12 +694,18 @@
209      {
210          boost::detail::sp_assert_convertible< Y, T >();
211  
212 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
213 +       boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
214 +#endif
215          pn.swap( r.pn );
216          r.px = 0;
217      }
218  
219      shared_ptr & operator=( shared_ptr && r ) BOOST_NOEXCEPT
220      {
221 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
222 +       boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
223 +#endif
224          this_type( static_cast< shared_ptr && >( r ) ).swap( *this );
225          return *this;
226      }
227 @@ -638,6 +713,9 @@
228      template<class Y>
229      shared_ptr & operator=( shared_ptr<Y> && r ) BOOST_NOEXCEPT
230      {
231 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
232 +       boost_debug_shared_ptr_operator_equals (this, get(), use_count(), r.get(), r.use_count());
233 +#endif
234          this_type( static_cast< shared_ptr<Y> && >( r ) ).swap( *this );
235          return *this;
236      }
237 @@ -656,6 +734,9 @@
238  
239      shared_ptr & operator=( boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT // never throws
240      {
241 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
242 +           boost_debug_shared_ptr_operator_reset (this, get(), use_count(), 0, 0);
243 +#endif
244          this_type().swap(*this);
245          return *this;
246      }
247 @@ -664,27 +745,42 @@
248  
249      void reset() BOOST_NOEXCEPT // never throws in 1.30+
250      {
251 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
252 +       boost_debug_shared_ptr_reset (this, get(), use_count(), 0, 0);
253 +#endif
254          this_type().swap(*this);
255      }
256  
257      template<class Y> void reset( Y * p ) // Y must be complete
258      {
259          BOOST_ASSERT( p == 0 || p != px ); // catch self-reset errors
260 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
261 +       boost_debug_shared_ptr_reset (this, get(), use_count(), p, 0);
262 +#endif
263          this_type( p ).swap( *this );
264      }
265  
266      template<class Y, class D> void reset( Y * p, D d )
267      {
268 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
269 +       boost_debug_shared_ptr_reset (this, get(), use_count(), p, 0);
270 +#endif
271          this_type( p, d ).swap( *this );
272      }
273  
274      template<class Y, class D, class A> void reset( Y * p, D d, A a )
275      {
276 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
277 +       boost_debug_shared_ptr_reset (this, get(), use_count(), p, 0);
278 +#endif
279          this_type( p, d, a ).swap( *this );
280      }
281  
282      template<class Y> void reset( shared_ptr<Y> const & r, element_type * p )
283      {
284 +#ifdef BOOST_SP_ENABLE_DEBUG_HOOKS
285 +           boost_debug_shared_ptr_reset (this, get(), use_count(), p, 0);
286 +#endif
287          this_type( r, p ).swap( *this );
288      }
289