[C++-sig] make_constructor with custodian_and_ward not possible?

Roman Yakovenko roman.yakovenko at gmail.com
Tue Jan 15 20:10:42 CET 2008


On Jan 15, 2008 7:53 PM, André Anjos <andre.dos.anjos at gmail.com> wrote:
> André Anjos <andre.dos.anjos <at> gmail.com> writes:
>
> I have found several other posts on the same subject, suggesting there is no
> known solution. Has anybody found a way to circumvent this?
>
> http://mail.python.org/pipermail/c++-sig/2007-September/012846.html
>
> and
>
> http://mail.python.org/pipermail/c++-sig/2006-June/010746.html
>
> and
>
> http://www.nabble.com/-C%2B%2B-sig--make_constructor-%2B-
> with_custodian_and_ward-td4663469.html

I guess you can work around this problem:

You can expose "make_pointer" as regular function, with any policy you
want, and than add small code in Python:

from your module import Pointer as PointerImpl
from your module import make_pointer

def Pointer( x ):
    return make_pointer( x)

The only inconvenience is that "isinstance" will not work.

Another idea is to add new property to Pointer class "object holder",
that will keep reference to the Holder instance, than from Python
initialize that property:

from your module import Pointer as PointerImpl

class Pointer( PointerImpl ):
    def __init__( self, arg ):
        PointerImpl.__init__( self, arg )
        self.__arg = arg

HTH

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list