Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50368 - in trunk: boost/python/converter libs/python/test
From: rwgk_at_[hidden]
Date: 2008-12-23 02:55:34


Author: rwgk
Date: 2008-12-23 02:55:33 EST (Tue, 23 Dec 2008)
New Revision: 50368
URL: http://svn.boost.org/trac/boost/changeset/50368

Log:
Boost.Python enable_shared_from_this patches by Nicolas Lelong and Chad Austin:
  http://mail.python.org/pipermail/cplusplus-sig/2008-December/014103.html
  http://mail.python.org/pipermail/cplusplus-sig/2008-February/013003.html

Added:
   trunk/libs/python/test/enable_shared_from_this.cpp (contents, props changed)
   trunk/libs/python/test/enable_shared_from_this.py (contents, props changed)
Text files modified:
   trunk/boost/python/converter/shared_ptr_from_python.hpp | 10 +++++++---
   trunk/libs/python/test/Jamfile.v2 | 1 +
   2 files changed, 8 insertions(+), 3 deletions(-)

Modified: trunk/boost/python/converter/shared_ptr_from_python.hpp
==============================================================================
--- trunk/boost/python/converter/shared_ptr_from_python.hpp (original)
+++ trunk/boost/python/converter/shared_ptr_from_python.hpp 2008-12-23 02:55:33 EST (Tue, 23 Dec 2008)
@@ -45,10 +45,14 @@
         if (data->convertible == source)
             new (storage) shared_ptr<T>();
         else
+ {
+ boost::shared_ptr<void> hold_convertible_ref_count(
+ (void*)0, shared_ptr_deleter(handle<>(borrowed(source))) );
+ // use aliasing constructor
             new (storage) shared_ptr<T>(
- static_cast<T*>(data->convertible),
- shared_ptr_deleter(handle<>(borrowed(source)))
- );
+ hold_convertible_ref_count,
+ static_cast<T*>(data->convertible));
+ }
         
         data->convertible = storage;
     }

Modified: trunk/libs/python/test/Jamfile.v2
==============================================================================
--- trunk/libs/python/test/Jamfile.v2 (original)
+++ trunk/libs/python/test/Jamfile.v2 2008-12-23 02:55:33 EST (Tue, 23 Dec 2008)
@@ -75,6 +75,7 @@
 [ bpl-test return_arg ]
 [ bpl-test staticmethod ]
 [ bpl-test shared_ptr ]
+[ bpl-test enable_shared_from_this ]
 [ bpl-test andreas_beyer ]
 [ bpl-test polymorphism ]
 [ bpl-test polymorphism2 ]

Added: trunk/libs/python/test/enable_shared_from_this.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/python/test/enable_shared_from_this.cpp 2008-12-23 02:55:33 EST (Tue, 23 Dec 2008)
@@ -0,0 +1,48 @@
+// Copyright David Abrahams 2002.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/python/module.hpp>
+#include <boost/python/class.hpp>
+#include <boost/python/call_method.hpp>
+#include <boost/python/extract.hpp>
+#include <boost/python/def.hpp>
+#include <boost/enable_shared_from_this.hpp>
+#include <boost/shared_ptr.hpp>
+#include "test_class.hpp"
+
+#include <memory>
+
+using namespace boost::python;
+using boost::shared_ptr;
+
+class Test;
+typedef shared_ptr<Test> TestPtr;
+
+class Test : public boost::enable_shared_from_this<Test> {
+public:
+ static TestPtr construct() {
+ return TestPtr(new Test);
+ }
+
+ void act() {
+ TestPtr kungFuDeathGrip(shared_from_this());
+ }
+
+ void take(TestPtr t) {
+ }
+};
+
+BOOST_PYTHON_MODULE(enable_shared_from_this_ext)
+{
+ class_<Test, TestPtr, boost::noncopyable>("Test")
+ .def("construct", &Test::construct).staticmethod("construct")
+ .def("act", &Test::act)
+ .def("take", &Test::take)
+ ;
+}
+
+#include "module_tail.cpp"
+
+

Added: trunk/libs/python/test/enable_shared_from_this.py
==============================================================================
--- (empty file)
+++ trunk/libs/python/test/enable_shared_from_this.py 2008-12-23 02:55:33 EST (Tue, 23 Dec 2008)
@@ -0,0 +1,26 @@
+# Copyright David Abrahams 2004. Distributed under the Boost
+# Software License, Version 1.0. (See accompanying
+# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+'''
+>>> from enable_shared_from_this_ext import *
+
+>>> x = Test.construct()
+>>> x.take(x)
+>>> x.act()
+'''
+
+def run(args = None):
+ import sys
+ import doctest
+
+ if args is not None:
+ sys.argv = args
+ return doctest.testmod(sys.modules.get(__name__))
+
+if __name__ == '__main__':
+ print "running..."
+ import sys
+ status = run()[0]
+ if (status == 0): print "Done."
+ sys.exit(status)
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk