[C++-sig] Re: Shared Pointers and Boost.Python

Ingo Lütkebohle ingo at fargonauten.de
Mon Jul 26 10:20:28 CEST 2004


Am Sun, 25 Jul 2004 17:56:50 -0700 schrieb David Abrahams:
> The _warning_ (it should be a warning, not an assertion -- if it's an
> assertion something is very wrong)

It *is* an assertion.  See example at the end for this.  I'm using Boost
1.30.2

> Related?  I guess.  You haven't given much detail so it could be
> almost anything I suppose.

Hard to explain and I had trouble narrowing it down.  At the moment I'm
assuming its some threading-related problem in our code.  Thats why I
didn't report it earlier.  Your comment about creating shared_ptrs from
C++ just sparked my interest but from your explanation of the effects, I'm
back to the my-fault assumption again ;-)

Anyways, here's the example for the assertion problem.  It bombs on import.

---- begin
#include <boost/python/class.hpp>
#include <boost/python/implicit.hpp>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/register_ptr_to_python.hpp>

using namespace std;
using namespace boost::python;
 
namespace {
        struct me;
        typedef boost::shared_ptr<me> me_ptr;
         
        struct me {
                static me_ptr create() { return me_ptr(new me()); }
        };
 
        void print(const me_ptr me)
        {
                cerr << me.get() << endl;
        }
}
 
BOOST_PYTHON_MODULE(me)
{
        register_ptr_to_python<me_ptr>();
 
        class_<me, me_ptr>("ME", no_init)
                .def("debug", &print);
         
        def("create", &me::create);
}
---- end


-- 
Ingo

Soll doch jeder bleiben, wie er gern wäre.





More information about the Cplusplus-sig mailing list