Correct test for global shared_ptr variable
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10343 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
36e9ba403f
commit
a37115f55d
5 changed files with 13 additions and 17 deletions
|
|
@ -42,8 +42,8 @@ public class runme
|
||||||
|
|
||||||
int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();
|
int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();
|
||||||
if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING)
|
if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING)
|
||||||
if (wrapper_count != 0)
|
if (wrapper_count != 1) // Expect 1 instance - the one global variable (GlobalSmartValue)
|
||||||
throw new ApplicationException("shared_ptr wrapper count not zero: " + wrapper_count);
|
throw new ApplicationException("shared_ptr wrapper count=" + wrapper_count);
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
Console.WriteLine("Finished");
|
Console.WriteLine("Finished");
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,8 @@ public class li_boost_shared_ptr_runme {
|
||||||
|
|
||||||
int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();
|
int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();
|
||||||
if (wrapper_count != li_boost_shared_ptr.getNOT_COUNTING())
|
if (wrapper_count != li_boost_shared_ptr.getNOT_COUNTING())
|
||||||
if (wrapper_count != 0)
|
if (wrapper_count != 1) // Expect 1 instance - the one global variable (GlobalSmartValue)
|
||||||
throw new RuntimeException("shared_ptr wrapper count not zero: " + wrapper_count);
|
throw new RuntimeException("shared_ptr wrapper count=" + wrapper_count);
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
System.out.println("Finished");
|
System.out.println("Finished");
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
// the runtime tests can be run for a long time to monitor memory leaks using memory monitor tools
|
// the runtime tests can be run for a long time to monitor memory leaks using memory monitor tools
|
||||||
// like 'top'. There is a wrapper for shared_ptr in shared_ptr_wrapper.h which enables one to
|
// like 'top'. There is a wrapper for shared_ptr in shared_ptr_wrapper.h which enables one to
|
||||||
// count the instances of shared_ptr. Uncomment the SHARED_PTR_WRAPPER macro to turn this on.
|
// count the instances of shared_ptr. Uncomment the SHARED_PTR_WRAPPER macro to turn this on.
|
||||||
|
//
|
||||||
|
// Also note the debug_shared flag which can be set from the target language.
|
||||||
|
|
||||||
%module li_boost_shared_ptr
|
%module li_boost_shared_ptr
|
||||||
|
|
||||||
|
|
@ -36,7 +38,7 @@
|
||||||
|
|
||||||
#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED)
|
#if defined(SHARED_PTR_WRAPPERS_IMPLEMENTED)
|
||||||
|
|
||||||
%include "boost_shared_ptr.i"
|
%include <boost_shared_ptr.i>
|
||||||
SWIG_SHARED_PTR(Klass, Space::Klass)
|
SWIG_SHARED_PTR(Klass, Space::Klass)
|
||||||
SWIG_SHARED_PTR_DERIVED(KlassDerived, Space::Klass, Space::KlassDerived)
|
SWIG_SHARED_PTR_DERIVED(KlassDerived, Space::Klass, Space::KlassDerived)
|
||||||
|
|
||||||
|
|
@ -212,13 +214,6 @@ Klass *pointerownertest() {
|
||||||
SwigBoost::shared_ptr<Klass>* smartpointerpointerownertest() {
|
SwigBoost::shared_ptr<Klass>* smartpointerpointerownertest() {
|
||||||
return new SwigBoost::shared_ptr<Klass>(new Klass("smartpointerpointerownertest"));
|
return new SwigBoost::shared_ptr<Klass>(new Klass("smartpointerpointerownertest"));
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
Klass* arraytest(Klass k[]) {
|
|
||||||
k[0].append(" arraytest");
|
|
||||||
return k;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// Provide overloads for Klass and KlassDerived as some language modules, eg Python, create an extra reference in
|
// Provide overloads for Klass and KlassDerived as some language modules, eg Python, create an extra reference in
|
||||||
// the marshalling if an upcast to a base class is required.
|
// the marshalling if an upcast to a base class is required.
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,13 @@ class li_boost_shared_ptr_runme:
|
||||||
|
|
||||||
# Expect 1 instance - the one global variable (GlobalValue)
|
# Expect 1 instance - the one global variable (GlobalValue)
|
||||||
if (li_boost_shared_ptr.Klass.getTotal_count() != 1):
|
if (li_boost_shared_ptr.Klass.getTotal_count() != 1):
|
||||||
raise RuntimeError("Klass.total_count=", li_boost_shared_ptr.Klass.getTotal_count())
|
raise RuntimeError("Klass.total_count=%s" % li_boost_shared_ptr.Klass.getTotal_count())
|
||||||
|
|
||||||
wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count()
|
wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count()
|
||||||
if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING):
|
if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING):
|
||||||
if (wrapper_count != 0):
|
# Expect 1 instance - the one global variable (GlobalSmartValue)
|
||||||
raise RuntimeError("shared_ptr wrapper count not zero: ", wrapper_count)
|
if (wrapper_count != 1):
|
||||||
|
raise RuntimeError("shared_ptr wrapper count=%s" % wrapper_count)
|
||||||
|
|
||||||
if (debug):
|
if (debug):
|
||||||
print "Finished"
|
print "Finished"
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,12 @@ namespace SharedPtrWrapper {
|
||||||
|
|
||||||
template<typename T> void increment(boost::shared_ptr<T>* ptr) {
|
template<typename T> void increment(boost::shared_ptr<T>* ptr) {
|
||||||
SwigExamples::Lock lock(critical_section);
|
SwigExamples::Lock lock(critical_section);
|
||||||
std::cout << ptr << " " << show_message(ptr) << " " << " +" << std::endl << std::flush;
|
std::cout << "====SharedPtrWrapper==== + " << ptr << " " << show_message(ptr) << " " << std::endl << std::flush;
|
||||||
total_count++;
|
total_count++;
|
||||||
}
|
}
|
||||||
template<typename T> void decrement(boost::shared_ptr<T>* ptr) {
|
template<typename T> void decrement(boost::shared_ptr<T>* ptr) {
|
||||||
SwigExamples::Lock lock(critical_section);
|
SwigExamples::Lock lock(critical_section);
|
||||||
std::cout << ptr << " " << show_message(ptr) << " " << " -" << std::endl << std::flush;
|
std::cout << "====SharedPtrWrapper==== - " << ptr << " " << show_message(ptr) << " " << std::endl << std::flush;
|
||||||
total_count--;
|
total_count--;
|
||||||
}
|
}
|
||||||
static int getTotalCount() { return total_count; }
|
static int getTotalCount() { return total_count; }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue