From 243671700fd8ac0e18880962c19bf10cf4d91e1b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 18 May 2014 23:09:58 +0100 Subject: [PATCH] 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. --- .../java/li_boost_intrusive_ptr_runme.java | 20 ++++++++++--------- Examples/test-suite/li_boost_intrusive_ptr.i | 15 +++++++++++--- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java b/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java index 530008a87..750ec5067 100644 --- a/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java +++ b/Examples/test-suite/java/li_boost_intrusive_ptr_runme.java @@ -33,7 +33,7 @@ public class li_boost_intrusive_ptr_runme { // Change loop count to run for a long time to monitor memory final int loopCount = 5000; //5000; for (int i=0; i #include #include -template void intrusive_ptr_add_ref(const T* r) { r->addref(); } -template 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 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* r) { r->addref(); } + inline friend void intrusive_ptr_release(const Base* r) { r->release(); } }; %}