En Wed, 01 Aug 2007 20:14:06 -0300, Raj B <[EMAIL PROTECTED]> escribió:
> Consider a new-style class
>
> class rabbit(object):
> def __init__(self,c):
> self.color = c
>
> r1=rabbit("blue")
> r2=rabbit("purple")
>
> Which C struct in the Python implementation is used to represent the
> instances c1 and c2 of the
> new-style class? I understand that when the class 'rabbit' is
> created, the type_new function
> in typeobject.c creates a copy of a 'struct typeobject' with
> dictionary tp_dict appropriately modified.
Yes. Then, rabbit("blue") means "call rabbit with a single argument,
blue". The slot tp_call is searched, giving usually type_call, which
itself calls tp_new (type_new if not overriden). (see type_call in
typeobject.c).
> However, I can't figure out which structure is used for new-style
> instances and where the instance dictionary is stored. Could anyone
> please clarify?
All objects in Python are based on a PyObject structure; see object.h
Different object types have additional fields at the end, but all share
the same basic layout.
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list