[Python-checkins] CVS: python/dist/src/Include object.h,2.67,2.68

Guido van Rossum gvanrossum@users.sourceforge.net
Wed, 17 Jan 2001 07:20:41 -0800


Update of /cvsroot/python/python/dist/src/Include
In directory usw-pr-cvs1:/tmp/cvs-serv11585

Modified Files:
	object.h 
Log Message:
Introduction to rich comparisons:

- Removed the nb_add slot from the PyNumberMethods struct.

- Renamed Py_TPFLAGS_NEWSTYLENUMBER to Py_TPFLAGS_CHECKTYPES.

- Added typedef richcmpfunc.

- Added tp_richcompare slot to PyTypeObject (replacing spare tp_xxx7).

- Added APIs PyObject_RichCompare() and PyObject_RichCompareBool().

- Added rich comparison operators Py_LT through Py_GE.


Index: object.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/object.h,v
retrieving revision 2.67
retrieving revision 2.68
diff -C2 -r2.67 -r2.68
*** object.h	2001/01/04 01:31:50	2.67
--- object.h	2001/01/17 15:20:39	2.68
***************
*** 120,127 ****
  
  typedef struct {
! 	/* For old style numbers all arguments are guaranteed to be of the
! 	   object's type (modulo coercion hacks that is); new style numbers
! 	   should check both arguments for proper type and implement the
! 	   necessary conversions in the slots themselves. */
  
  	binaryfunc nb_add;
--- 120,130 ----
  
  typedef struct {
! 	/* For numbers without flag bit Py_TPFLAGS_CHECKTYPES set, all
! 	   arguments are guaranteed to be of the object's type (modulo
! 	   coercion hacks that is -- i.e. if the type's coercion function
! 	   returns other types, then these are allowed as well).  Numbers that
! 	   have the Py_TPFLAGS_CHECKTYPES flag bit set should check *both*
! 	   arguments for proper type and implement the necessary conversions
! 	   in the slot functions themselves. */
  
  	binaryfunc nb_add;
***************
*** 159,168 ****
  	binaryfunc nb_inplace_xor;
  	binaryfunc nb_inplace_or;
- 
- 	/* New style number slots; these are only used the
- 	   Py_TPFLAGS_NEWSTYLENUMBER flag is set */
- 
- 	binaryfunc nb_cmp; /* XXX this should be richcmpfunc */
- 
  } PyNumberMethods;
  
--- 162,165 ----
***************
*** 203,206 ****
--- 200,204 ----
  typedef PyObject *(*reprfunc)(PyObject *);
  typedef long (*hashfunc)(PyObject *);
+ typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
  
  typedef struct _typeobject {
***************
*** 246,251 ****
  	inquiry tp_clear;
  
  	/* More spares */
- 	long tp_xxx7;
  	long tp_xxx8;
  
--- 244,251 ----
  	inquiry tp_clear;
  
+ 	/* rich comparisons */
+ 	richcmpfunc tp_richcompare;
+ 
  	/* More spares */
  	long tp_xxx8;
  
***************
*** 268,271 ****
--- 268,273 ----
  extern DL_IMPORT(PyObject *) PyObject_Str(PyObject *);
  extern DL_IMPORT(int) PyObject_Compare(PyObject *, PyObject *);
+ extern DL_IMPORT(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
+ extern DL_IMPORT(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);
  extern DL_IMPORT(PyObject *) PyObject_GetAttrString(PyObject *, char *);
  extern DL_IMPORT(int) PyObject_SetAttrString(PyObject *, char *, PyObject *);
***************
*** 335,339 ****
  
  /* PyNumberMethods do their own coercion */
! #define Py_TPFLAGS_NEWSTYLENUMBER (1L<<4)
  
  #define Py_TPFLAGS_DEFAULT  (Py_TPFLAGS_HAVE_GETCHARBUFFER | \
--- 337,341 ----
  
  /* PyNumberMethods do their own coercion */
! #define Py_TPFLAGS_CHECKTYPES (1L<<4)
  
  #define Py_TPFLAGS_DEFAULT  (Py_TPFLAGS_HAVE_GETCHARBUFFER | \
***************
*** 457,460 ****
--- 459,470 ----
  
  #define Py_NotImplemented (&_Py_NotImplementedStruct)
+ 
+ /* Rich comparison opcodes */
+ #define Py_LT 0
+ #define Py_LE 1
+ #define Py_EQ 2
+ #define Py_NE 3
+ #define Py_GT 4
+ #define Py_GE 5
  
  /*