[C++-sig] Re: (no subject)

Andrew Ellem alellem at uwaterloo.ca
Mon Sep 29 03:30:36 CEST 2003

> Andrew,
> Clearly the error must be coming from somewhere else, for example
> a destructor of one of your objects which uses a HANDLE.  None of the
> Boost.Python code manipulates any type called HANDLE.

You are correct in that it is my code that is causing the problem.  More

specifically, it is that Boost.Python is deleting one of my objects when
don't want it to.

My problem is this:
In my class's constructor, I create a class that is implemented in
The constructor takes a pointer to the calling class.
Some pseudo-code for clarity's sake:

class X {
   X() {
      Y y = PythonClass( this )

The problem is that after the __init__ method is called, Boost tries to 
clean up the arguments, which causes my calling class to be deleted,
the crash.  So my problem is how do I prevent this?  

I'm guessing the problem is that by default Python passes by value, and
does Boost.  How do I do otherwise?  I'm guessing call-policies, but in
honesty I'm having some trouble getting my head around them all.

> Yes, it seems like you're taking shots in the dark.  Have you tried
> reading the documentation on Call Policies and/or stepping through the
> code that's crashing with a debugger?
I've read the documentation, but I admit I don't understand it 100%.
what I've read, I need to use a precall policy that tells Boost not to 
manage the variable I'm passing.  But I'm really not sure which policy
this, or even one exists.

I've been trying to find an example, the closest I can find is from the 
init.html example, which uses with_custodian_and_ward.  Is this what I
to do?  I don't really want to just throw it in and see if it works.

Perhaps a better question, where can I find a thorough explanation of
way Python, and Boost.Python handle arguments?  

Thanks for your help,

Andrew Ellem

More information about the Cplusplus-sig mailing list