C-API, Tuple return value refcounts

Garyr garyr at fidalgo.net
Sun Mar 31 11:00:04 EST 2002


See the post by Edward C. Jones on 7/6/01.

"Eric Merritt" <cyberlync at yahoo.com> wrote in message
news:mailman.1017529670.5524.python-list at python.org...
> Hello All,
>
>  I have searched the archives fairly well and not
> found an answer to this question, so I thought I would
> post it to the list. I believe that this question
> stems, to some extent, from a lack of understanding
> concerning the reference counting system, so please
> keep that in mind when you answer.
>
> I am using the C-API to interface with a library
> function. Its a fairly simple interface in that it
> makes a call and returns a PyTuple to the calling
> process. It make no use of borrowed references. My
> question is this;
>
> When I return the new tuple type,
>
> 1) Do I need to increment the reference count before I
> return it (Keeping in mind that the tuple type is not
> reference out side of this function, it is simply a
> return value).
>
> 2) Do the PyObject values that make up the tuple type
> need their reference counts incremented?.
>
> In the above case I do not believe that they need to
> be incremented. Because according to the documentation
> the reference counts are incremented automatically
> when the PyObjects are created using the built in api
> functions. This, of course, creates another couple of
> questions.
>
> 1) Do I need to decref the tuple before it is
> returned?
>
> 2) Do I need to decref the objects comprising the
> tuple?
>
>
> I truly hope this question is not considered list
> clutter I have done my best to research the answers
> before I posted, but I am uncomfortable with my
> current understanding in this regard.
>
> Thank you,
> Eric
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Greetings - send holiday greetings for Easter, Passover
> http://greetings.yahoo.com/
>





More information about the Python-list mailing list