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:
William S Fulton 2008-04-04 23:26:54 +00:00
parent 36e9ba403f
commit a37115f55d
5 changed files with 13 additions and 17 deletions

View File

@ -42,8 +42,8 @@ public class runme
int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();
if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING)
if (wrapper_count != 0)
throw new ApplicationException("shared_ptr wrapper count not zero: " + wrapper_count);
if (wrapper_count != 1) // Expect 1 instance - the one global variable (GlobalSmartValue)
throw new ApplicationException("shared_ptr wrapper count=" + wrapper_count);
if (debug)
Console.WriteLine("Finished");

View File

@ -55,8 +55,8 @@ public class li_boost_shared_ptr_runme {
int wrapper_count = li_boost_shared_ptr.shared_ptr_wrapper_count();
if (wrapper_count != li_boost_shared_ptr.getNOT_COUNTING())
if (wrapper_count != 0)
throw new RuntimeException("shared_ptr wrapper count not zero: " + wrapper_count);
if (wrapper_count != 1) // Expect 1 instance - the one global variable (GlobalSmartValue)
throw new RuntimeException("shared_ptr wrapper count=" + wrapper_count);
if (debug)
System.out.println("Finished");

View File

@ -4,6 +4,8 @@
// 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
// 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
@ -36,7 +38,7 @@
#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_DERIVED(KlassDerived, Space::Klass, Space::KlassDerived)
@ -212,13 +214,6 @@ Klass *pointerownertest() {
SwigBoost::shared_ptr<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
// the marshalling if an upcast to a base class is required.

View File

@ -18,12 +18,13 @@ class li_boost_shared_ptr_runme:
# Expect 1 instance - the one global variable (GlobalValue)
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()
if (wrapper_count != li_boost_shared_ptr.NOT_COUNTING):
if (wrapper_count != 0):
raise RuntimeError("shared_ptr wrapper count not zero: ", wrapper_count)
# Expect 1 instance - the one global variable (GlobalSmartValue)
if (wrapper_count != 1):
raise RuntimeError("shared_ptr wrapper count=%s" % wrapper_count)
if (debug):
print "Finished"

View File

@ -24,12 +24,12 @@ namespace SharedPtrWrapper {
template<typename T> void increment(boost::shared_ptr<T>* ptr) {
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++;
}
template<typename T> void decrement(boost::shared_ptr<T>* ptr) {
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--;
}
static int getTotalCount() { return total_count; }