From 9f9892648f954e45a628113febb524261075db32 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Mon, 2 Feb 2009 21:29:40 +0000 Subject: Issue #1717, continued: Doc fixes and other cleanup related to renaming of tp_compare. --- Doc/c-api/typeobj.rst | 37 +++++++++++++------------------------ Doc/extending/newtypes.rst | 10 +++++----- Doc/includes/noddy.c | 2 +- Doc/includes/noddy2.c | 2 +- Doc/includes/noddy3.c | 2 +- Doc/includes/noddy4.c | 2 +- Doc/includes/shoddy.c | 2 +- Doc/includes/typestruct.h | 2 +- Tools/framer/framer/slots.py | 2 +- 9 files changed, 25 insertions(+), 36 deletions(-) diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst index 6d98d6b..7dd576e 100644 --- a/Doc/c-api/typeobj.rst +++ b/Doc/c-api/typeobj.rst @@ -23,7 +23,7 @@ structure. Typedefs: unaryfunc, binaryfunc, ternaryfunc, inquiry, intargfunc, intintargfunc, intobjargproc, intintobjargproc, objobjargproc, destructor, freefunc, printfunc, getattrfunc, getattrofunc, setattrfunc, setattrofunc, -cmpfunc, reprfunc, hashfunc +reprfunc, hashfunc The structure definition for :ctype:`PyTypeObject` can be found in :file:`Include/object.h`. For convenience of reference, this repeats the @@ -244,19 +244,9 @@ type objects) *must* have the :attr:`ob_size` field. the subtype's :attr:`tp_setattr` and :attr:`tp_setattro` are both *NULL*. -.. cmember:: cmpfunc PyTypeObject.tp_compare +.. cmember:: void* PyTypeObject.tp_reserved - An optional pointer to the three-way comparison function. - - The signature is the same as for :cfunc:`PyObject_Compare`. The function should - return ``1`` if *self* greater than *other*, ``0`` if *self* is equal to - *other*, and ``-1`` if *self* less than *other*. It should return ``-1`` and - set an exception condition when an error occurred during the comparison. - - This field is inherited by subtypes together with :attr:`tp_richcompare` and - :attr:`tp_hash`: a subtypes inherits all three of :attr:`tp_compare`, - :attr:`tp_richcompare`, and :attr:`tp_hash` when the subtype's - :attr:`tp_compare`, :attr:`tp_richcompare`, and :attr:`tp_hash` are all *NULL*. + Reserved slot, formerly known as tp_compare. .. cmember:: reprfunc PyTypeObject.tp_repr @@ -329,14 +319,13 @@ type objects) *must* have the :attr:`ob_size` field. the Python level will result in the ``tp_hash`` slot being set to :cfunc:`PyObject_HashNotImplemented`. - When this field is not set, two possibilities exist: if the :attr:`tp_compare` - and :attr:`tp_richcompare` fields are both *NULL*, a default hash value based on - the object's address is returned; otherwise, a :exc:`TypeError` is raised. + When this field is not set, an attempt to take the hash of the + object raises :exc:`TypeError`. - This field is inherited by subtypes together with :attr:`tp_richcompare` and - :attr:`tp_compare`: a subtypes inherits all three of :attr:`tp_compare`, - :attr:`tp_richcompare`, and :attr:`tp_hash`, when the subtype's - :attr:`tp_compare`, :attr:`tp_richcompare` and :attr:`tp_hash` are all *NULL*. + This field is inherited by subtypes together with + :attr:`tp_richcompare`: a subtype inherits both of + :attr:`tp_richcompare` and :attr:`tp_hash`, when the subtype's + :attr:`tp_richcompare` and :attr:`tp_hash` are both *NULL*. .. cmember:: ternaryfunc PyTypeObject.tp_call @@ -596,10 +585,10 @@ type objects) *must* have the :attr:`ob_size` field. comparisons makes sense (e.g. ``==`` and ``!=``, but not ``<`` and friends), directly raise :exc:`TypeError` in the rich comparison function. - This field is inherited by subtypes together with :attr:`tp_compare` and - :attr:`tp_hash`: a subtype inherits all three of :attr:`tp_compare`, - :attr:`tp_richcompare`, and :attr:`tp_hash`, when the subtype's - :attr:`tp_compare`, :attr:`tp_richcompare`, and :attr:`tp_hash` are all *NULL*. + This field is inherited by subtypes together with :attr:`tp_hash`: + a subtype inherits :attr:`tp_richcompare` and :attr:`tp_hash` when + the subtype's :attr:`tp_richcompare` and :attr:`tp_hash` are both + *NULL*. The following constants are defined to be used as the third argument for :attr:`tp_richcompare` and for :cfunc:`PyObject_RichCompare`: diff --git a/Doc/extending/newtypes.rst b/Doc/extending/newtypes.rst index 1484c79..a0a797a 100644 --- a/Doc/extending/newtypes.rst +++ b/Doc/extending/newtypes.rst @@ -80,7 +80,7 @@ Moving on, we come to the crunch --- the type object. :: 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_compare */ + 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -1484,10 +1484,10 @@ provide. They are in :file:`object.h` in the Python include directory that comes with the source distribution of Python. In order to learn how to implement any specific method for your new data type, -do the following: Download and unpack the Python source distribution. Go the -:file:`Objects` directory, then search the C source files for ``tp_`` plus the -function you want (for example, ``tp_compare``). You will find examples of the -function you want to implement. +do the following: Download and unpack the Python source distribution. Go to +the :file:`Objects` directory, then search the C source files for ``tp_`` plus +the function you want (for example, ``tp_richcompare``). You will find examples +of the function you want to implement. When you need to verify that an object is an instance of the type you are implementing, use the :cfunc:`PyObject_TypeCheck` function. A sample of its use diff --git a/Doc/includes/noddy.c b/Doc/includes/noddy.c index b6b7d6f..3f37434 100644 --- a/Doc/includes/noddy.c +++ b/Doc/includes/noddy.c @@ -14,7 +14,7 @@ static PyTypeObject noddy_NoddyType = { 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_compare */ + 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/Doc/includes/noddy2.c b/Doc/includes/noddy2.c index db9c7a8..0907281 100644 --- a/Doc/includes/noddy2.c +++ b/Doc/includes/noddy2.c @@ -131,7 +131,7 @@ static PyTypeObject NoddyType = { 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_compare */ + 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/Doc/includes/noddy3.c b/Doc/includes/noddy3.c index e98b87f..fac44d8 100644 --- a/Doc/includes/noddy3.c +++ b/Doc/includes/noddy3.c @@ -184,7 +184,7 @@ static PyTypeObject NoddyType = { 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_compare */ + 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/Doc/includes/noddy4.c b/Doc/includes/noddy4.c index 5be00a7..1b3704c 100644 --- a/Doc/includes/noddy4.c +++ b/Doc/includes/noddy4.c @@ -165,7 +165,7 @@ static PyTypeObject NoddyType = { 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_compare */ + 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/Doc/includes/shoddy.c b/Doc/includes/shoddy.c index 3757bca..bb7f05b 100644 --- a/Doc/includes/shoddy.c +++ b/Doc/includes/shoddy.c @@ -39,7 +39,7 @@ static PyTypeObject ShoddyType = { 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ - 0, /* tp_compare */ + 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ diff --git a/Doc/includes/typestruct.h b/Doc/includes/typestruct.h index f6451b9..32647c0 100644 --- a/Doc/includes/typestruct.h +++ b/Doc/includes/typestruct.h @@ -9,7 +9,7 @@ typedef struct _typeobject { printfunc tp_print; getattrfunc tp_getattr; setattrfunc tp_setattr; - cmpfunc tp_compare; + void *tp_reserved; reprfunc tp_repr; /* Method suites for standard classes */ diff --git a/Tools/framer/framer/slots.py b/Tools/framer/framer/slots.py index d369c9a..0f6e6fe 100644 --- a/Tools/framer/framer/slots.py +++ b/Tools/framer/framer/slots.py @@ -15,7 +15,7 @@ Slots = (Slot("ob_size"), Slot("tp_print", "printfunc"), Slot("tp_getattr", "getattrfunc"), Slot("tp_setattr", "setattrfunc"), - Slot("tp_compare", "cmpfunc", "__cmp__"), + Slot("tp_reserved", "void*"), Slot("tp_repr", "reprfunc", "__repr__"), Slot("tp_as_number"), Slot("tp_as_sequence"), -- cgit v0.12