Fix li_boost_intrusive_ptr for various versions of boost

Modify testcase to fix compile errors on various versions of boost.
Tested using various combinations from boost-1.33/gcc-3.4.2 to
boost-1.53/gcc-4.7.3. Originally noticed as broken on
boost-1.36/gcc-4.3.4 on SLE 11.

Add in some diagnostics when reference count is wrong... which does
still happen occasionally.
This commit is contained in:
William S Fulton 2014-05-18 23:09:58 +01:00
commit 243671700f
2 changed files with 23 additions and 12 deletions

View file

@ -6,6 +6,9 @@
// count the instances of intrusive_ptr. Uncomment the INTRUSIVE_PTR_WRAPPER macro to turn this on.
//
// Also note the debug_shared flag which can be set from the target language.
//
// Usage of intrusive_ptr_add_ref and intrusive_ptr_release based on boost testing:
// http://www.boost.org/doc/libs/1_36_0/libs/smart_ptr/test/intrusive_ptr_test.cpp
%module li_boost_intrusive_ptr
@ -13,14 +16,14 @@
%warnfilter(SWIGWARN_LANG_SMARTPTR_MISSING) KlassDerived;
%warnfilter(SWIGWARN_LANG_SMARTPTR_MISSING) KlassDerivedDerived;
%ignore intrusive_ptr_add_ref;
%ignore intrusive_ptr_release;
%{
#include <boost/shared_ptr.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/detail/atomic_count.hpp>
template<typename T> void intrusive_ptr_add_ref(const T* r) { r->addref(); }
template<typename T> void intrusive_ptr_release(const T* r) { r->release(); }
// Uncomment macro below to turn on intrusive_ptr memory leak checking as described above
//#define INTRUSIVE_PTR_WRAPPER
@ -132,6 +135,8 @@ struct Klass {
void release(void) const { if (--count == 0) delete this; }
int use_count(void) const { return count; }
static long getTotal_count() { return total_count; }
friend void intrusive_ptr_add_ref(const Klass* r) { r->addref(); }
friend void intrusive_ptr_release(const Klass* r) { r->release(); }
private:
static void increment() { ++total_count; if (debug_shared) cout << " ++xxxxx Klass::increment tot: " << total_count << endl;}
@ -177,6 +182,8 @@ struct IgnoredRefCountingBase {
void addref(void) const { ++count; }
void release(void) const { if (--count == 0) delete this; }
int use_count(void) const { return count; }
inline friend void intrusive_ptr_add_ref(const IgnoredRefCountingBase* r) { r->addref(); }
inline friend void intrusive_ptr_release(const IgnoredRefCountingBase* r) { r->release(); }
static long getTotal_count() { return total_count; }
private:
@ -414,6 +421,8 @@ template <class T1, class T2> struct Base {
void addref(void) const { count++; }
void release(void) const { if (--count == 0) delete this; }
int use_count(void) const { return count; }
inline friend void intrusive_ptr_add_ref(const Base<T1, T2>* r) { r->addref(); }
inline friend void intrusive_ptr_release(const Base<T1, T2>* r) { r->release(); }
};
%}