mirror of
https://github.com/python/cpython.git
synced 2025-08-21 17:25:34 +00:00
the nb_long slot on classobject instances now defaults to call the nb_int slot member if there is no __long__ attribute found. This is in accordance with a suggestion from Armin Rigo, and allows the test_getargs2.py test in the testsuite for x64
This commit is contained in:
parent
f4601d874f
commit
dffe9a214b
1 changed files with 13 additions and 1 deletions
|
@ -1539,6 +1539,18 @@ static PyObject *funcname(PyInstanceObject *self) { \
|
||||||
return generic_unary_op(self, o); \
|
return generic_unary_op(self, o); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* unary function with a fallback */
|
||||||
|
#define UNARY_FB(funcname, methodname, funcname_fb) \
|
||||||
|
static PyObject *funcname(PyInstanceObject *self) { \
|
||||||
|
static PyObject *o; \
|
||||||
|
if (o == NULL) { o = PyString_InternFromString(methodname); \
|
||||||
|
if (o == NULL) return NULL; } \
|
||||||
|
if (PyObject_HasAttr((PyObject*)self, o)) \
|
||||||
|
return generic_unary_op(self, o); \
|
||||||
|
else \
|
||||||
|
return funcname_fb(self); \
|
||||||
|
}
|
||||||
|
|
||||||
#define BINARY(f, m, n) \
|
#define BINARY(f, m, n) \
|
||||||
static PyObject *f(PyObject *v, PyObject *w) { \
|
static PyObject *f(PyObject *v, PyObject *w) { \
|
||||||
return do_binop(v, w, "__" m "__", "__r" m "__", n); \
|
return do_binop(v, w, "__" m "__", "__r" m "__", n); \
|
||||||
|
@ -1777,7 +1789,7 @@ instance_index(PyInstanceObject *self)
|
||||||
|
|
||||||
UNARY(instance_invert, "__invert__")
|
UNARY(instance_invert, "__invert__")
|
||||||
UNARY(instance_int, "__int__")
|
UNARY(instance_int, "__int__")
|
||||||
UNARY(instance_long, "__long__")
|
UNARY_FB(instance_long, "__long__", instance_int)
|
||||||
UNARY(instance_float, "__float__")
|
UNARY(instance_float, "__float__")
|
||||||
UNARY(instance_oct, "__oct__")
|
UNARY(instance_oct, "__oct__")
|
||||||
UNARY(instance_hex, "__hex__")
|
UNARY(instance_hex, "__hex__")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue