[C++-sig] Python __init__ that copies internal reference, boost.python

Branan Purvine-Riley branan at gmail.com
Mon Aug 16 23:33:04 CEST 2010


I'm working on replacing hand-rolled python bindings with boost.python. 
Unfortunately, I've hit a bit of a snag at a particular construct:

  a = someFunction(...) # returns an instance of myClass
  b = myClass(a)

In the current bindings, this creates a new python object that references the 
same internal C++ object. It's effectively no-op, and I have no idea why it was 
written that way in the first place, but I have to maintain API compatibility.

That being the case, how do I implement this in boost.python? I considered 
replacing __init__, but it seems if I implement that as a standalone function 
rather than a constructor, boost has already created a new C++ instance for 
me, so that's too late. I'm not really sure what else to try.


More information about the Cplusplus-sig mailing list