[C++-sig] shared_ptr trouble
Alex Mohr
amohr at pixar.com
Tue Mar 14 19:54:56 CET 2006
> Instead, it creates a
> new shared_ptr (with a whole new "control block" containing a
> use_count, weak_count and deleter) whose deleter manages a reference
> count on the owning Python object. That's the magic that allows
> Boost.Python to recover the original Python object when such a
> shared_ptr is converted back to Python.
I've been meaning to post regarding this and my effort to make custom
smart pointers work as well as shared_ptr does with c++ <-> python
polymorphism.
This "object identity" problem is the biggest issue. You can sort of
make it work with custom smart pointers by registering from_ and
to_python conversions that store and lookup a handle to the associated
python object. It doesn't completely work, because class_<> registers a
to_python conversion for you.
I'd love to have a generic mechanism where users could customize the
object identity mapping. Perhaps something similar to get_pointer
(set/get_object)? Ideally we could use this to remove some of the
special-case shared_ptr code, and just provide a default implementation
for shared_ptr.
If this seems like a good idea, I'd be willing to work on this when I'm
finished with the (*args, **kw) stuff.
Something like this may be useful to help solve Ralf's problem.
Actually, if one is willing to have an "invasive" handle to the python
object stored in the c++ object, I think it's definitely solvable.
Alex
More information about the Cplusplus-sig
mailing list