FWIW, it seems I can't reproduce the problem with current boost svn trunk code, 
the problem still existed in boost_1_37_0 though. I could not spot the changes 
made that fixed the problem.

I took a look at the shared_ptr aliasing constructor, and made a patch to my 
boost_1_37_0 that solves the problem without altering shared_ptr code. All 
boost.python tests still pass after that. It may be useful to someone (the test 
case from Chad is attached)

--- python_1_37\converter\shared_ptr_from_python.hpp    2008-12-12 
15:49:04.156250000 +0100
+++ python\converter\shared_ptr_from_python.hpp 2008-12-12 14:24:24.781250000 
+0100
@@ -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;
     }

---

to include the test in python test pass :

Index: libs/python/test/Jamfile.v2
===================================================================
--- libs/python/test/Jamfile.v2 (revision 72)
+++ libs/python/test/Jamfile.v2 (working copy)
@@ -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 ]
// 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"

Attachment: enable_shared_from_this.py
Description: Binary data

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to