[C++-sig] Re: Newbie : build & return a new list
dave at boost-consulting.com
Fri Nov 21 13:33:31 CET 2003
"Benjamin Golinvaux" <Benjamin.Golinvaux at euresys.com> writes:
> I am creating a function like this :
> PyObject* testCreateList()
> PyObject* newList = PyList_New(...);
> return newList;
Don't do that; use boost::python::list instead:
using namespace boost::python;
> can I assume that if I wrap it that way :
> def("testCreateList", testCreateList)
> Then will it behave correctly wrt references,
> i.e. is doing this :
> myList = myTestModule.testCreateList()
> the same as
> myList = [ .... ]
> or do I need to use the manage_new_object call policy ?
> I must say I don't understand when manage_new_object needs
> to be used.
It's used when you are returning some object you've allocated with
operator new and which would otherwise be leaked.
> Also, and this is unrelated, is there a nicer way to create
> a list using boost ?
See above ;-)
> I hope I'm not bothering you with my ultrabasic questions.
> If there is some example code I can read to help me going
> from the very simple tutorial to something more complex,
> I'd be glad to read it !
might help a bit.
More information about the Cplusplus-sig