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

Raoul Gough RaoulGough at yahoo.co.uk
Mon Sep 29 13:51:51 CEST 2003


"Andrew Ellem" <alellem at uwaterloo.ca> writes:

>> 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
> I 
> don't want it to.
>
> My problem is this:
> In my class's constructor, I create a class that is implemented in
> Python.  
> 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,
> hence 
> the crash.  So my problem is how do I prevent this?  

Without really understanding your example, I would *guess* that this
is a Python reference counting issue. Have you read the docs under
http://www.python.org/doc/current/ext/refcounts.html ?

Also, if you want to manage Python objects in C++, the Boost.Python
library has some code to help with the reference count management,
mostly in the "object" class. Maybe grepping for the (undocumented?)
borrowed_reference or new_reference in the libs/python/src tree will
provide suitable examples?

-- 
Raoul Gough.
(setq dabbrev-case-fold-search nil)





More information about the Cplusplus-sig mailing list