Richie,
Your comment makes sense because it is possible to pass a constant reference of int from python the the C++ DLL.
There seems to be two ways out of this predicament:
1) Write a specialized class of int which would then be non-immutable (wierd wording, I know). Possibly this could be a templatized class such that it would work on a variety of POD's. I am working on this method in a preliminary fashion.
2) As you suggested, find out if boost.python has some special ways of indicating the calling convention. Unfortunately, I was working on this for an entire day yesterda, unsuccessfully.
Does anyone know enough about boost.python to pass a non-const reference to a POD to a C++ DLL?
Thanks, Chris.
Main Topics
Browse All Topics





by: RichieHindlePosted on 2005-09-30 at 06:05:23ID: 14991691
If you're expecting that Python script to print "1" and change nRef to 123, you're going to be disappointed. Python doesn't support that kind of pass-by-reference for immutable objects, and integers are immutable. I imagine that's why Boost is failing (although I know very little about Boost). In Python, the way you'd implement a function that returned both 1 and 123 (which is effectively what your IntRef does) would be like this:
def IntRef():
return 1, 123
result, newValue = IntRef()
More realistically, if the new value was dependent on the old value, you'd do something like this:
def IntRef2(value):
return 1, value*2
value = 10
result, value = IntRef(value)
Maybe Boost has a way of specifying that a pass-by-reference parameter in the C++ function should become an input parameter and one member of a returned tuple in the Python function?