[Python-Dev] Py_TPFLAGS_HEAPTYPE, what's its real meaning ?
Michael Hudson
mwh at python.net
Thu Oct 30 08:11:45 EST 2003
Boris Boutillier <Boris.Boutillier at arteris.net> writes:
> No answers on this ? I posted the question two times on c.l.py and got
> no answers., help would be appreciated.
I answered, on comp.lang.python. I didn't say anything especially
useful, though.
> Boris Boutillier wrote:
>
>> Hi all,
>>
>> I've posted this question to the main python list, but got no
>> answers, and I didn't see the issue arose on Python-dev (but I
>> subscribed only two weeks ago).
>> It concerns problems with the Py_TPFLAGS_HEAPTYPE and the new
>> hackcheck' in python 2.3.
>>
>> I'm writing a C-extension module for python 2.3.
>> I need to declare a new class, MyClass.
>> For this class I want two things :
>> 1) redefine the setattr function on objects of this class
>> (ie setting a new tp_setattro)
>> 2) I want that the python user can change attributes on MyClass (the
>> class itself).
>>
>> Now I have a conflict on the Py_TPFLAGS_HEAPTYPE with new Python 2.3.
>> If I have Py_TPFLAGS_HEAPTYPE set on MyClass, I'll have problem with the
>> new hackcheck (Object/typeobject.c:3631), as I am a HEAPTYPE but I also
>> redefine tp_setattro.
>> If I don't have Py_TPFLAGS_HEAPTYPE, the user can't set new attributes on
>> my class because of a check in type_setattro (Object/typeobject.c:2047).
>>
>> The only solution I've got without modifying python source is to
>> create a specific Metaclass for Myclass, and write the tp_setattr.
I think this is the appropriate solution: your type object is *not* a
heap type (i.e. is not allocated on the heap) and you want to
influence what happens when you set an attribute on it.
Cheers,
mwh
--
I'd certainly be shocked to discover a consensus. ;-)
-- Aahz, comp.lang.python
More information about the Python-Dev
mailing list