Sign in to follow this  
load_bitmap_file

Boost.Python pointer parameters

Recommended Posts

1. If I want to expose a C++ function like: void f(string* ptr) or void g(int* ptr), do I have to explicitly expose string and int to python? Trying to call f() or g() from Python w/ a string or int respectively gives me a "does not match C++ signature" error. 2. If I have:
void acceptPtr(C* ptr)
{
	delete ptr;
	ptr = NULL;
}
and I call acceptPtr() from Python:
c = module.C()
module.acceptPtr(c)
How is c passed? I defined the deconstructor of C to print out a message, which it did following the call to acceptPtr(), which should mean that ptr was successfully deleted. However, after the call to acceptPtr(), the c object in Python was still working like it wasn't deleted (I could still access member variables and call member methods with it). Does Python pass a new'd copy of the Python object? EDIT: In regards to #2, it seems that the member variable values for c got erased so I'm thinking that the c object in Python was actually deleted by the acceptPtr() function in C++, and for some reason just bits and pieces of it are still floating around in memory. I'm also guessing this means Python objects are passed in to C++ functions as a new'd object?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this