This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Enable __slots__ for meta-types
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: gvanrossum, tismer
Priority: normal Keywords: patch

Created on 2003-03-02 21:02 by tismer, last changed 2022-04-10 16:07 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
typeobject.diff tismer, 2003-03-02 21:03 diff to object.h and typeobject.c
Messages (6)
msg42937 - (view) Author: Christian Tismer (old) (tismer) Date: 2003-03-02 21:02
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.
msg42938 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-03-03 14:57
Logged In: YES 
user_id=6380

I'll look at this on Friday.
msg42939 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-03-07 15:04
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.
msg42940 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-03-07 15:24
Logged In: YES 
user_id=6380

Checked in, with that one fix.
msg42941 - (view) Author: Christian Tismer (old) (tismer) Date: 2003-03-07 15:51
Logged In: YES 
user_id=105700

Oops! You are right.
I forgot to back-port that change into the future. My
2.2.2 version already reads like this:

/* access macro to the members which are floating "behind"
the object */
#define PyHeapType_GET_MEMBERS(etype) \
	((PyMemberDef *)(((char *)etype) +
(etype)->type.ob_type->tp_basicsize))

Thanks for taking care -- chris
msg42942 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-03-07 17:37
Logged In: YES 
user_id=6380

You're welcome. That's what I'm here for. :-)
History
Date User Action Args
2022-04-10 16:07:16adminsetgithub: 38080
2003-03-02 21:02:44tismercreate