[C++-sig] Re: How to use call?

David Abrahams david.abrahams at rcn.com
Fri Jun 14 22:06:37 CEST 2002


> > That's a very strange way to invoke call<>. Did you look at the simple
> > example at
> >
> >
>
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/boost/boost/libs/
> > python/doc/v2/call.html
> >
> > and the more-complete text at
> >
> >
>
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/boost/boost/libs/
> > python/doc/v2/callbacks.html
> >
>
> Yes, but due to some previous compile errors I review the docs agains the
> source and wasn't sure if the comment about MSVC meant the parameter was
> required or not.

What comment about MSVC?

> > > I know the intention here is to copy the lvalue
> >
> > Huh? Which lvalue?
> >
>
> The lvalue_from_python code that seems to get invoked

There is no intention to copy an lvalue unless the explicit template
argument to call<> is a non-pointer, non-reference type.

> > MyClass* p = call<MyClass*>(callable, arg1, arg2, ...);
> >
>
> Then I  will get the "Attempt to return dangling internal reference"
> exception because I need to take possesion of the returned object.

Well, yeah. Who else is going to keep it alive?

> > > Maybe this will
> > > be fixed when the object work is complete and the return type can be
> > object.
> >
> > Not sure what you think that would buy you; you'd still need to get the
> C++
> > object out of it.
> >
>
> see above, the returned object needs to be 'owned'.

OK, you need what I mentioned to Dominic in a previous message: a smart
pointer type which holds a PyObject* and which "points to" its contained
lvalue. Yeah, that's not implemented, but patches are welcome.

-Dave







More information about the Cplusplus-sig mailing list