From 69d6ce4f33df00167fe73b86ec228e63a0d476b3 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 4 Apr 2008 23:29:59 +0000 Subject: [PATCH] Fix shared_ptr typemaps for use with %pythonnondynamic git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10344 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 8 ++++++++ Examples/test-suite/common.mk | 1 + .../test-suite/li_boost_shared_ptr_bits.i | 18 +++++++++++++++++ .../python/li_boost_shared_ptr_bits_runme.py | 20 +++++++++++++++++++ Lib/python/boost_shared_ptr.i | 2 +- 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 Examples/test-suite/li_boost_shared_ptr_bits.i create mode 100644 Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py diff --git a/CHANGES.current b/CHANGES.current index 9174845a0..f6a7c82b5 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,10 @@ Version 1.3.35 (in progress) ============================ +04/05/2008: wsfulton + [Python] Fix shared_ptr typemaps so that %pythonnondynamic can be used. Also corrects + display of the proxy class type. Reported by Robert Lupton. + 04/04/2008: olly [Python] Add %newobject reference to python memory management subsection of manual (patch from mdbeachy in SF#1894610). @@ -70,3 +74,7 @@ Version 1.3.35 (in progress) 02/29/2008: wsfulton [Python] Add shared_ptr varin/varout typemaps for wrapping global variables. + +02/25/2008: wsfulton + Fix $wrapname to work in %exception (fixes some wrap:name assertions) + diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index 0529f3a78..91a89b3d8 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -178,6 +178,7 @@ CPP_TEST_CASES += \ langobj \ li_attribute \ li_boost_shared_ptr \ + li_boost_shared_ptr_bits \ li_carrays \ li_cdata \ li_cpointer \ diff --git a/Examples/test-suite/li_boost_shared_ptr_bits.i b/Examples/test-suite/li_boost_shared_ptr_bits.i new file mode 100644 index 000000000..d2c703c05 --- /dev/null +++ b/Examples/test-suite/li_boost_shared_ptr_bits.i @@ -0,0 +1,18 @@ +%module li_boost_shared_ptr_bits + +%include + +#if defined(SWIGPYTHON) +%pythonnondynamic NonDynamic; +#endif + +SWIG_SHARED_PTR(NonDynamic, NonDynamic) + +%inline %{ +#include +struct NonDynamic { + int i; +}; +boost::shared_ptr boing(boost::shared_ptr b) { return b; } +%} + diff --git a/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py b/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py new file mode 100644 index 000000000..c6bd2f97a --- /dev/null +++ b/Examples/test-suite/python/li_boost_shared_ptr_bits_runme.py @@ -0,0 +1,20 @@ +from li_boost_shared_ptr_bits import * + +def check(nd): + nd.i = 200 + i = nd.i + + try: + nd.notexist = 100 + passed = 0 + except: + passed = 1 + + if not passed: + raise "Test failed" + +nd = NonDynamic() +check(nd) +b = boing(nd) +check(b) + diff --git a/Lib/python/boost_shared_ptr.i b/Lib/python/boost_shared_ptr.i index f8dffb36c..2e34290ac 100644 --- a/Lib/python/boost_shared_ptr.i +++ b/Lib/python/boost_shared_ptr.i @@ -69,7 +69,7 @@ } %typemap(out, fragment="SWIG_null_deleter") CONST TYPE * { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0; - %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN)); + %set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), $owner | SWIG_POINTER_OWN)); } %typemap(varin) CONST TYPE * {