faqts : Computers : Programming : Languages : Python : Common Problems : C/C++ Code

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 3 people (67%) answered Yes
Recently 0 of 1 people (0%) answered Yes

Entry

Should __getattr__ increment the reference count before it returns the appropriate attribute, or not? writing a Python module in C

May 16th, 2000 07:17
unknown unknown, Gordon McMillan


It should incref the attribute and leave the owner alone.

Imagine a sequence like this:
 newref = a.b # here's your __getattr__
 a = None
Now a's refcount drops. If it drops to 0, it gets deallocated, which 
will decref b. Without an incref in __getattr__, the user would have 
an invalid reference.