|
Prev: pythoncom InternetExplorer.Application don't work in vista ||firefox pythoncom ?
Next: Elisp Lesson on file processing (make downloadable copy of a website)
From: Giuseppe Ottaviano on 5 Jul 2008 23:14 > > In Python, I retrive an Entity from the EntityList: > > elist = EntityList() > elist.append(Entity()) > elist.append(Entity()) > > entity = elist.get_at(0) > > entity.foo() > > But it crashes inside foo() as the private static data is empty; or > rather the string array is empty. I know before that point that the > private static data is valid when accessed earlier by the C++ code as > the program works fine. It just won't work from Python, so somehow the > private static data has been blown away but I can't work out where or > why. Probably it is a problem of lifetime. What is the signature of append? Who deletes the appended Entity in C++ code? If append takes a raw pointer, Boost.Python copies the pointer but destroys the Entity object because it is a temporary and its reference count went to zero. So the pointer in the list is referring to a destroyed object, which results in undefined behaviour. Did you have a look at the lifetime policies of Boost.Python? The simplest way to workaround the problem is using const reference arguments, and always use value semantics. If it can result in a performance penalty, another simple way is using shared_ptr's, which have their own reference count (different from the one in CPython lib), but Boost.Python does the magic to make them work together. HTH, Giuseppe |