On 05/25/2011 02:26 PM, Jay Riley wrote:
I have some class functions that takes in parameters by pointer. However, when I expose and override this class/these functions in boost::python, any changes I make to the parameters are not reflected back to the original, meaning it isn't being passed by pointer as I expect. I previously had them as pass-by-reference, but the same problem still occurred. For an example of what I mean, here's some of my code with unimportant functions and details omitted.
I note two spots that bear further investigation. The most likely source is here:
//In the actual scripting code void StatusEffectWrapper::TickCharacter(Game::Character::BaseCharacter* character, Game::Battles::BattleField *field, int ticks) { call_method<void>(self, "TickCharacter", character, field, ticks); }
I think there's a very good chance that call_method is copying your character argument when it converts it to Python. Boost.Python is extra-careful about making sure the C++ objects it puts inside Python objects don't turn into dangling references, and it has no way to control the lifetime of a raw pointer or reference. I think you could probably fix this by using shared_ptr<BaseCharacter> here, because Boost.Python does know how to convert that safely to Python without copying the pointee.
If that fails, look here:
.def("TickCharacter", &StatusEffect::TickCharacter, &StatusEffectWrapper::TickCharacterDefault)
I've personally never seen this invocation of .def, with two member function pointer arguments. That doesn't necessarily mean it's incorrect, because overloading virtual methods in Python is feature I almost never use, and it seems like there are a half-dozen ways to do it and I never know which one is considered best (perhaps someone else on this list does?). But you might want to make sure this does what you expect.
HTH Jim Bosch _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig