[Patches] [ python-Patches-696193 ] Enable __slots__ for meta-types

SourceForge.net noreply@sourceforge.net
Fri, 07 Mar 2003 07:04:50 -0800


Patches item #696193, was opened at 2003-03-02 16:02
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=696193&group_id=5470

Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Christian Tismer (tismer)
Assigned to: Guido van Rossum (gvanrossum)
Summary: Enable __slots__ for meta-types

Initial Comment:
The new type system allows non-empty __slots__ only
for fixed-size objects.

Meta-types are types which instances are also types.
types are variable-sized, because they take the slot
definitions for their instances, so the cannot have
extra members from their meta-type.

The proposed solution allows for two things:
a) meta-types can have slots
b) extensions get access to the whole type object and
    can create extended types with private fields.

The changes providing this are quite simple:
- replace the internal hidden "etype" and turn it into
  an explicit PyHeapTypeObject in object.h
- instead of a fixed offset into the former etype, the
slots
  calculation is based upon tp_basicsize.

To keep things easy, I added a macro which does this
calculation, and member access read now like so:

before:
	type->tp_members = et->members;
after:
	type->tp_members = PyHeapType_GET_MEMBERS(et);

This patch has been tested thoroughly in my own code since
Python 2.2, and I think it is ripe to get into the
distribution.
It has almost no impact on speed or simlicity.


----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2003-03-07 10:04

Message:
Logged In: YES 
user_id=6380

Everything looks fine, except subtracting 1 from the
expression in the PyHeapType_GET_MEMBERS() macro. Thart
makes the first members slot overlap with the 'name' and
'slots' struct members. I'll get rid of the "-1" part.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2003-03-03 09:57

Message:
Logged In: YES 
user_id=6380

I'll look at this on Friday.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=696193&group_id=5470