[C++-sig] How do I make correct wrappers to interfaces while using shared_ptrs?

Jim Bosch talljimbo at gmail.com
Tue Feb 7 17:21:47 CET 2012


On 02/05/2012 07:49 PM, Adam Preble wrote:

> Would using register_ptr_to_python explicitly and consistently instead of
> the online shared_ptr declaration potentially eliminate some side-effects?
> I cannot yet isolate why my real app crashes in python when it tries to do
> an eval into one of my wrappers.

Overall, I doubt it.  Usually putting shared_ptr in the class_ template 
params would allow you to do more fancy shared_ptr tricks, not less. 
And as I said before, it might be necessary if you use 
enable_shared_from_this.

What your previous example showed, though, was that it might be useful 
to use register_ptr_to_python on every type you ever make a shared_ptr 
to in C++ *in addition* to putting shared_ptr in the class_ templates - 
you'll get some warnings in Python about redundant converters, and those 
will tell you which of those extra declarations it's safe to remove. 
Any that remain might help fix your problem.

Jim


More information about the Cplusplus-sig mailing list