From: Barry S. <ba...@ba...> - 2010-11-01 09:16:20
|
On 31 Oct 2010, at 23:59, Murali Donthireddy wrote: > Thank you, Barry! I will modify my code as you suggest. > > >> Python may try to delete this instance and that may fail. > fwiw, > I did some testing by having my python code assign the result of this method to a variable and then set the variable to None. > At first it wasn't calling the destructor of my new style class. I printed out reference counts of various objects in python and I noticed that these objects created in C++ code had reference counts one higher than other objects. That is when I added the "owned" argument to self() so that I could get an object with the right reference count. After that, my destructors were being called and I had no problems. I take that to mean Python is deleting the instance successfully. Of course there could be other things wrong that I haven't tested, and it is possible I have been lucky not to run into problems. I was seeing some strange crashes getting the new style class support working. The way new style classes work in python is that there is a python self object that is extended by PyCXX. In the extension I put a pointer to the C++ class instance. Because you need this special self from python just wrapping a C++ pointer will not work. Barry |