C-API, Tuple return value refcounts 
Author Message
 C-API, Tuple return value refcounts

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://www.*-*-*.com/



Thu, 16 Sep 2004 07:06:03 GMT  
 C-API, Tuple return value refcounts
See the post by Edward C. Jones on 7/6/01.


Quote:
> 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/



Fri, 17 Sep 2004 00:00:04 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Tuples, iterators, and multiple return values in Eiffel?

2. RETURN / RETURN-FROM and values

3. can a SWIG generated wrapper return a tuple

4. Python2.3 tkFileDialog.askopenfilename returns tuple on Cancel

5. KGL's fuzzy values (was: empty and singleton tuples)

6. LEA allways returning offset from CS

7. Difference in formatting list and tuple values

8. finding a value in a tuple

9. changing values of CS:IP

10. PROP: tuple.index(), tuple.count()

11. PROP: tuple.index(), tuple.count() (fwd)

12. tuple to list to tuple conversion

 

 
Powered by phpBB® Forum Software