Documentation on creating new types with slots in C ?

B

Boris Boutillier

Hi all,

Of what I heard Python 2.3 now allow creation of new types in C with
slots.
Is there somewhere some documentation on this, or at least an example ?

Thanks a lot

Boris
 
A

Alex Martelli

Boris said:
Hi all,

Of what I heard Python 2.3 now allow creation of new types in C with
slots.
Is there somewhere some documentation on this, or at least an example ?

I'm not sure what you mean by "with slots" in this context. Creating
new types is well documented at:

http://www.python.org/doc/current/api/newTypes.html

and descriptors, assuming that might be what you mean by 'slots',
at http://users.rcn.com/python/download/Descriptor.htm (all the
examples there are in Python, but it should be easy for you to
translate them into C).


Alex
 
T

Thomas Heller

Alex Martelli said:
I'm not sure what you mean by "with slots" in this context. Creating
new types is well documented at:

http://www.python.org/doc/current/api/newTypes.html

and descriptors, assuming that might be what you mean by 'slots',
at http://users.rcn.com/python/download/Descriptor.htm (all the
examples there are in Python, but it should be easy for you to
translate them into C).

I would guess he means this:

http://www.python.org/sf/696193

and I would also be interested in an example.

Thomas
 
A

Alex Martelli

Thomas Heller wrote:
...
...
I would guess he means this:

http://www.python.org/sf/696193

i.e. METAtypes (types whose instances are types) with '__slots__' ...?

and I would also be interested in an example.

Sorry, I've never written a metatype in C -- always in Python, almost
invariably inheriting from the built-in type.

"Normal" C types don't _need_ __slots__ of course, since __slots__'s
effect (avoiding a per-instance dict) is most easily achieved by
simply leaving the tp_dictoffset field at 0 (as most built-in types
do, save for those who DO want a per-instance dict -- functions and
modules come to mind).


Alex
 
B

Boris Boutillier

That was not clear.
By slots, I mean the equivalent of '__slots__' in pure python,
ie adding some attribute as offsets at the end of the C description of a
Type.
And in fact what I am really looking for is how to describe '__slots__' in the C
description of a Metaclass.

Hope this make it a bit clearer.

Boris
 
M

Michael Hudson

Boris Boutillier said:
That was not clear.
By slots, I mean the equivalent of '__slots__' in pure python,
ie adding some attribute as offsets at the end of the C description of a
Type.
And in fact what I am really looking for is how to describe '__slots__' in the C
description of a Metaclass.

Either you or I are confused: do you want the slots to appear on the
*type* or on *instances of the type*?

Cheers,
mwh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top