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:
parent
11963788e0
commit
243671700f
2 changed files with 23 additions and 12 deletions
|
|
@ -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<loopCount; i++) {
|
||||
new li_boost_intrusive_ptr_runme().runtest();
|
||||
new li_boost_intrusive_ptr_runme().runtest(i);
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
try {
|
||||
|
|
@ -78,7 +78,9 @@ public class li_boost_intrusive_ptr_runme {
|
|||
System.out.println("Finished");
|
||||
}
|
||||
|
||||
private void runtest() {
|
||||
private int loopCount = 0;
|
||||
private void runtest(int loopCount) {
|
||||
this.loopCount = loopCount;
|
||||
// simple shared_ptr usage - created in C++
|
||||
{
|
||||
Klass k = new Klass("me oh my");
|
||||
|
|
@ -671,36 +673,36 @@ private void toIgnore() {
|
|||
}
|
||||
private void verifyValue(String expected, String got) {
|
||||
if (!expected.equals(got))
|
||||
throw new RuntimeException("verify value failed. Expected: " + expected + " Got: " + got);
|
||||
throw new RuntimeException("verify value failed. Expected: " + expected + " Got: " + got + " loopCount: " + loopCount);
|
||||
}
|
||||
private void verifyCount(int expected, Klass k) {
|
||||
int got = li_boost_intrusive_ptr.use_count(k);
|
||||
if (expected != got)
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got);
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got + " loopCount: " + loopCount);
|
||||
}
|
||||
private void verifyCount(int expected, KlassDerived kd) {
|
||||
int got = li_boost_intrusive_ptr.use_count(kd);
|
||||
if (expected != got)
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got);
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got + " loopCount: " + loopCount);
|
||||
}
|
||||
private void verifyCount(int expected, KlassDerivedDerived kdd) {
|
||||
int got = li_boost_intrusive_ptr.use_count(kdd);
|
||||
if (expected != got)
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got);
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got + " loopCount: " + loopCount);
|
||||
}
|
||||
private void verifyIntrusiveCount(int expected, Klass k) {
|
||||
int got = k.use_count();
|
||||
if (expected != got)
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got);
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got + " loopCount: " + loopCount);
|
||||
}
|
||||
private void verifyIntrusiveCount(int expected, KlassDerived kd) {
|
||||
int got = kd.use_count();
|
||||
if (expected != got)
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got);
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got + " loopCount: " + loopCount);
|
||||
}
|
||||
private void verifyIntrusiveCount(int expected, KlassDerivedDerived kdd) {
|
||||
int got = kdd.use_count();
|
||||
if (expected != got)
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got);
|
||||
throw new RuntimeException("verify use_count failed. Expected: " + expected + " Got: " + got + " loopCount: " + loopCount);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(); }
|
||||
};
|
||||
%}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue