By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,485 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,485 IT Pros & Developers. It's quick & easy.

Documentation on creating new types with slots in C ?

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Boris Boutillier wrote:
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

Jul 18 '05 #2

P: n/a
Alex Martelli <al***@aleax.it> writes:
Boris Boutillier wrote:
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).


I would guess he means this:

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

and I would also be interested in an example.

Thomas
Jul 18 '05 #3

P: n/a
Thomas Heller wrote:
...
Of what I heard Python 2.3 now allow creation of new types in C with
slots.
... 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

Jul 18 '05 #4

P: n/a
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
On Fri, 17 Oct 2003 14:58:44 +0000, Alex Martelli wrote:
Boris Boutillier wrote:
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


Jul 18 '05 #5

P: n/a
Thanks Thomas, I think this is exactly what I was looking for.

Boris

On Fri, 17 Oct 2003 17:20:49 +0200, Thomas Heller wrote:
Alex Martelli <al***@aleax.it> writes:
Boris Boutillier wrote:
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).


I would guess he means this:

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

and I would also be interested in an example.

Thomas


Jul 18 '05 #6

P: n/a
"Boris Boutillier" <bo**************@arteris.net> writes:
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

--
In general, I'd recommend injecting LSD directly into your temples,
Syd-Barret-style, before mucking with Motif's resource framework.
The former has far lower odds of leading directly to terminal
insanity. -- Dan Martinez
Jul 18 '05 #7

P: n/a
[Thomas]
I would guess he means this:

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

and I would also be interested in an example.

[Boris] Thanks Thomas, I think this is exactly what I was looking for.


For an alternative, which also works on Python 2.2, you can take a look
into the sources for ctypes.

Thomas
Jul 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.