Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7ed694

Browse files
committed
- Add nb_cmp slot for new style nubmers.
- Define type flag for new style numbers. - Add Py_NotImplemented.
1 parent dd038db commit a7ed694

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Include/object.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ typedef int (*visitproc)(PyObject *, void *);
119119
typedef int (*traverseproc)(PyObject *, visitproc, void *);
120120

121121
typedef struct {
122+
/* For old style numbers all arguments are guaranteed to be of the
123+
object's type (modulo coercion hacks that is); new style numbers
124+
should check both arguments for proper type and implement the
125+
necessary conversions in the slots themselves. */
126+
122127
binaryfunc nb_add;
123128
binaryfunc nb_subtract;
124129
binaryfunc nb_multiply;
@@ -153,6 +158,12 @@ typedef struct {
153158
binaryfunc nb_inplace_and;
154159
binaryfunc nb_inplace_xor;
155160
binaryfunc nb_inplace_or;
161+
162+
/* New style number slots; these are only used the
163+
Py_TPFLAGS_NEWSTYLENUMBER flag is set */
164+
165+
binaryfunc nb_cmp; /* XXX this should be richcmpfunc */
166+
156167
} PyNumberMethods;
157168

158169
typedef struct {
@@ -322,6 +333,9 @@ given type object has a specified feature.
322333
/* PySequenceMethods and PyNumberMethods contain in-place operators */
323334
#define Py_TPFLAGS_HAVE_INPLACEOPS (1L<<3)
324335

336+
/* PyNumberMethods do their own coercion */
337+
#define Py_TPFLAGS_NEWSTYLENUMBER (1L<<4)
338+
325339
#define Py_TPFLAGS_DEFAULT (Py_TPFLAGS_HAVE_GETCHARBUFFER | \
326340
Py_TPFLAGS_HAVE_SEQUENCE_IN | \
327341
Py_TPFLAGS_HAVE_INPLACEOPS)
@@ -434,6 +448,14 @@ extern DL_IMPORT(PyObject) _Py_NoneStruct; /* Don't use this directly */
434448

435449
#define Py_None (&_Py_NoneStruct)
436450

451+
/*
452+
Py_NotImplemented is a singleton used to signal that an operation is
453+
not implemented for a given type combination.
454+
*/
455+
456+
extern DL_IMPORT(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */
457+
458+
#define Py_NotImplemented (&_Py_NotImplementedStruct)
437459

438460
/*
439461
A common programming style in Python requires the forward declaration

0 commit comments

Comments
 (0)