~ubuntu-branches/ubuntu/karmic/python3.0/karmic

« back to all changes in this revision

Viewing changes to Doc/c-api/typeobj.rst

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-16 17:18:23 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090216171823-1d5cm5qnnjvmnzzm
Tags: 3.0.1-0ubuntu1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
Typedefs: unaryfunc, binaryfunc, ternaryfunc, inquiry, intargfunc,
24
24
intintargfunc, intobjargproc, intintobjargproc, objobjargproc, destructor,
25
25
freefunc, printfunc, getattrfunc, getattrofunc, setattrfunc, setattrofunc,
26
 
cmpfunc, reprfunc, hashfunc
 
26
reprfunc, hashfunc
27
27
 
28
28
The structure definition for :ctype:`PyTypeObject` can be found in
29
29
:file:`Include/object.h`.  For convenience of reference, this repeats the
135
135
   :attr:`ob_size` field, and the instance size is :attr:`tp_basicsize` plus N
136
136
   times :attr:`tp_itemsize`, where N is the "length" of the object.  The value of
137
137
   N is typically stored in the instance's :attr:`ob_size` field.  There are
138
 
   exceptions:  for example, long ints use a negative :attr:`ob_size` to indicate a
 
138
   exceptions:  for example, ints use a negative :attr:`ob_size` to indicate a
139
139
   negative number, and N is ``abs(ob_size)`` there.  Also, the presence of an
140
140
   :attr:`ob_size` field in the instance layout doesn't mean that the instance
141
141
   structure is variable-length (for example, the structure for the list type has
244
244
   the subtype's :attr:`tp_setattr` and :attr:`tp_setattro` are both *NULL*.
245
245
 
246
246
 
247
 
.. cmember:: cmpfunc PyTypeObject.tp_compare
248
 
 
249
 
   An optional pointer to the three-way comparison function.
250
 
 
251
 
   The signature is the same as for :cfunc:`PyObject_Compare`. The function should
252
 
   return ``1`` if *self* greater than *other*, ``0`` if *self* is equal to
253
 
   *other*, and ``-1`` if *self* less than *other*.  It should return ``-1`` and
254
 
   set an exception condition when an error occurred during the comparison.
255
 
 
256
 
   This field is inherited by subtypes together with :attr:`tp_richcompare` and
257
 
   :attr:`tp_hash`: a subtypes inherits all three of :attr:`tp_compare`,
258
 
   :attr:`tp_richcompare`, and :attr:`tp_hash` when the subtype's
259
 
   :attr:`tp_compare`, :attr:`tp_richcompare`, and :attr:`tp_hash` are all *NULL*.
 
247
.. cmember:: void* PyTypeObject.tp_reserved
 
248
 
 
249
   Reserved slot, formerly known as tp_compare.
260
250
 
261
251
 
262
252
.. cmember:: reprfunc PyTypeObject.tp_repr
329
319
   the Python level will result in the ``tp_hash`` slot being set to
330
320
   :cfunc:`PyObject_HashNotImplemented`.
331
321
 
332
 
   When this field is not set, two possibilities exist: if the :attr:`tp_compare`
333
 
   and :attr:`tp_richcompare` fields are both *NULL*, a default hash value based on
334
 
   the object's address is returned; otherwise, a :exc:`TypeError` is raised.
 
322
   When this field is not set, an attempt to take the hash of the
 
323
   object raises :exc:`TypeError`.
335
324
 
336
 
   This field is inherited by subtypes together with :attr:`tp_richcompare` and
337
 
   :attr:`tp_compare`: a subtypes inherits all three of :attr:`tp_compare`,
338
 
   :attr:`tp_richcompare`, and :attr:`tp_hash`, when the subtype's
339
 
   :attr:`tp_compare`, :attr:`tp_richcompare` and :attr:`tp_hash` are all *NULL*.
 
325
   This field is inherited by subtypes together with
 
326
   :attr:`tp_richcompare`: a subtype inherits both of
 
327
   :attr:`tp_richcompare` and :attr:`tp_hash`, when the subtype's
 
328
   :attr:`tp_richcompare` and :attr:`tp_hash` are both *NULL*.
340
329
 
341
330
 
342
331
.. cmember:: ternaryfunc PyTypeObject.tp_call
596
585
      comparisons makes sense (e.g. ``==`` and ``!=``, but not ``<`` and
597
586
      friends), directly raise :exc:`TypeError` in the rich comparison function.
598
587
 
599
 
   This field is inherited by subtypes together with :attr:`tp_compare` and
600
 
   :attr:`tp_hash`: a subtype inherits all three of :attr:`tp_compare`,
601
 
   :attr:`tp_richcompare`, and :attr:`tp_hash`, when the subtype's
602
 
   :attr:`tp_compare`, :attr:`tp_richcompare`, and :attr:`tp_hash` are all *NULL*.
 
588
   This field is inherited by subtypes together with :attr:`tp_hash`:
 
589
   a subtype inherits :attr:`tp_richcompare` and :attr:`tp_hash` when
 
590
   the subtype's :attr:`tp_richcompare` and :attr:`tp_hash` are both
 
591
   *NULL*.
603
592
 
604
593
   The following constants are defined to be used as the third argument for
605
594
   :attr:`tp_richcompare` and for :cfunc:`PyObject_RichCompare`:
652
641
   :attr:`__weakref__`, the type inherits its :attr:`tp_weaklistoffset` from its
653
642
   base type.
654
643
 
655
 
 
656
644
.. cmember:: getiterfunc PyTypeObject.tp_iter
657
645
 
658
646
   An optional pointer to a function that returns an iterator for the object.  Its
813
801
 
814
802
   where :attr:`tp_basicsize`, :attr:`tp_itemsize` and :attr:`tp_dictoffset` are
815
803
   taken from the type object, and :attr:`ob_size` is taken from the instance.  The
816
 
   absolute value is taken because long ints use the sign of :attr:`ob_size` to
 
804
   absolute value is taken because ints use the sign of :attr:`ob_size` to
817
805
   store the sign of the number.  (There's never a need to do this calculation
818
806
   yourself; it is done for you by :cfunc:`_PyObject_GetDictPtr`.)
819
807
 
1058
1046
            binaryfunc nb_xor;
1059
1047
            binaryfunc nb_or;
1060
1048
            unaryfunc nb_int;
1061
 
            unaryfunc nb_long;
 
1049
            void *nb_reserved;
1062
1050
            unaryfunc nb_float;
1063
1051
 
1064
1052
            binaryfunc nb_inplace_add;
1089
1077
      ``Py_NotImplemented``, if another error occurred they must return ``NULL``
1090
1078
      and set an exception.
1091
1079
 
 
1080
   .. note::
 
1081
 
 
1082
      The :cdata:`nb_reserved` field should always be ``NULL``.  It
 
1083
      was previously called :cdata:`nb_long`, and was renamed in
 
1084
      Python 3.0.1.
 
1085
 
1092
1086
 
1093
1087
.. _mapping-structs:
1094
1088