Embedding Python in C++ application: Question #1
Mark Hammond
MarkH at ActiveState.com
Tue Dec 4 23:35:15 EST 2001
Russell Turpin wrote:
> Mark Hammond <MarkH at ActiveState.com> wrote in message news:<3C0C3B3E.9030302 at ActiveState.com>...
>
>>Py_BuildValue is a convenience function.
>>
>
> OK. I'm finding the relevant interfaces in Python/C API.
> Do I read this right, that all new objects are created
> with a refcount of 1 , so that a called function
> can pass them to the caller without ref-count manipulation?
> Thus, I can call PyList_New() to create the list that will
> be returned to the calling Python procedure, iteratively
> pass the results of PyTuple_New() directly to
> PyList_SetItem(), which "steals" the reference to the
> tuple, and then return the list, all without a single
> INCREF or DECREF? Which, of course, is the way it *ought*
> to work, and that seems to be what it says ..
In general you are correct. However you can't rely on the "Set"
functions stealing a reference count - eg, PyTuple_SET_ITEM does, but I
can never remember if PyTuple_SetItem() does :)
Mark.
More information about the Python-list
mailing list